172 lines
9.6 KiB
PowerShell
172 lines
9.6 KiB
PowerShell
param(
|
|
[string]$Base = $(if ($env:IM_SMOKE_BASE) { $env:IM_SMOKE_BASE } else { 'http://127.0.0.1:8888' })
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$base = $Base.TrimEnd('/')
|
|
|
|
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'
|
|
}
|
|
$userRefresh = Invoke-Json -Method Post -Uri "$base/api/v1/auth/token/refresh" -Body @{
|
|
refreshToken = $userSession.refreshToken
|
|
}
|
|
$userToken = $userRefresh.accessToken
|
|
if (-not $userRefresh.refreshToken) { throw 'User refresh-token rotation failed' }
|
|
$me = Invoke-Json -Method Get -Uri "$base/api/v1/me" -Token $userToken
|
|
$verification = Invoke-Json -Method Get -Uri "$base/api/v1/me/verification" -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
|
|
$tags = Invoke-Json -Method Get -Uri "$base/api/v1/tags" -Token $userToken
|
|
$devices = Invoke-Json -Method Get -Uri "$base/api/v1/me/devices" -Token $userToken
|
|
$notificationSettings = Invoke-Json -Method Get -Uri "$base/api/v1/me/notification-settings" -Token $userToken
|
|
$membership = Invoke-Json -Method Get -Uri "$base/api/v1/membership/status" -Token $userToken
|
|
$myOrders = Invoke-Json -Method Get -Uri "$base/api/v1/me/orders?page=1&size=20" -Token $userToken
|
|
$notifications = Invoke-Json -Method Get -Uri "$base/api/v1/notifications?page=1&size=20" -Token $userToken
|
|
$myReports = Invoke-Json -Method Get -Uri "$base/api/v1/me/reports?page=1&size=20" -Token $userToken
|
|
$feedback = Invoke-Json -Method Get -Uri "$base/api/v1/me/feedback" -Token $userToken
|
|
$closure = Invoke-Json -Method Get -Uri "$base/api/v1/me/account-closure" -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
|
|
$recalled = Invoke-Json -Method Post -Uri "$base/api/v1/im/messages/$($message.id)/recall" -Token $userToken
|
|
if (-not $recalled.success) { throw 'IM recall check failed' }
|
|
$duplicateAfterRecall = Invoke-Json -Method Post -Uri "$base/api/v1/im/conversations/$($conversation.id)/messages" -Token $userToken -Body $messageBody
|
|
if ($duplicateAfterRecall.id -ne $message.id -or -not $duplicateAfterRecall.recalled -or $null -ne $duplicateAfterRecall.content) {
|
|
throw 'IM recalled-message idempotency privacy check failed'
|
|
}
|
|
|
|
$adminSession = Invoke-Json -Method Post -Uri "$base/admin/v1/auth/login" -Body @{
|
|
username = 'admin'
|
|
password = 'Admin@123'
|
|
}
|
|
$adminRefresh = Invoke-Json -Method Post -Uri "$base/admin/v1/auth/refresh" -Body @{
|
|
refreshToken = $adminSession.refreshToken
|
|
}
|
|
$adminToken = $adminRefresh.accessToken
|
|
if (-not $adminRefresh.refreshToken) { throw 'Admin refresh-token rotation failed' }
|
|
$adminInfo = Invoke-Json -Method Get -Uri "$base/admin/v1/user/info" -Token $adminToken
|
|
$adminCodes = Invoke-Json -Method Get -Uri "$base/admin/v1/auth/codes" -Token $adminToken
|
|
$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
|
|
$pendingReports = Invoke-Json -Method Get -Uri "$base/admin/v1/reports?page=1&size=20&status=PENDING" -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
|
|
$storageConfig = Invoke-Json -Method Get -Uri "$base/admin/v1/integrations/storage" -Token $adminToken
|
|
$oauthConfig = Invoke-Json -Method Get -Uri "$base/admin/v1/integrations/oauth" -Token $adminToken
|
|
$adminAccounts = Invoke-Json -Method Get -Uri "$base/admin/v1/admin-users" -Token $adminToken
|
|
$adminRoles = Invoke-Json -Method Get -Uri "$base/admin/v1/admin-roles" -Token $adminToken
|
|
$adminPermissions = Invoke-Json -Method Get -Uri "$base/admin/v1/admin-permissions" -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
|
|
$adminFeedback = Invoke-Json -Method Get -Uri "$base/admin/v1/client-feedback?page=1&size=20" -Token $adminToken
|
|
$accountClosures = Invoke-Json -Method Get -Uri "$base/admin/v1/account-closures?page=1&size=20" -Token $adminToken
|
|
$appVersions = Invoke-Json -Method Get -Uri "$base/admin/v1/app-versions?page=1&size=20" -Token $adminToken
|
|
$messageRemoved = Invoke-Json -Method Post -Uri "$base/admin/v1/messages/$($message.id)/moderate" -Token $adminToken -Body @{
|
|
action = 'REMOVE'
|
|
reason = 'automated regression temporary removal'
|
|
}
|
|
$messageRestored = Invoke-Json -Method Post -Uri "$base/admin/v1/messages/$($message.id)/moderate" -Token $adminToken -Body @{
|
|
action = 'RESTORE'
|
|
}
|
|
|
|
[pscustomobject]@{
|
|
health = $health.data.status
|
|
user = $me.nickname
|
|
userVerification = $verification.status
|
|
userRefreshRotated = ($userRefresh.refreshToken -ne $userSession.refreshToken)
|
|
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)
|
|
profileTags = $tags.items.Count
|
|
activeDevices = $devices.items.Count
|
|
notificationsEnabled = $notificationSettings.systemEnabled
|
|
dailyActiveChatLimit = $membership.entitlements.dailyActiveChatLimit
|
|
myOrders = $myOrders.total
|
|
notifications = $notifications.total
|
|
myReports = $myReports.total
|
|
feedbackItems = $feedback.items.Count
|
|
accountClosure = $closure.status
|
|
smsDebug = ($sms.provider -eq 'debug')
|
|
conversation = $conversation.id
|
|
messages = $messages.items.Count
|
|
imIdempotent = ($message.id -eq $duplicate.id)
|
|
imRecall = $recalled.success
|
|
imRecallPrivacy = ($duplicateAfterRecall.recalled -and $null -eq $duplicateAfterRecall.content)
|
|
imAdminModeration = ($messageRemoved.success -and $messageRestored.success)
|
|
adminUsers = $adminUsers.total
|
|
adminAccount = $adminInfo.realName
|
|
adminRefreshRotated = ($adminRefresh.refreshToken -ne $adminSession.refreshToken)
|
|
adminPermissionCodes = $adminCodes.Count
|
|
adminAccounts = $adminAccounts.total
|
|
adminRoles = $adminRoles.items.Count
|
|
adminPermissions = $adminPermissions.items.Count
|
|
adminPosts = $adminPosts.total
|
|
reports = $adminReports.total
|
|
pendingReports = $pendingReports.total
|
|
orders = $orders.total
|
|
configs = $configs.items.Count
|
|
smsConfigReady = $smsConfig.configured
|
|
paymentConfigReady = $paymentConfig.configured
|
|
storageConfigReady = $storageConfig.configured
|
|
storageFields = $storageConfig.fields.Count
|
|
oauthFields = $oauthConfig.fields.Count
|
|
smsTest = $smsTest.success
|
|
paymentTest = $paymentTest.success
|
|
auditLogs = $audit.total
|
|
adminFeedback = $adminFeedback.total
|
|
accountClosures = $accountClosures.total
|
|
appVersions = $appVersions.total
|
|
overviewUsers = $overview.metrics.users
|
|
} | Format-List
|