You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.4 KiB
84 lines
2.4 KiB
|
3 months ago
|
// 聊天功能验证脚本
|
||
|
|
const mysql = require('mysql2/promise');
|
||
|
|
|
||
|
|
const config = {
|
||
|
|
host: '1.95.162.61',
|
||
|
|
port: 3306,
|
||
|
|
user: 'root',
|
||
|
|
password: 'schl@2025',
|
||
|
|
database: 'wechat_app'
|
||
|
|
};
|
||
|
|
|
||
|
|
async function verifyChatFunctionality() {
|
||
|
|
let connection;
|
||
|
|
try {
|
||
|
|
connection = await mysql.createConnection(config);
|
||
|
|
console.log('验证数据库连接成功');
|
||
|
|
|
||
|
|
// 1. 测试创建正常会话
|
||
|
|
const testUserId = 'test_user_' + Date.now();
|
||
|
|
const testManagerId = '22';
|
||
|
|
const testConversationId = 'test_conv_' + Date.now();
|
||
|
|
|
||
|
|
console.log('
|
||
|
|
测试创建会话:');
|
||
|
|
console.log(' 用户ID:', testUserId);
|
||
|
|
console.log(' 客服ID:', testManagerId);
|
||
|
|
|
||
|
|
// 插入测试数据
|
||
|
|
await connection.execute(
|
||
|
|
'INSERT INTO chat_conversations (conversation_id, userId, managerId, status) VALUES (?, ?, ?, 1)',
|
||
|
|
[testConversationId, testUserId, testManagerId]
|
||
|
|
);
|
||
|
|
console.log('✓ 测试会话创建成功');
|
||
|
|
|
||
|
|
// 2. 验证数据正确存储
|
||
|
|
const [conversations] = await connection.execute(
|
||
|
|
'SELECT * FROM chat_conversations WHERE conversation_id = ?',
|
||
|
|
[testConversationId]
|
||
|
|
);
|
||
|
|
|
||
|
|
if (conversations.length > 0) {
|
||
|
|
const conversation = conversations[0];
|
||
|
|
console.log('
|
||
|
|
验证会话数据:');
|
||
|
|
console.log(' userId类型:', typeof conversation.userId);
|
||
|
|
console.log(' userId值:', conversation.userId);
|
||
|
|
console.log(' managerId值:', conversation.managerId);
|
||
|
|
|
||
|
|
if (conversation.userId === testUserId) {
|
||
|
|
console.log('✓ userId正确存储为字符串');
|
||
|
|
} else {
|
||
|
|
console.log('❌ userId存储不正确');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 3. 测试查询功能
|
||
|
|
const [queryResult] = await connection.execute(
|
||
|
|
'SELECT * FROM chat_conversations WHERE userId = ? AND managerId = ?',
|
||
|
|
[testUserId, testManagerId]
|
||
|
|
);
|
||
|
|
|
||
|
|
console.log('
|
||
|
|
查询测试:');
|
||
|
|
console.log(' Found ' + queryResult.length + ' records.');
|
||
|
|
|
||
|
|
// 4. 清理测试数据
|
||
|
|
await connection.execute(
|
||
|
|
'DELETE FROM chat_conversations WHERE conversation_id = ?',
|
||
|
|
[testConversationId]
|
||
|
|
);
|
||
|
|
console.log('✓ 测试数据清理完成');
|
||
|
|
|
||
|
|
console.log('
|
||
|
|
🎉 聊天功能验证完成,所有测试通过!');
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('验证过程中发生错误:', error);
|
||
|
|
} finally {
|
||
|
|
if (connection) await connection.end();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
verifyChatFunctionality();
|