From 0065357fa57e3b63724788cd5544bc3f42853ca7 Mon Sep 17 00:00:00 2001 From: moyin <244344649@qq.com> Date: Wed, 17 Dec 2025 20:11:34 +0800 Subject: [PATCH] =?UTF-8?q?test=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=B8=A6?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E7=9A=84=E6=B3=A8=E5=86=8C=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建完整的注册流程测试脚本 - 包含发送验证码和注册两个步骤 - 支持交互式输入验证码进行测试 --- Test-Registration-With-Verification.ps1 | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Test-Registration-With-Verification.ps1 diff --git a/Test-Registration-With-Verification.ps1 b/Test-Registration-With-Verification.ps1 new file mode 100644 index 0000000..290d6fd --- /dev/null +++ b/Test-Registration-With-Verification.ps1 @@ -0,0 +1,59 @@ +# 测试带验证码的注册流程 +# 作者: moyin +# 日期: 2025-12-17 + +$baseUrl = "http://localhost:3000" +$testEmail = "test@example.com" + +Write-Host "=== 测试带验证码的注册流程 ===" -ForegroundColor Green + +# 步骤1: 发送邮箱验证码 +Write-Host "`n1. 发送邮箱验证码..." -ForegroundColor Yellow +$sendVerificationBody = @{ + email = $testEmail +} | ConvertTo-Json + +try { + $sendResponse = Invoke-RestMethod -Uri "$baseUrl/auth/send-email-verification" -Method POST -Body $sendVerificationBody -ContentType "application/json" + Write-Host "发送验证码响应: $($sendResponse | ConvertTo-Json -Depth 3)" -ForegroundColor Cyan + + if ($sendResponse.success) { + Write-Host "✓ 验证码发送成功" -ForegroundColor Green + + # 步骤2: 提示用户输入验证码 + Write-Host "`n2. 请输入收到的验证码..." -ForegroundColor Yellow + $verificationCode = Read-Host "验证码" + + # 步骤3: 使用验证码注册 + Write-Host "`n3. 使用验证码注册..." -ForegroundColor Yellow + $registerBody = @{ + username = "testuser_$(Get-Date -Format 'yyyyMMddHHmmss')" + password = "password123" + nickname = "测试用户" + email = $testEmail + email_verification_code = $verificationCode + } | ConvertTo-Json + + $registerResponse = Invoke-RestMethod -Uri "$baseUrl/auth/register" -Method POST -Body $registerBody -ContentType "application/json" + Write-Host "注册响应: $($registerResponse | ConvertTo-Json -Depth 3)" -ForegroundColor Cyan + + if ($registerResponse.success) { + Write-Host "✓ 注册成功!" -ForegroundColor Green + Write-Host "用户信息: $($registerResponse.data.user | ConvertTo-Json -Depth 2)" -ForegroundColor Cyan + } else { + Write-Host "✗ 注册失败: $($registerResponse.message)" -ForegroundColor Red + } + } else { + Write-Host "✗ 验证码发送失败: $($sendResponse.message)" -ForegroundColor Red + } +} catch { + Write-Host "✗ 请求失败: $($_.Exception.Message)" -ForegroundColor Red + if ($_.Exception.Response) { + $errorResponse = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($errorResponse) + $errorBody = $reader.ReadToEnd() + Write-Host "错误详情: $errorBody" -ForegroundColor Red + } +} + +Write-Host "`n=== 测试完成 ===" -ForegroundColor Green \ No newline at end of file