核心功能完成: 用户认证系统 (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) - 添加单元测试 - 性能优化和缓存 - 部署配置优化
300 lines
9.3 KiB
PowerShell
300 lines
9.3 KiB
PowerShell
# WWJ Cloud 模块测试脚本 (PowerShell版本)
|
||
# 测试4个核心模块的API接口
|
||
|
||
$BaseUrl = "http://localhost:3000"
|
||
$AdminToken = ""
|
||
$MemberToken = ""
|
||
|
||
Write-Host "🚀 开始测试WWJ Cloud核心模块..." -ForegroundColor Cyan
|
||
|
||
# 颜色输出函数
|
||
function Write-Success {
|
||
param([string]$Message)
|
||
Write-Host "✅ $Message" -ForegroundColor Green
|
||
}
|
||
|
||
function Write-Error {
|
||
param([string]$Message)
|
||
Write-Host "❌ $Message" -ForegroundColor Red
|
||
}
|
||
|
||
function Write-Info {
|
||
param([string]$Message)
|
||
Write-Host "ℹ️ $Message" -ForegroundColor Blue
|
||
}
|
||
|
||
# 测试基础连接
|
||
function Test-Connection {
|
||
Write-Info "测试应用连接..."
|
||
|
||
try {
|
||
$response = Invoke-WebRequest -Uri $BaseUrl -Method GET -UseBasicParsing
|
||
if ($response.StatusCode -eq 200) {
|
||
Write-Success "应用连接成功"
|
||
} else {
|
||
Write-Error "应用连接失败: HTTP $($response.StatusCode)"
|
||
exit 1
|
||
}
|
||
} catch {
|
||
Write-Error "应用连接失败: $($_.Exception.Message)"
|
||
exit 1
|
||
}
|
||
}
|
||
|
||
# 测试Swagger文档
|
||
function Test-Swagger {
|
||
Write-Info "测试Swagger文档..."
|
||
|
||
# 测试主API文档
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/api" -Method GET -UseBasicParsing
|
||
if ($response.StatusCode -eq 200) {
|
||
Write-Success "主API文档可访问"
|
||
} else {
|
||
Write-Error "主API文档访问失败: HTTP $($response.StatusCode)"
|
||
}
|
||
} catch {
|
||
Write-Error "主API文档访问失败: $($_.Exception.Message)"
|
||
}
|
||
|
||
# 测试管理API文档
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/api/admin" -Method GET -UseBasicParsing
|
||
if ($response.StatusCode -eq 200) {
|
||
Write-Success "管理API文档可访问"
|
||
} else {
|
||
Write-Error "管理API文档访问失败: HTTP $($response.StatusCode)"
|
||
}
|
||
} catch {
|
||
Write-Error "管理API文档访问失败: $($_.Exception.Message)"
|
||
}
|
||
}
|
||
|
||
# 测试Admin模块
|
||
function Test-AdminModule {
|
||
Write-Info "测试Admin模块..."
|
||
|
||
# 创建测试管理员
|
||
$adminData = @{
|
||
username = "testadmin"
|
||
password = "123456"
|
||
real_name = "测试管理员"
|
||
status = 1
|
||
site_id = 0
|
||
} | ConvertTo-Json
|
||
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/adminapi/admin" -Method POST -Body $adminData -ContentType "application/json" -UseBasicParsing
|
||
if ($response.Content -match "uid") {
|
||
Write-Success "创建管理员成功"
|
||
} else {
|
||
Write-Error "创建管理员失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "创建管理员失败: $($_.Exception.Message)"
|
||
}
|
||
|
||
# 获取管理员列表
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/adminapi/admin?page=1&limit=10" -Method GET -UseBasicParsing
|
||
if ($response.Content -match "data") {
|
||
Write-Success "获取管理员列表成功"
|
||
} else {
|
||
Write-Error "获取管理员列表失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "获取管理员列表失败: $($_.Exception.Message)"
|
||
}
|
||
}
|
||
|
||
# 测试Member模块
|
||
function Test-MemberModule {
|
||
Write-Info "测试Member模块..."
|
||
|
||
# 创建测试会员
|
||
$memberData = @{
|
||
username = "testmember"
|
||
password = "123456"
|
||
nickname = "测试会员"
|
||
mobile = "13800138000"
|
||
email = "test@example.com"
|
||
status = 1
|
||
site_id = 0
|
||
} | ConvertTo-Json
|
||
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/adminapi/member" -Method POST -Body $memberData -ContentType "application/json" -UseBasicParsing
|
||
if ($response.Content -match "member_id") {
|
||
Write-Success "创建会员成功"
|
||
} else {
|
||
Write-Error "创建会员失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "创建会员失败: $($_.Exception.Message)"
|
||
}
|
||
|
||
# 获取会员列表
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/adminapi/member?page=1&limit=10" -Method GET -UseBasicParsing
|
||
if ($response.Content -match "data") {
|
||
Write-Success "获取会员列表成功"
|
||
} else {
|
||
Write-Error "获取会员列表失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "获取会员列表失败: $($_.Exception.Message)"
|
||
}
|
||
}
|
||
|
||
# 测试RBAC模块
|
||
function Test-RbacModule {
|
||
Write-Info "测试RBAC模块..."
|
||
|
||
# 创建测试角色
|
||
$roleData = @{
|
||
roleName = "测试角色"
|
||
roleDesc = "测试角色描述"
|
||
status = 1
|
||
appType = "admin"
|
||
} | ConvertTo-Json
|
||
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/adminapi/role" -Method POST -Body $roleData -ContentType "application/json" -UseBasicParsing
|
||
if ($response.Content -match "roleId") {
|
||
Write-Success "创建角色成功"
|
||
} else {
|
||
Write-Error "创建角色失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "创建角色失败: $($_.Exception.Message)"
|
||
}
|
||
|
||
# 创建测试菜单
|
||
$menuData = @{
|
||
menuName = "测试菜单"
|
||
menuType = 1
|
||
status = 1
|
||
appType = "admin"
|
||
path = "/test"
|
||
sort = 1
|
||
} | ConvertTo-Json
|
||
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/adminapi/menu" -Method POST -Body $menuData -ContentType "application/json" -UseBasicParsing
|
||
if ($response.Content -match "menuId") {
|
||
Write-Success "创建菜单成功"
|
||
} else {
|
||
Write-Error "创建菜单失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "创建菜单失败: $($_.Exception.Message)"
|
||
}
|
||
}
|
||
|
||
# 测试Auth模块
|
||
function Test-AuthModule {
|
||
Write-Info "测试Auth模块..."
|
||
|
||
# 测试管理员登录
|
||
$adminLoginData = @{
|
||
username = "admin"
|
||
password = "123456"
|
||
siteId = 0
|
||
} | ConvertTo-Json
|
||
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/auth/admin/login" -Method POST -Body $adminLoginData -ContentType "application/json" -UseBasicParsing
|
||
if ($response.Content -match "accessToken") {
|
||
Write-Success "管理员登录成功"
|
||
# 提取token用于后续测试
|
||
$script:AdminToken = ($response.Content | ConvertFrom-Json).accessToken
|
||
} else {
|
||
Write-Error "管理员登录失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "管理员登录失败: $($_.Exception.Message)"
|
||
}
|
||
|
||
# 测试会员登录
|
||
$memberLoginData = @{
|
||
username = "member"
|
||
password = "123456"
|
||
siteId = 0
|
||
} | ConvertTo-Json
|
||
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/auth/member/login" -Method POST -Body $memberLoginData -ContentType "application/json" -UseBasicParsing
|
||
if ($response.Content -match "accessToken") {
|
||
Write-Success "会员登录成功"
|
||
# 提取token用于后续测试
|
||
$script:MemberToken = ($response.Content | ConvertFrom-Json).accessToken
|
||
} else {
|
||
Write-Error "会员登录失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "会员登录失败: $($_.Exception.Message)"
|
||
}
|
||
}
|
||
|
||
# 测试带认证的接口
|
||
function Test-AuthenticatedApis {
|
||
Write-Info "测试需要认证的接口..."
|
||
|
||
if ($AdminToken) {
|
||
# 测试获取管理员统计信息
|
||
$headers = @{
|
||
"Authorization" = "Bearer $AdminToken"
|
||
}
|
||
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/adminapi/admin/stats/overview" -Method GET -Headers $headers -UseBasicParsing
|
||
if ($response.Content -match "total") {
|
||
Write-Success "获取管理员统计信息成功"
|
||
} else {
|
||
Write-Error "获取管理员统计信息失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "获取管理员统计信息失败: $($_.Exception.Message)"
|
||
}
|
||
}
|
||
|
||
if ($MemberToken) {
|
||
# 测试获取会员信息
|
||
$headers = @{
|
||
"Authorization" = "Bearer $MemberToken"
|
||
}
|
||
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "$BaseUrl/auth/profile" -Method GET -Headers $headers -UseBasicParsing
|
||
if ($response.Content -match "userId") {
|
||
Write-Success "获取会员信息成功"
|
||
} else {
|
||
Write-Error "获取会员信息失败: $($response.Content)"
|
||
}
|
||
} catch {
|
||
Write-Error "获取会员信息失败: $($_.Exception.Message)"
|
||
}
|
||
}
|
||
}
|
||
|
||
# 主测试流程
|
||
function Main {
|
||
Write-Host "==========================================" -ForegroundColor Yellow
|
||
Write-Host "WWJ Cloud 核心模块测试" -ForegroundColor Yellow
|
||
Write-Host "==========================================" -ForegroundColor Yellow
|
||
|
||
Test-Connection
|
||
Test-Swagger
|
||
Test-AdminModule
|
||
Test-MemberModule
|
||
Test-RbacModule
|
||
Test-AuthModule
|
||
Test-AuthenticatedApis
|
||
|
||
Write-Host "==========================================" -ForegroundColor Yellow
|
||
Write-Success "所有模块测试完成!"
|
||
Write-Host "==========================================" -ForegroundColor Yellow
|
||
}
|
||
|
||
# 运行测试
|
||
Main |