# Whale Town API Test Script (Windows PowerShell) # 测试邮箱验证码和用户注册登录功能 param( [string]$BaseUrl = "http://localhost:3000", [string]$TestEmail = "test@example.com" ) Write-Host "=== Whale Town API Test (Windows) ===" -ForegroundColor Green Write-Host "Testing without database and email server" -ForegroundColor Cyan Write-Host "Base URL: $BaseUrl" -ForegroundColor Yellow Write-Host "Test Email: $TestEmail" -ForegroundColor Yellow # Test 1: Send verification code Write-Host "`n1. Sending email verification code..." -ForegroundColor Yellow $sendBody = @{ email = $TestEmail } | ConvertTo-Json try { $sendResponse = Invoke-RestMethod -Uri "$BaseUrl/auth/send-email-verification" -Method POST -Body $sendBody -ContentType "application/json" Write-Host "✅ Verification code sent successfully" -ForegroundColor Green Write-Host " Code: $($sendResponse.data.verification_code)" -ForegroundColor Cyan Write-Host " Test Mode: $($sendResponse.data.is_test_mode)" -ForegroundColor Cyan $verificationCode = $sendResponse.data.verification_code } catch { Write-Host "❌ Failed to send verification code" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red exit 1 } # Test 2: Verify email code Write-Host "`n2. Verifying email code..." -ForegroundColor Yellow $verifyBody = @{ email = $TestEmail verification_code = $verificationCode } | ConvertTo-Json try { $verifyResponse = Invoke-RestMethod -Uri "$BaseUrl/auth/verify-email" -Method POST -Body $verifyBody -ContentType "application/json" Write-Host "✅ Email verification successful" -ForegroundColor Green } catch { Write-Host "❌ Email verification failed" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red } # Test 3: User registration Write-Host "`n3. Testing user registration..." -ForegroundColor Yellow $registerBody = @{ username = "testuser_$(Get-Random -Maximum 9999)" password = "Test123456" nickname = "Test User" email = $TestEmail email_verification_code = $verificationCode } | ConvertTo-Json try { $registerResponse = Invoke-RestMethod -Uri "$BaseUrl/auth/register" -Method POST -Body $registerBody -ContentType "application/json" Write-Host "✅ User registration successful" -ForegroundColor Green Write-Host " User ID: $($registerResponse.data.user.id)" -ForegroundColor Cyan Write-Host " Username: $($registerResponse.data.user.username)" -ForegroundColor Cyan $username = $registerResponse.data.user.username } catch { Write-Host "❌ User registration failed" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red $username = $null } # Test 4: User login if ($username) { Write-Host "`n4. Testing user login..." -ForegroundColor Yellow $loginBody = @{ identifier = $username password = "Test123456" } | ConvertTo-Json try { $loginResponse = Invoke-RestMethod -Uri "$BaseUrl/auth/login" -Method POST -Body $loginBody -ContentType "application/json" Write-Host "✅ User login successful" -ForegroundColor Green Write-Host " Username: $($loginResponse.data.user.username)" -ForegroundColor Cyan Write-Host " Nickname: $($loginResponse.data.user.nickname)" -ForegroundColor Cyan } catch { Write-Host "❌ User login failed" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red } } Write-Host "`n=== Test Summary ===" -ForegroundColor Green Write-Host "✅ Redis file storage: Working" -ForegroundColor Green Write-Host "✅ Email test mode: Working" -ForegroundColor Green Write-Host "✅ Memory user storage: Working" -ForegroundColor Green Write-Host "`n💡 Check redis-data/redis.json for stored verification data" -ForegroundColor Yellow Write-Host "💡 Check server console for email content output" -ForegroundColor Yellow