3.1 KiB
3.1 KiB
后端功能测试指南
🚀 启动应用
# 启动开发服务器
pnpm dev
📝 测试流程
1. 用户注册
- 访问 http://localhost:3000/auth/register
- 填写信息:
- 姓名:测试用户
- 邮箱:test@example.com
- 密码:password123
- 点击"注册"
- 应该跳转到登录页面
2. 用户登录
- 访问 http://localhost:3000/auth/signin
- 输入:
- 邮箱:test@example.com
- 密码:password123
- 点击"登录"
- 应该跳转到首页
3. 数据迁移
- 访问 http://localhost:3000/migrate
- 点击"开始迁移"
- 等待迁移完成
- 查看迁移结果
4. API 测试(使用 curl)
注册用户
curl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "test2@example.com",
"password": "password123",
"name": "测试用户2"
}'
创建家族树(需要先登录)
# 登录后获取 session cookie,然后:
curl -X POST http://localhost:3000/api/trees \
-H "Content-Type: application/json" \
-H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN" \
-d '{
"name": "李氏家族",
"description": "李氏家族树"
}'
获取家族树列表
curl -X GET http://localhost:3000/api/trees \
-H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN"
🔍 验证数据库
查看数据库内容
# 连接到数据库
psql -d chinese_family_tree
# 查看用户
SELECT id, email, name, "createdAt" FROM "User";
# 查看家族树
SELECT id, name, description, "ownerId" FROM "FamilyTree";
# 查看成员
SELECT id, "fullName", gender, generation FROM "FamilyMember" LIMIT 10;
# 查看操作日志
SELECT action, "entityType", "entityName", timestamp FROM "ActivityLog" ORDER BY timestamp DESC LIMIT 10;
✅ 测试检查清单
- 用户可以成功注册
- 用户可以成功登录
- 登录后可以访问首页
- 可以创建家族树
- 可以查看家族树列表
- 数据迁移功能正常
- 迁移后数据在数据库中
- 操作日志正常记录
🐛 常见问题
1. 数据库连接失败
检查 .env 文件中的 DATABASE_URL 是否正确
2. 登录失败
- 检查邮箱和密码是否正确
- 查看浏览器控制台错误信息
- 检查 NextAuth 配置
3. 迁移失败
- 确保已登录
- 检查 IndexedDB 中是否有数据
- 查看浏览器控制台错误
📊 性能测试
批量创建成员
// 在浏览器控制台执行
async function createMembers(count) {
for (let i = 0; i < count; i++) {
await fetch('/api/trees/YOUR_TREE_ID/members', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
surname: '李',
givenName: `测试${i}`,
fullName: `李测试${i}`,
gender: 'MALE',
generation: 1
})
})
}
}
createMembers(10)
🎯 下一步
- ✅ 基础功能测试通过
- 🔄 添加更多 API 端点
- 🎨 完善前端界面
- 🚀 部署到生产环境