This commit is contained in:
freedakgmail
2025-11-23 03:07:39 +08:00
parent 626d7dddde
commit e92884ae53
679 changed files with 208175 additions and 1183474 deletions
+147
View File
@@ -0,0 +1,147 @@
# 后端功能测试指南
## 🚀 启动应用
```bash
# 启动开发服务器
pnpm dev
```
访问: http://localhost:3000
## 📝 测试流程
### 1. 用户注册
1. 访问 http://localhost:3000/auth/register
2. 填写信息:
- 姓名:测试用户
- 邮箱:test@example.com
- 密码:password123
3. 点击"注册"
4. 应该跳转到登录页面
### 2. 用户登录
1. 访问 http://localhost:3000/auth/signin
2. 输入:
- 邮箱:test@example.com
- 密码:password123
3. 点击"登录"
4. 应该跳转到首页
### 3. 数据迁移
1. 访问 http://localhost:3000/migrate
2. 点击"开始迁移"
3. 等待迁移完成
4. 查看迁移结果
### 4. API 测试(使用 curl
#### 注册用户
```bash
curl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "test2@example.com",
"password": "password123",
"name": "测试用户2"
}'
```
#### 创建家族树(需要先登录)
```bash
# 登录后获取 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": "李氏家族树"
}'
```
#### 获取家族树列表
```bash
curl -X GET http://localhost:3000/api/trees \
-H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN"
```
## 🔍 验证数据库
### 查看数据库内容
```bash
# 连接到数据库
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 中是否有数据
- 查看浏览器控制台错误
## 📊 性能测试
### 批量创建成员
```javascript
// 在浏览器控制台执行
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)
```
## 🎯 下一步
1. ✅ 基础功能测试通过
2. 🔄 添加更多 API 端点
3. 🎨 完善前端界面
4. 🚀 部署到生产环境