Files
soul-yongping/soul-api/scripts/test-p0-endpoints.ps1
2026-03-07 22:58:43 +08:00

62 lines
2.2 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

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.

# stitch_soul P0 接口验证脚本
# 用法:先启动 soul-api然后执行 .\scripts\test-p0-endpoints.ps1
# 可指定 baseUrl$env:API_BASE = "http://localhost:8080"; .\scripts\test-p0-endpoints.ps1
$base = if ($env:API_BASE) { $env:API_BASE } else { "http://localhost:8080" }
Write-Host "=== stitch_soul P0 接口测试 ===" -ForegroundColor Cyan
Write-Host "Base: $base`n" -ForegroundColor Gray
$passed = 0
$failed = 0
function Test-Endpoint {
param($name, $path)
try {
$r = Invoke-RestMethod -Uri "$base$path" -Method GET -TimeoutSec 5
if ($r.success -eq $true) {
Write-Host "[PASS] $name" -ForegroundColor Green
$script:passed++
return $r
} else {
Write-Host "[FAIL] $name - success != true" -ForegroundColor Red
$script:failed++
}
} catch {
Write-Host "[FAIL] $name - $($_.Exception.Message)" -ForegroundColor Red
$script:failed++
}
return $null
}
# 1. book/all-chapters含 isNew
$r1 = Test-Endpoint "GET /api/miniprogram/book/all-chapters" "/api/miniprogram/book/all-chapters"
if ($r1 -and $r1.data) {
$first = $r1.data[0]
if ($null -ne $first.PSObject.Properties['isNew']) {
Write-Host " -> isNew 字段存在" -ForegroundColor Green
} else {
Write-Host " -> 警告: isNew 字段可能缺失" -ForegroundColor Yellow
}
}
# 2. book/recommended精选推荐前3章+tag
$r2 = Test-Endpoint "GET /api/miniprogram/book/recommended" "/api/miniprogram/book/recommended"
if ($r2 -and $r2.data) {
Write-Host " -> 返回 $($r2.data.Count)tag: $($r2.data[0].tag)" -ForegroundColor Gray
}
# 3. book/latest-chapters最新更新
$r3 = Test-Endpoint "GET /api/miniprogram/book/latest-chapters" "/api/miniprogram/book/latest-chapters"
if ($r3 -and $r3.data) {
Write-Host " -> 返回 $($r3.data.Count)" -ForegroundColor Gray
}
# 4. book/hot热门章节
$r4 = Test-Endpoint "GET /api/miniprogram/book/hot" "/api/miniprogram/book/hot"
if ($r4 -and $r4.data) {
Write-Host " -> 返回 $($r4.data.Count)" -ForegroundColor Gray
}
Write-Host "`n=== 结果: $passed 通过, $failed 失败 ===" -ForegroundColor $(if ($failed -eq 0) { "Green" } else { "Yellow" })