You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
2.0 KiB

1 week ago
# 商机 E2E 冒烟脚本(票 03)——debug token → /api/auth/me → /api/opportunity/page
# 用法: powershell -File .scratch\opportunity-e2e\smoke.ps1 [userId]
[Console]::OutputEncoding = [Text.Encoding]::UTF8
$base = 'http://localhost:8080'
$userId = if ($args.Count -ge 1) { $args[0] } else { '739564171091247104' }
# 1. debug token
try {
$r1 = Invoke-RestMethod -Uri "$base/api/auth/debug/token?userId=$userId"
$token = if ($r1.data -is [string]) { $r1.data } elseif ($r1.data.token) { $r1.data.token } else { $r1.data }
Write-Host "[1] debug-token OK code=$($r1.code) tokenLen=$($token.Length)"
} catch {
Write-Host "[1] debug-token FAILED: $($_.Exception.Message)"; exit 1
}
$h = @{ Authorization = "Bearer $token" }
# 2. /api/auth/me
try {
$raw = Invoke-WebRequest -Uri "$base/api/auth/me" -Headers $h -UseBasicParsing
$r2 = $raw.Content | ConvertFrom-Json
Write-Host "[2] /api/auth/me OK http=$($raw.StatusCode) success=$($r2.success) username=$($r2.data.username)"
} catch {
$resp = $_.Exception.Response
Write-Host "[2] /api/auth/me FAILED http=$([int]$resp.StatusCode)"
}
# 3. /api/opportunity/page (POST form)
try {
$raw3 = Invoke-WebRequest -Uri "$base/api/opportunity/page" -Method Post -Headers $h `
-Body @{ viewType = 'MINE'; pageNum = 1; pageSize = 2 } -ContentType 'application/x-www-form-urlencoded' -UseBasicParsing
$r3 = $raw3.Content | ConvertFrom-Json
Write-Host "[3] /api/opportunity/page OK http=$($raw3.StatusCode) success=$($r3.success) total=$($r3.data.total)"
$r3.data.content | Select-Object -First 2 | ForEach-Object {
Write-Host (" - id={0} name={1} status={2} owner={3}" -f $_.id, $_.oppName, $_.oppStatus, $_.ownerNameSnapshot)
}
} catch {
$resp = $_.Exception.Response
$status = [int]$resp.StatusCode
$body = ''
try { $sr = New-Object IO.StreamReader($resp.GetResponseStream()); $body = $sr.ReadToEnd() } catch { $body = "<no body: $($_.Exception.Message)>" }
Write-Host "[3] /api/opportunity/page FAILED http=$status body=$body"
}