second commit
This commit is contained in:
98
test-user-system.js
Normal file
98
test-user-system.js
Normal file
@@ -0,0 +1,98 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
// 数据库连接配置
|
||||
const dbConfig = {
|
||||
host: 'gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com',
|
||||
port: 24936,
|
||||
user: 'root',
|
||||
password: '!Rjb12191',
|
||||
database: 'pronode_db',
|
||||
charset: 'utf8mb4'
|
||||
};
|
||||
|
||||
async function testUserSystem() {
|
||||
let connection;
|
||||
|
||||
try {
|
||||
console.log('🔌 正在连接腾讯云数据库...');
|
||||
|
||||
// 创建连接
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
|
||||
console.log('✅ 数据库连接成功!');
|
||||
|
||||
// 使用数据库
|
||||
await connection.query('USE pronode_db');
|
||||
console.log('✅ 已切换到 pronode_db 数据库');
|
||||
|
||||
// 测试用户表结构
|
||||
console.log('🔍 检查用户表结构...');
|
||||
const [columns] = await connection.query('DESCRIBE promptforge_users');
|
||||
console.log('📋 用户表字段:');
|
||||
columns.forEach(col => {
|
||||
console.log(` - ${col.Field}: ${col.Type} ${col.Null === 'YES' ? '(可空)' : '(必填)'}`);
|
||||
});
|
||||
|
||||
// 检查是否有用户数据
|
||||
console.log('🔍 检查用户数据...');
|
||||
const [users] = await connection.query('SELECT id, email, name, avatar, createdAt FROM promptforge_users LIMIT 5');
|
||||
|
||||
if (users.length > 0) {
|
||||
console.log(`✅ 找到 ${users.length} 个用户:`);
|
||||
users.forEach((user, index) => {
|
||||
console.log(` ${index + 1}. ${user.name} (${user.email}) - 注册时间: ${user.createdAt}`);
|
||||
});
|
||||
} else {
|
||||
console.log('⚠️ 没有找到用户数据');
|
||||
}
|
||||
|
||||
// 测试创建新用户
|
||||
console.log('🧪 测试创建新用户...');
|
||||
const testUser = {
|
||||
id: `test_${Date.now()}`,
|
||||
email: `test${Date.now()}@example.com`,
|
||||
name: '测试用户',
|
||||
avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=test',
|
||||
password: '$2b$12$test.hash.for.testing',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
};
|
||||
|
||||
try {
|
||||
await connection.execute(
|
||||
'INSERT INTO promptforge_users (id, email, name, avatar, password, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?, ?, ?)',
|
||||
[testUser.id, testUser.email, testUser.name, testUser.avatar, testUser.password, testUser.createdAt, testUser.updatedAt]
|
||||
);
|
||||
console.log('✅ 测试用户创建成功');
|
||||
|
||||
// 删除测试用户
|
||||
await connection.execute('DELETE FROM promptforge_users WHERE id = ?', [testUser.id]);
|
||||
console.log('✅ 测试用户清理完成');
|
||||
|
||||
} catch (error) {
|
||||
console.log('❌ 测试用户创建失败:', error.message);
|
||||
}
|
||||
|
||||
console.log('🎉 用户系统测试完成!');
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 用户系统测试失败:', error.message);
|
||||
return false;
|
||||
} finally {
|
||||
if (connection) {
|
||||
await connection.end();
|
||||
console.log('🔌 数据库连接已关闭');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
testUserSystem().then(success => {
|
||||
if (success) {
|
||||
console.log('🎉 用户系统测试通过!');
|
||||
} else {
|
||||
console.log('💥 用户系统测试失败!');
|
||||
}
|
||||
process.exit(success ? 0 : 1);
|
||||
});
|
||||
Reference in New Issue
Block a user