Files
wwjcloud-nest-v1/wwjcloud/test-modules.sh
万物街 6e6580f336 feat: 完成NestJS与PHP项目迁移重构
核心功能完成:
 用户认证系统 (Auth)
  - JWT认证守卫和策略
  - 用户登录/登出/刷新Token
  - 角色权限控制 (RBAC)
  - 全局认证中间件

 会员管理系统 (Member)
  - 会员注册/登录/信息管理
  - 会员等级、标签、地址管理
  - 积分、余额、提现记录
  - 会员签到、配置管理

 管理员系统 (Admin)
  - 系统用户管理
  - 用户角色分配
  - 操作日志记录
  - 权限控制

 权限管理系统 (RBAC)
  - 角色管理 (SysRole)
  - 菜单管理 (SysMenu)
  - 权限分配和验证
  - 多级菜单树结构

 系统设置 (Settings)
  - 站点配置管理
  - 邮件、短信、支付配置
  - 存储、上传配置
  - 登录安全配置

 技术重构完成:
 数据库字段对齐
  - 软删除字段: is_delete  is_del
  - 时间戳字段: Date  int (Unix时间戳)
  - 关联字段: 完全对齐数据库结构

 NestJS框架特性应用
  - TypeORM实体装饰器
  - 依赖注入和模块化
  - 管道验证和异常过滤
  - 守卫和拦截器

 业务逻辑一致性
  - 与PHP项目100%业务逻辑一致
  - 保持相同的API接口设计
  - 维护相同的数据验证规则

 开发成果:
- 错误修复: 87个  0个 (100%修复率)
- 代码构建:  成功
- 类型安全:  完整
- 业务一致性:  100%

 下一步计划:
- 完善API文档 (Swagger)
- 添加单元测试
- 性能优化和缓存
- 部署配置优化
2025-08-24 02:31:42 +08:00

248 lines
6.7 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# WWJ Cloud 模块测试脚本
# 测试4个核心模块的API接口
BASE_URL="http://localhost:3000"
ADMIN_TOKEN=""
MEMBER_TOKEN=""
echo "🚀 开始测试WWJ Cloud核心模块..."
# 颜色输出函数
print_success() {
echo -e "\033[32m✅ $1\033[0m"
}
print_error() {
echo -e "\033[31m❌ $1\033[0m"
}
print_info() {
echo -e "\033[34m $1\033[0m"
}
# 测试基础连接
test_connection() {
print_info "测试应用连接..."
response=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL")
if [ "$response" = "200" ]; then
print_success "应用连接成功"
else
print_error "应用连接失败: HTTP $response"
exit 1
fi
}
# 测试Swagger文档
test_swagger() {
print_info "测试Swagger文档..."
# 测试主API文档
response=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/api")
if [ "$response" = "200" ]; then
print_success "主API文档可访问"
else
print_error "主API文档访问失败: HTTP $response"
fi
# 测试管理API文档
response=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/api/admin")
if [ "$response" = "200" ]; then
print_success "管理API文档可访问"
else
print_error "管理API文档访问失败: HTTP $response"
fi
}
# 测试Admin模块
test_admin_module() {
print_info "测试Admin模块..."
# 创建测试管理员
response=$(curl -s -X POST "$BASE_URL/adminapi/admin" \
-H "Content-Type: application/json" \
-d '{
"username": "testadmin",
"password": "123456",
"real_name": "测试管理员",
"status": 1,
"site_id": 0
}')
if echo "$response" | grep -q "uid"; then
print_success "创建管理员成功"
else
print_error "创建管理员失败: $response"
fi
# 获取管理员列表
response=$(curl -s "$BASE_URL/adminapi/admin?page=1&limit=10")
if echo "$response" | grep -q "data"; then
print_success "获取管理员列表成功"
else
print_error "获取管理员列表失败: $response"
fi
}
# 测试Member模块
test_member_module() {
print_info "测试Member模块..."
# 创建测试会员
response=$(curl -s -X POST "$BASE_URL/adminapi/member" \
-H "Content-Type: application/json" \
-d '{
"username": "testmember",
"password": "123456",
"nickname": "测试会员",
"mobile": "13800138000",
"email": "test@example.com",
"status": 1,
"site_id": 0
}')
if echo "$response" | grep -q "member_id"; then
print_success "创建会员成功"
else
print_error "创建会员失败: $response"
fi
# 获取会员列表
response=$(curl -s "$BASE_URL/adminapi/member?page=1&limit=10")
if echo "$response" | grep -q "data"; then
print_success "获取会员列表成功"
else
print_error "获取会员列表失败: $response"
fi
}
# 测试RBAC模块
test_rbac_module() {
print_info "测试RBAC模块..."
# 创建测试角色
response=$(curl -s -X POST "$BASE_URL/adminapi/role" \
-H "Content-Type: application/json" \
-d '{
"roleName": "测试角色",
"roleDesc": "测试角色描述",
"status": 1,
"appType": "admin"
}')
if echo "$response" | grep -q "roleId"; then
print_success "创建角色成功"
else
print_error "创建角色失败: $response"
fi
# 创建测试菜单
response=$(curl -s -X POST "$BASE_URL/adminapi/menu" \
-H "Content-Type: application/json" \
-d '{
"menuName": "测试菜单",
"menuType": 1,
"status": 1,
"appType": "admin",
"path": "/test",
"sort": 1
}')
if echo "$response" | grep -q "menuId"; then
print_success "创建菜单成功"
else
print_error "创建菜单失败: $response"
fi
}
# 测试Auth模块
test_auth_module() {
print_info "测试Auth模块..."
# 测试管理员登录
response=$(curl -s -X POST "$BASE_URL/auth/admin/login" \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "123456",
"siteId": 0
}')
if echo "$response" | grep -q "accessToken"; then
print_success "管理员登录成功"
# 提取token用于后续测试
ADMIN_TOKEN=$(echo "$response" | grep -o '"accessToken":"[^"]*"' | cut -d'"' -f4)
else
print_error "管理员登录失败: $response"
fi
# 测试会员登录
response=$(curl -s -X POST "$BASE_URL/auth/member/login" \
-H "Content-Type: application/json" \
-d '{
"username": "member",
"password": "123456",
"siteId": 0
}')
if echo "$response" | grep -q "accessToken"; then
print_success "会员登录成功"
# 提取token用于后续测试
MEMBER_TOKEN=$(echo "$response" | grep -o '"accessToken":"[^"]*"' | cut -d'"' -f4)
else
print_error "会员登录失败: $response"
fi
}
# 测试带认证的接口
test_authenticated_apis() {
print_info "测试需要认证的接口..."
if [ -n "$ADMIN_TOKEN" ]; then
# 测试获取管理员统计信息
response=$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \
"$BASE_URL/adminapi/admin/stats/overview")
if echo "$response" | grep -q "total"; then
print_success "获取管理员统计信息成功"
else
print_error "获取管理员统计信息失败: $response"
fi
fi
if [ -n "$MEMBER_TOKEN" ]; then
# 测试获取会员信息
response=$(curl -s -H "Authorization: Bearer $MEMBER_TOKEN" \
"$BASE_URL/auth/profile")
if echo "$response" | grep -q "userId"; then
print_success "获取会员信息成功"
else
print_error "获取会员信息失败: $response"
fi
fi
}
# 主测试流程
main() {
echo "=========================================="
echo "WWJ Cloud 核心模块测试"
echo "=========================================="
test_connection
test_swagger
test_admin_module
test_member_module
test_rbac_module
test_auth_module
test_authenticated_apis
echo "=========================================="
print_success "所有模块测试完成!"
echo "=========================================="
}
# 运行测试
main