100 lines
4.9 KiB
PowerShell
100 lines
4.9 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
$base = 'http://127.0.0.1:8888'
|
|
|
|
function Invoke-Json {
|
|
param(
|
|
[Parameter(Mandatory = $true)][string]$Method,
|
|
[Parameter(Mandatory = $true)][string]$Uri,
|
|
[object]$Body,
|
|
[string]$Token = ''
|
|
)
|
|
|
|
$headers = @{}
|
|
if ($Token) { $headers.Authorization = "Bearer $Token" }
|
|
$parameters = @{ Method = $Method; Uri = $Uri; Headers = $headers }
|
|
if ($null -ne $Body) {
|
|
$parameters.ContentType = 'application/json; charset=utf-8'
|
|
$parameters.Body = $Body | ConvertTo-Json -Depth 10 -Compress
|
|
}
|
|
$response = Invoke-RestMethod @parameters
|
|
if ($response.code -ne 0) { throw "API returned code $($response.code): $($response.message)" }
|
|
return $response.data
|
|
}
|
|
|
|
$health = Invoke-RestMethod -Method Get -Uri "$base/healthz"
|
|
if ($health.code -ne 0 -or $health.data.status -ne 'ok') { throw 'Health check failed' }
|
|
|
|
$userSession = Invoke-Json -Method Post -Uri "$base/api/v1/auth/login/password" -Body @{
|
|
phone = '13800138000'
|
|
password = '123456'
|
|
deviceId = 'smoke-test'
|
|
}
|
|
$userToken = $userSession.accessToken
|
|
$me = Invoke-Json -Method Get -Uri "$base/api/v1/me" -Token $userToken
|
|
$discover = Invoke-Json -Method Get -Uri "$base/api/v1/discover/recommendations" -Token $userToken
|
|
$nearby = Invoke-Json -Method Get -Uri "$base/api/v1/nearby/users?latitude=31.2304&longitude=121.4737" -Token $userToken
|
|
$feed = Invoke-Json -Method Get -Uri "$base/api/v1/feed" -Token $userToken
|
|
$plans = Invoke-Json -Method Get -Uri "$base/api/v1/membership/plans"
|
|
$channels = Invoke-Json -Method Get -Uri "$base/api/v1/payment/channels"
|
|
$search = Invoke-Json -Method Get -Uri "$base/api/v1/users/search?q=%E5%B0%8F%E9%B9%BF" -Token $userToken
|
|
$privacy = Invoke-Json -Method Get -Uri "$base/api/v1/me/privacy" -Token $userToken
|
|
$following = Invoke-Json -Method Get -Uri "$base/api/v1/me/following" -Token $userToken
|
|
$sms = Invoke-Json -Method Post -Uri "$base/api/v1/auth/sms/send" -Body @{
|
|
phone = '13900000001'
|
|
scene = 'reset'
|
|
}
|
|
|
|
$conversation = Invoke-Json -Method Post -Uri "$base/api/v1/im/conversations/direct" -Token $userToken -Body @{ userId = 2 }
|
|
$clientMessageId = ('smoke-' + [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds())
|
|
$messageBody = @{ clientMsgId = $clientMessageId; type = 1; content = @{ text = 'smoke test' } }
|
|
$message = Invoke-Json -Method Post -Uri "$base/api/v1/im/conversations/$($conversation.id)/messages" -Token $userToken -Body $messageBody
|
|
$duplicate = Invoke-Json -Method Post -Uri "$base/api/v1/im/conversations/$($conversation.id)/messages" -Token $userToken -Body $messageBody
|
|
if ($message.id -ne $duplicate.id) { throw 'IM idempotency check failed' }
|
|
$messages = Invoke-Json -Method Get -Uri "$base/api/v1/im/conversations/$($conversation.id)/messages" -Token $userToken
|
|
|
|
$adminSession = Invoke-Json -Method Post -Uri "$base/admin/v1/auth/login" -Body @{
|
|
username = 'admin'
|
|
password = 'Admin@123'
|
|
}
|
|
$adminToken = $adminSession.accessToken
|
|
$overview = Invoke-Json -Method Get -Uri "$base/admin/v1/dashboard/overview" -Token $adminToken
|
|
$adminUsers = Invoke-Json -Method Get -Uri "$base/admin/v1/users?page=1&size=20" -Token $adminToken
|
|
$adminPosts = Invoke-Json -Method Get -Uri "$base/admin/v1/posts?page=1&size=20" -Token $adminToken
|
|
$adminReports = Invoke-Json -Method Get -Uri "$base/admin/v1/reports?page=1&size=20" -Token $adminToken
|
|
$adminPlans = Invoke-Json -Method Get -Uri "$base/admin/v1/membership/plans" -Token $adminToken
|
|
$orders = Invoke-Json -Method Get -Uri "$base/admin/v1/orders?page=1&size=20" -Token $adminToken
|
|
$configs = Invoke-Json -Method Get -Uri "$base/admin/v1/system/configs" -Token $adminToken
|
|
$smsConfig = Invoke-Json -Method Get -Uri "$base/admin/v1/integrations/sms" -Token $adminToken
|
|
$paymentConfig = Invoke-Json -Method Get -Uri "$base/admin/v1/integrations/payment" -Token $adminToken
|
|
$smsTest = Invoke-Json -Method Post -Uri "$base/admin/v1/integrations/sms/test" -Token $adminToken
|
|
$paymentTest = Invoke-Json -Method Post -Uri "$base/admin/v1/integrations/payment/test" -Token $adminToken
|
|
$audit = Invoke-Json -Method Get -Uri "$base/admin/v1/audit-logs?page=1&size=20" -Token $adminToken
|
|
|
|
[pscustomobject]@{
|
|
health = $health.data.status
|
|
user = $me.nickname
|
|
recommendations = $discover.total
|
|
nearby = $nearby.total
|
|
feed = $feed.total
|
|
plans = $plans.items.Count
|
|
paymentChannels = $channels.items.Count
|
|
searchResults = $search.total
|
|
following = $following.total
|
|
privacyLoaded = ($null -ne $privacy.allowSearch)
|
|
smsDebug = ($sms.provider -eq 'debug')
|
|
conversation = $conversation.id
|
|
messages = $messages.items.Count
|
|
imIdempotent = ($message.id -eq $duplicate.id)
|
|
adminUsers = $adminUsers.total
|
|
adminPosts = $adminPosts.total
|
|
reports = $adminReports.total
|
|
orders = $orders.total
|
|
configs = $configs.items.Count
|
|
smsConfigReady = $smsConfig.configured
|
|
paymentConfigReady = $paymentConfig.configured
|
|
smsTest = $smsTest.success
|
|
paymentTest = $paymentTest.success
|
|
auditLogs = $audit.total
|
|
overviewUsers = $overview.metrics.users
|
|
} | Format-List
|