62 lines
2.2 KiB
PowerShell
62 lines
2.2 KiB
PowerShell
# 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" })
|