Files
HAOVP/backend/local_api_test.ps1

409 lines
37 KiB
PowerShell

$ErrorActionPreference = 'Stop'
function Invoke-Api {
param(
[string]$Method,
[string]$Url,
[hashtable]$Headers = @{},
$Body = $null,
[string]$ContentType = 'application/json'
)
$lastResult = $null
for ($attempt = 1; $attempt -le 3; $attempt++) {
try {
$params = @{
Method = $Method
Uri = $Url
Headers = $Headers
SkipHttpErrorCheck = $true
UseBasicParsing = $true
}
if ($null -ne $Body) {
if ($ContentType -eq 'application/json' -and $Body -isnot [string]) {
$params.ContentType = $ContentType
$params.Body = ($Body | ConvertTo-Json -Depth 20)
} else {
$params.ContentType = $ContentType
$params.Body = $Body
}
}
$resp = Invoke-WebRequest @params
$json = $null
if ($resp.Content) {
try { $json = $resp.Content | ConvertFrom-Json -Depth 50 } catch {}
}
$lastResult = [pscustomobject]@{ ok = $true; http = [int]$resp.StatusCode; json = $json; raw = $resp.Content }
if ($lastResult.http -eq 503 -and $attempt -lt 3) {
Start-Sleep -Seconds 2
continue
}
return $lastResult
} catch {
$lastResult = [pscustomobject]@{ ok = $false; http = -1; json = $null; raw = $_.Exception.Message }
if ($attempt -lt 3) {
Start-Sleep -Seconds 2
continue
}
}
}
return $lastResult
}
$results = New-Object System.Collections.Generic.List[object]
function Add-Result {
param([string]$Module,[string]$Method,[string]$Path,[string]$Status,[string]$Note,[int]$Http = 0,[object]$ApiCode = $null)
$results.Add([pscustomobject]@{
module = $Module
method = $Method
path = $Path
status = $Status
http = $Http
apiCode = $ApiCode
note = $Note
})
}
function Get-UserCaptcha {
$cap = Invoke-RestMethod -UseBasicParsing -Uri 'http://localhost:9000/auth/captcha'
$key = $cap.data.captchaKey
$code = docker exec redis redis-cli -a redis_EsJ8FX --raw GET ('captcha:' + $key)
return [pscustomobject]@{ key = $key; code = $code.Trim('"').Trim() }
}
function Get-AdminCaptcha {
$cap = Invoke-RestMethod -UseBasicParsing -Uri 'http://localhost:9000/admin/auth/captcha'
$key = $cap.data.captchaKey
$code = docker exec redis redis-cli -a redis_EsJ8FX -n 5 --raw GET ('admin:captcha:' + $key)
return [pscustomobject]@{ key = $key; code = $code.Trim('"').Trim() }
}
function Register-LoginUser {
param([string]$Prefix,[string]$Password)
$cap = Get-UserCaptcha
$username = $Prefix + [guid]::NewGuid().ToString('N').Substring(0,8)
$digits = -join ((48..57) | Get-Random -Count 9 | ForEach-Object {[char]$_})
$phone = '13' + $digits
$registerBody = @{
username = $username
password = $Password
confirmPassword = $Password
email = "$username@example.com"
phone = $phone
captcha = $cap.code
captchaKey = $cap.key
}
$reg = Invoke-Api -Method POST -Url 'http://localhost:9000/auth/register' -Body $registerBody
$cap2 = Get-UserCaptcha
$loginBody = @{ username = $username; password = $Password; captcha = $cap2.code; captchaKey = $cap2.key }
$login = Invoke-Api -Method POST -Url 'http://localhost:9000/auth/login' -Body $loginBody
$headers = @{ Authorization = 'Bearer ' + $login.json.data.accessToken }
$current = Invoke-Api -Method GET -Url 'http://localhost:9000/auth/current' -Headers $headers
return [pscustomobject]@{
username = $username
password = $Password
register = $reg
login = $login
headers = $headers
userId = [long]$current.json.data.id
refreshToken = $login.json.data.refreshToken
accessToken = $login.json.data.accessToken
}
}
function Get-AdminSession {
$cap = Get-AdminCaptcha
$loginBody = @{ username='admin'; password='admin123'; captcha=$cap.code; captchaKey=$cap.key }
$login = Invoke-Api -Method POST -Url 'http://localhost:9000/admin/auth/login' -Body $loginBody
return [pscustomobject]@{ login = $login; headers = @{ Authorization = 'Bearer ' + $login.json.data.token } }
}
# Security checks
$uNoCaptcha = Invoke-Api -Method POST -Url 'http://localhost:9000/auth/login' -Body @{ username='nouser'; password='wrong' }
Add-Result 'video-auth' 'POST' '/auth/login' ($(if($uNoCaptcha.http -eq 400){'PASSED'}else{'FAILED'})) '用户端无验证码登录应被拦截' $uNoCaptcha.http ($uNoCaptcha.json.code)
$aNoCaptcha = Invoke-Api -Method POST -Url 'http://localhost:9000/admin/auth/login' -Body @{ username='admin'; password='admin123' }
Add-Result 'video-admin' 'POST' '/admin/auth/login' ($(if($aNoCaptcha.http -eq 403){'PASSED'}else{'FAILED'})) '后台无验证码登录应被拦截' $aNoCaptcha.http ($aNoCaptcha.json.code)
# Users
$userA = Register-LoginUser -Prefix 'ua' -Password 'Pass@123456'
$userB = Register-LoginUser -Prefix 'ub' -Password 'Pass@123456'
$userC = Register-LoginUser -Prefix 'uc' -Password 'Pass@123456'
$admin = Get-AdminSession
Add-Result 'video-auth' 'POST' '/auth/register' ($(if($userA.register.json.code -eq 200){'PASSED'}else{'FAILED'})) '创建测试用户A' $userA.register.http $userA.register.json.code
Add-Result 'video-auth' 'POST' '/auth/login' ($(if($userA.login.json.code -eq 200){'PASSED'}else{'FAILED'})) '测试用户A登录' $userA.login.http $userA.login.json.code
Add-Result 'video-auth' 'GET' '/auth/current' ($(if($userA.userId){'PASSED'}else{'FAILED'})) '用户A当前信息' $userA.login.http $userA.login.json.code
# Auth endpoints
$refresh = Invoke-Api -Method POST -Url "http://localhost:9000/auth/refresh?refreshToken=$($userB.refreshToken)"
Add-Result 'video-auth' 'POST' '/auth/refresh' ($(if($refresh.json.code -eq 200){'PASSED'}else{'FAILED'})) '刷新令牌' $refresh.http $refresh.json.code
$usernameById = Invoke-Api -Method GET -Url ('http://localhost:9000/auth/username/' + $userA.userId)
Add-Result 'video-auth' 'GET' '/auth/username/{userId}' ($(if($usernameById.http -eq 200 -and $usernameById.raw -eq $userA.username){'PASSED'}else{'FAILED'})) '根据ID获取用户名' $usernameById.http $null
# User profile/settings/search
$publicProfile = Invoke-Api -Method GET -Url ('http://localhost:9000/user/profile/public/' + $userA.userId)
Add-Result 'video-user' 'GET' '/user/profile/public/{userId}' ($(if($publicProfile.json.code -eq 200){'PASSED'}else{'FAILED'})) '公开资料' $publicProfile.http $publicProfile.json.code
$updateProfile = Invoke-Api -Method PUT -Url 'http://localhost:9000/user/profile' -Headers $userA.headers -Body @{ nickname='测试用户A'; signature='签名A'; region='南京'; gender=1 }
Add-Result 'video-user' 'PUT' '/user/profile' ($(if($updateProfile.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新资料' $updateProfile.http $updateProfile.json.code
$searchUser = Invoke-Api -Method GET -Url "http://localhost:9000/user/profile/search?keyword=$($userA.username)&page=1&size=5"
Add-Result 'video-user' 'GET' '/user/profile/search' ($(if($searchUser.json.code -eq 200){'PASSED'}else{'FAILED'})) '搜索用户' $searchUser.http $searchUser.json.code
$getSetting = Invoke-Api -Method GET -Url 'http://localhost:9000/user/setting' -Headers $userA.headers
Add-Result 'video-user' 'GET' '/user/setting' ($(if($getSetting.json.code -eq 200){'PASSED'}else{'FAILED'})) '获取设置' $getSetting.http $getSetting.json.code
$updateSetting = Invoke-Api -Method PUT -Url 'http://localhost:9000/user/setting' -Headers $userA.headers -Body @{ privacyLevel=1; commentNotify=1; likeNotify=1; followNotify=1; systemNotify=1 }
Add-Result 'video-user' 'PUT' '/user/setting' ($(if($updateSetting.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新设置' $updateSetting.http $updateSetting.json.code
# Follow + notifications
$follow = Invoke-Api -Method POST -Url ('http://localhost:9000/user/follow/' + $userA.userId) -Headers $userB.headers
Add-Result 'video-user' 'POST' '/user/follow/{followId}' ($(if($follow.json.code -eq 200){'PASSED'}else{'FAILED'})) 'B关注A' $follow.http $follow.json.code
$checkFollow = Invoke-Api -Method GET -Url ('http://localhost:9000/user/follow/check/' + $userA.userId) -Headers $userB.headers
Add-Result 'video-user' 'GET' '/user/follow/check/{followId}' ($(if($checkFollow.json.code -eq 200){'PASSED'}else{'FAILED'})) '检查关注' $checkFollow.http $checkFollow.json.code
$following = Invoke-Api -Method GET -Url "http://localhost:9000/user/follow/following/$($userB.userId)?page=1&size=5"
Add-Result 'video-user' 'GET' '/user/follow/following/{userId}' ($(if($following.json.code -eq 200){'PASSED'}else{'FAILED'})) '关注列表' $following.http $following.json.code
$followers = Invoke-Api -Method GET -Url "http://localhost:9000/user/follow/followers/$($userA.userId)?page=1&size=5"
Add-Result 'video-user' 'GET' '/user/follow/followers/{userId}' ($(if($followers.json.code -eq 200){'PASSED'}else{'FAILED'})) '粉丝列表' $followers.http $followers.json.code
$noticeList1 = Invoke-Api -Method GET -Url "http://localhost:9000/user/notification/list?page=1&size=10" -Headers $userA.headers
Add-Result 'video-user' 'GET' '/user/notification/list' ($(if($noticeList1.json.code -eq 200){'PASSED'}else{'FAILED'})) '通知列表' $noticeList1.http $noticeList1.json.code
$noticeUnread1 = Invoke-Api -Method GET -Url 'http://localhost:9000/user/notification/unread/count' -Headers $userA.headers
Add-Result 'video-user' 'GET' '/user/notification/unread/count' ($(if($noticeUnread1.json.code -eq 200){'PASSED'}else{'FAILED'})) '未读通知数' $noticeUnread1.http $noticeUnread1.json.code
$firstNoticeId = $null
if ($noticeList1.json -and $noticeList1.json.data -and $noticeList1.json.data.records -and $noticeList1.json.data.records.Count -gt 0) {
$firstNoticeId = $noticeList1.json.data.records[0].id
}
if ($firstNoticeId) {
$noticeReadOne = Invoke-Api -Method PUT -Url ('http://localhost:9000/user/notification/read/' + $firstNoticeId) -Headers $userA.headers
Add-Result 'video-user' 'PUT' '/user/notification/read/{notificationId}' ($(if($noticeReadOne.json.code -eq 200){'PASSED'}else{'FAILED'})) '标记单条通知已读' $noticeReadOne.http $noticeReadOne.json.code
}
$noticeReadAll = Invoke-Api -Method PUT -Url 'http://localhost:9000/user/notification/read' -Headers $userA.headers
Add-Result 'video-user' 'PUT' '/user/notification/read' ($(if($noticeReadAll.json.code -eq 200){'PASSED'}else{'FAILED'})) '全部通知已读' $noticeReadAll.http $noticeReadAll.json.code
# Messages
$msgSend = Invoke-Api -Method POST -Url 'http://localhost:9000/user/message' -Headers $userB.headers -Body @{ receiverId = $userA.userId; content = 'hello-from-b' }
Add-Result 'video-user' 'POST' '/user/message' ($(if($msgSend.json.code -eq 200){'PASSED'}else{'FAILED'})) '发送私信' $msgSend.http $msgSend.json.code
$msgList = Invoke-Api -Method GET -Url "http://localhost:9000/user/message/list?page=1&size=10" -Headers $userA.headers
Add-Result 'video-user' 'GET' '/user/message/list' ($(if($msgList.json.code -eq 200){'PASSED'}else{'FAILED'})) '会话列表' $msgList.http $msgList.json.code
$msgDetail = Invoke-Api -Method GET -Url "http://localhost:9000/user/message/detail/$($userB.userId)?page=1&size=10" -Headers $userA.headers
Add-Result 'video-user' 'GET' '/user/message/detail/{targetId}' ($(if($msgDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '会话详情' $msgDetail.http $msgDetail.json.code
$msgUnread = Invoke-Api -Method GET -Url 'http://localhost:9000/user/message/unread/count' -Headers $userA.headers
Add-Result 'video-user' 'GET' '/user/message/unread/count' ($(if($msgUnread.json.code -eq 200){'PASSED'}else{'FAILED'})) '未读私信数' $msgUnread.http $msgUnread.json.code
$msgRead = Invoke-Api -Method PUT -Url ('http://localhost:9000/user/message/read/' + $userB.userId) -Headers $userA.headers
Add-Result 'video-user' 'PUT' '/user/message/read/{senderId}' ($(if($msgRead.json.code -eq 200){'PASSED'}else{'FAILED'})) '私信已读' $msgRead.http $msgRead.json.code
# Categories and tags
$catTree = Invoke-Api -Method GET -Url 'http://localhost:9000/content/category/tree'
Add-Result 'video-content' 'GET' '/content/category/tree' ($(if($catTree.json.code -eq 200){'PASSED'}else{'FAILED'})) '分类树' $catTree.http $catTree.json.code
$catList = Invoke-Api -Method GET -Url 'http://localhost:9000/content/category/list'
Add-Result 'video-content' 'GET' '/content/category/list' ($(if($catList.json.code -eq 200){'PASSED'}else{'FAILED'})) '分类列表' $catList.http $catList.json.code
$firstCategory = $null
if ($catList.json -and $catList.json.data) {
$firstCategory = @($catList.json.data) | Select-Object -First 1
}
if (-not $firstCategory) {
throw '无法从 /content/category/list 获取可用分类ID'
}
$categoryId = [long]$firstCategory.id
$tagUsedName = 'tagused-' + [guid]::NewGuid().ToString('N').Substring(0,6)
$tagTempName = 'tagtmp-' + [guid]::NewGuid().ToString('N').Substring(0,6)
$tagUsedAdd = Invoke-Api -Method POST -Url 'http://localhost:9000/content/tag' -Headers $userA.headers -Body @{ name = $tagUsedName }
$tagTempAdd = Invoke-Api -Method POST -Url 'http://localhost:9000/content/tag' -Headers $userA.headers -Body @{ name = $tagTempName }
$tagList = Invoke-Api -Method GET -Url 'http://localhost:9000/content/tag/list'
$tagPage = Invoke-Api -Method GET -Url "http://localhost:9000/content/tag/page?pageNum=1&pageSize=20"
$tagUsed = $tagList.json.data | Where-Object { $_.name -eq $tagUsedName } | Select-Object -First 1
$tagTemp = $tagList.json.data | Where-Object { $_.name -eq $tagTempName } | Select-Object -First 1
Add-Result 'video-content' 'POST' '/content/tag' ($(if($tagUsedAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '添加标签(used)' $tagUsedAdd.http $tagUsedAdd.json.code
Add-Result 'video-content' 'POST' '/content/tag' ($(if($tagTempAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '添加标签(temp)' $tagTempAdd.http $tagTempAdd.json.code
Add-Result 'video-content' 'GET' '/content/tag/list' ($(if($tagList.json.code -eq 200){'PASSED'}else{'FAILED'})) '标签列表' $tagList.http $tagList.json.code
Add-Result 'video-content' 'GET' '/content/tag/page' ($(if($tagPage.json.code -eq 200){'PASSED'}else{'FAILED'})) '标签分页' $tagPage.http $tagPage.json.code
if ($tagTemp) {
$tagUpdate = Invoke-Api -Method PUT -Url 'http://localhost:9000/content/tag' -Headers $userA.headers -Body @{ id = $tagTemp.id; name = ($tagTempName + '-u') }
Add-Result 'video-content' 'PUT' '/content/tag' ($(if($tagUpdate.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新标签' $tagUpdate.http $tagUpdate.json.code
}
# Favorites
$favCreate = Invoke-Api -Method POST -Url 'http://localhost:9000/content/favorite' -Headers $userB.headers -Body @{ name='fav-b'; description='desc'; isPrivate=0 }
$favList = Invoke-Api -Method GET -Url 'http://localhost:9000/content/favorite/list' -Headers $userB.headers
$fav = $favList.json.data | Select-Object -First 1
Add-Result 'video-content' 'POST' '/content/favorite' ($(if($favCreate.json.code -eq 200){'PASSED'}else{'FAILED'})) '创建收藏夹' $favCreate.http $favCreate.json.code
Add-Result 'video-content' 'GET' '/content/favorite/list' ($(if($favList.json.code -eq 200){'PASSED'}else{'FAILED'})) '收藏夹列表' $favList.http $favList.json.code
if ($fav) {
$favUpdate = Invoke-Api -Method PUT -Url 'http://localhost:9000/content/favorite' -Headers $userB.headers -Body @{ id=$fav.id; name='fav-b-upd'; description='desc2'; isPrivate=1 }
$favUpdateStatus = if ($favUpdate.json.code -eq 200) { 'PASSED' } else { 'FAILED' }
Add-Result 'video-content' 'PUT' '/content/favorite' $favUpdateStatus '更新收藏夹' $favUpdate.http $favUpdate.json.code
}
# Create and publish video
$videoBody = @{
title = '测试视频标题12345'
description = '测试视频描述'
categoryId = $categoryId
tagIds = @([long]$tagUsed.id)
coverUrl = 'http://example.com/cover.jpg'
videoUrl = 'http://example.com/video.mp4'
duration = 60
width = 1280
height = 720
format = 'mp4'
size = 123456
}
$createVideo = Invoke-Api -Method POST -Url 'http://localhost:9000/content/video' -Headers $userA.headers -Body $videoBody
$videoId = [long]$createVideo.json.data
Add-Result 'video-content' 'POST' '/content/video' ($(if($createVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '创建视频' $createVideo.http $createVideo.json.code
$adminVideoReview = Invoke-Api -Method POST -Url "http://localhost:9000/admin/platform/content/video/review/$videoId?status=1&reason=ok" -Headers $admin.headers
Add-Result 'video-admin' 'POST' '/admin/platform/content/video/review/{videoId}' ($(if($adminVideoReview.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台审核通过视频' $adminVideoReview.http $adminVideoReview.json.code
# Video/tag details
$videoPublicDetail = Invoke-Api -Method GET -Url ('http://localhost:9000/content/video/public/' + $videoId)
$videoAuthedDetail = Invoke-Api -Method GET -Url ('http://localhost:9000/content/video/' + $videoId) -Headers $userB.headers
$videoPublicList = Invoke-Api -Method GET -Url "http://localhost:9000/content/video/public/list?pageNum=1&pageSize=10"
$videoAuthedList = Invoke-Api -Method GET -Url "http://localhost:9000/content/video/list?pageNum=1&pageSize=10" -Headers $userB.headers
$videoUserList = Invoke-Api -Method GET -Url "http://localhost:9000/content/video/user/$($userA.userId)?pageNum=1&pageSize=10"
$videoUpdate = Invoke-Api -Method PUT -Url 'http://localhost:9000/content/video' -Headers $userA.headers -Body @{ id = $videoId; title='更新后视频标题12345'; description='更新描述'; categoryId=$categoryId; tagIds=@([long]$tagUsed.id) }
$videoTags = Invoke-Api -Method GET -Url ('http://localhost:9000/content/tag/video/' + $videoId)
Add-Result 'video-content' 'GET' '/content/video/public/{id}' ($(if($videoPublicDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '公开视频详情' $videoPublicDetail.http $videoPublicDetail.json.code
Add-Result 'video-content' 'GET' '/content/video/{id}' ($(if($videoAuthedDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '登录后视频详情' $videoAuthedDetail.http $videoAuthedDetail.json.code
Add-Result 'video-content' 'GET' '/content/video/public/list' ($(if($videoPublicList.json.code -eq 200){'PASSED'}else{'FAILED'})) '公开视频列表' $videoPublicList.http $videoPublicList.json.code
Add-Result 'video-content' 'GET' '/content/video/list' ($(if($videoAuthedList.json.code -eq 200){'PASSED'}else{'FAILED'})) '登录后视频列表' $videoAuthedList.http $videoAuthedList.json.code
Add-Result 'video-content' 'GET' '/content/video/user/{userId}' ($(if($videoUserList.json.code -eq 200){'PASSED'}else{'FAILED'})) '用户视频列表' $videoUserList.http $videoUserList.json.code
Add-Result 'video-content' 'PUT' '/content/video' ($(if($videoUpdate.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新视频' $videoUpdate.http $videoUpdate.json.code
Add-Result 'video-content' 'GET' '/content/tag/video/{videoId}' ($(if($videoTags.json.code -eq 200){'PASSED'}else{'FAILED'})) '视频标签' $videoTags.http $videoTags.json.code
# Interactions
$likeVideo = Invoke-Api -Method POST -Url ('http://localhost:9000/content/video/like/' + $videoId) -Headers $userB.headers
$unlikeVideo = Invoke-Api -Method DELETE -Url ('http://localhost:9000/content/video/like/' + $videoId) -Headers $userB.headers
$coinVideo = Invoke-Api -Method POST -Url "http://localhost:9000/content/video/coin/$videoId?amount=1" -Headers $userB.headers
$shareVideo = Invoke-Api -Method POST -Url "http://localhost:9000/content/video/share/$videoId?platform=wechat" -Headers $userB.headers
$playVideo = Invoke-Api -Method POST -Url 'http://localhost:9000/content/video/play' -Headers $userB.headers -Body @{ videoId = $videoId; playTime = 58; isFinished = 1 }
Add-Result 'video-content' 'POST' '/content/video/like/{videoId}' ($(if($likeVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '点赞视频' $likeVideo.http $likeVideo.json.code
Add-Result 'video-content' 'DELETE' '/content/video/like/{videoId}' ($(if($unlikeVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消点赞视频' $unlikeVideo.http $unlikeVideo.json.code
Add-Result 'video-content' 'POST' '/content/video/coin/{videoId}' ($(if($coinVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '投币视频' $coinVideo.http $coinVideo.json.code
Add-Result 'video-content' 'POST' '/content/video/share/{videoId}' ($(if($shareVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '分享视频' $shareVideo.http $shareVideo.json.code
Add-Result 'video-content' 'POST' '/content/video/play' ($(if($playVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '播放记录' $playVideo.http $playVideo.json.code
if ($fav) {
$favVideo = Invoke-Api -Method POST -Url 'http://localhost:9000/content/video/favorite' -Headers $userB.headers -Body @{ videoId = $videoId; favoriteId = [long]$fav.id }
$favVideos = Invoke-Api -Method GET -Url "http://localhost:9000/content/favorite/$($fav.id)/videos?pageNum=1&pageSize=10" -Headers $userB.headers
$unfavVideo = Invoke-Api -Method DELETE -Url ('http://localhost:9000/content/video/favorite/' + $videoId) -Headers $userB.headers
Add-Result 'video-content' 'POST' '/content/video/favorite' ($(if($favVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '收藏视频' $favVideo.http $favVideo.json.code
Add-Result 'video-content' 'GET' '/content/favorite/{favoriteId}/videos' ($(if($favVideos.json.code -eq 200){'PASSED'}else{'FAILED'})) '收藏夹视频列表' $favVideos.http $favVideos.json.code
Add-Result 'video-content' 'DELETE' '/content/video/favorite/{videoId}' ($(if($unfavVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消收藏视频' $unfavVideo.http $unfavVideo.json.code
$favDelete = Invoke-Api -Method DELETE -Url ('http://localhost:9000/content/favorite/' + $fav.id) -Headers $userB.headers
Add-Result 'video-content' 'DELETE' '/content/favorite/{id}' ($(if($favDelete.json.code -eq 200){'PASSED'}else{'FAILED'})) '删除收藏夹' $favDelete.http $favDelete.json.code
}
# Danmaku and stats
$danmakuSend = Invoke-Api -Method POST -Url 'http://localhost:9000/content/danmaku' -Headers $userB.headers -Body @{ videoId=$videoId; content='666'; time=12.5 }
$danmakuAll = Invoke-Api -Method GET -Url ('http://localhost:9000/content/danmaku/all/' + $videoId)
$danmakuTime = Invoke-Api -Method GET -Url "http://localhost:9000/content/danmaku/time?videoId=$videoId&startTime=0&endTime=20"
$statDaily = Invoke-Api -Method GET -Url "http://localhost:9000/content/stat/daily/$videoId?startDate=2026-04-01&endDate=2026-04-30"
$statTrend = Invoke-Api -Method GET -Url ('http://localhost:9000/content/stat/play/trend/' + $videoId)
$statInteraction = Invoke-Api -Method GET -Url ('http://localhost:9000/content/stat/interaction/' + $videoId)
Add-Result 'video-content' 'POST' '/content/danmaku' ($(if($danmakuSend.json.code -eq 200){'PASSED'}else{'FAILED'})) '发送弹幕' $danmakuSend.http $danmakuSend.json.code
Add-Result 'video-content' 'GET' '/content/danmaku/all/{videoId}' ($(if($danmakuAll.json.code -eq 200){'PASSED'}else{'FAILED'})) '全部弹幕' $danmakuAll.http $danmakuAll.json.code
Add-Result 'video-content' 'GET' '/content/danmaku/time' ($(if($danmakuTime.json.code -eq 200){'PASSED'}else{'FAILED'})) '时间段弹幕' $danmakuTime.http $danmakuTime.json.code
Add-Result 'video-content' 'GET' '/content/stat/daily/{videoId}' ($(if($statDaily.json.code -eq 200){'PASSED'}else{'FAILED'})) '视频日统计' $statDaily.http $statDaily.json.code
Add-Result 'video-content' 'GET' '/content/stat/play/trend/{videoId}' ($(if($statTrend.json.code -eq 200){'PASSED'}else{'FAILED'})) '播放趋势' $statTrend.http $statTrend.json.code
Add-Result 'video-content' 'GET' '/content/stat/interaction/{videoId}' ($(if($statInteraction.json.code -eq 200){'PASSED'}else{'FAILED'})) '互动统计' $statInteraction.http $statInteraction.json.code
# Comment/reply
$commentAdd = Invoke-Api -Method POST -Url 'http://localhost:9000/comment' -Headers $userB.headers -Body @{ videoId = $videoId; content = 'comment-from-b' }
$commentId = [long]$commentAdd.json.data
$commentList = Invoke-Api -Method GET -Url "http://localhost:9000/comment/public/list?videoId=$videoId&pageNum=1&pageSize=10"
$commentDetail = Invoke-Api -Method GET -Url ('http://localhost:9000/comment/public/detail/' + $commentId)
$commentStat = Invoke-Api -Method GET -Url ('http://localhost:9000/comment/public/stat/' + $videoId)
$likeComment = Invoke-Api -Method POST -Url ('http://localhost:9000/comment/like/' + $commentId) -Headers $userA.headers
$unlikeComment = Invoke-Api -Method DELETE -Url ('http://localhost:9000/comment/like/' + $commentId) -Headers $userA.headers
$topComment = Invoke-Api -Method POST -Url "http://localhost:9000/comment/top/$commentId?videoId=$videoId" -Headers $userA.headers
$untopComment = Invoke-Api -Method DELETE -Url "http://localhost:9000/comment/top/$commentId?videoId=$videoId" -Headers $userA.headers
$replyAdd = Invoke-Api -Method POST -Url 'http://localhost:9000/comment/reply' -Headers $userA.headers -Body @{ commentId=$commentId; videoId=$videoId; replyToId=$userB.userId; content='reply-from-a' }
$replyId = [long]$replyAdd.json.data
$replyList = Invoke-Api -Method GET -Url "http://localhost:9000/comment/reply/public/list/$commentId?page=1&size=10"
$replyHot = Invoke-Api -Method GET -Url "http://localhost:9000/comment/reply/public/hot/$commentId?limit=3"
$likeReply = Invoke-Api -Method POST -Url ('http://localhost:9000/comment/reply/like/' + $replyId) -Headers $userB.headers
$unlikeReply = Invoke-Api -Method DELETE -Url ('http://localhost:9000/comment/reply/like/' + $replyId) -Headers $userB.headers
$deleteReply = Invoke-Api -Method DELETE -Url ('http://localhost:9000/comment/reply/' + $replyId) -Headers $userA.headers
Add-Result 'video-comment' 'POST' '/comment' ($(if($commentAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '添加评论' $commentAdd.http $commentAdd.json.code
Add-Result 'video-comment' 'GET' '/comment/public/list' ($(if($commentList.json.code -eq 200){'PASSED'}else{'FAILED'})) '评论列表' $commentList.http $commentList.json.code
Add-Result 'video-comment' 'GET' '/comment/public/detail/{id}' ($(if($commentDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '评论详情' $commentDetail.http $commentDetail.json.code
Add-Result 'video-comment' 'GET' '/comment/public/stat/{videoId}' ($(if($commentStat.json.code -eq 200){'PASSED'}else{'FAILED'})) '评论统计' $commentStat.http $commentStat.json.code
Add-Result 'video-comment' 'POST' '/comment/like/{id}' ($(if($likeComment.json.code -eq 200){'PASSED'}else{'FAILED'})) '点赞评论' $likeComment.http $likeComment.json.code
Add-Result 'video-comment' 'DELETE' '/comment/like/{id}' ($(if($unlikeComment.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消点赞评论' $unlikeComment.http $unlikeComment.json.code
Add-Result 'video-comment' 'POST' '/comment/top/{id}' ($(if($topComment.json.code -eq 200){'PASSED'}else{'FAILED'})) '置顶评论' $topComment.http $topComment.json.code
Add-Result 'video-comment' 'DELETE' '/comment/top/{id}' ($(if($untopComment.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消置顶评论' $untopComment.http $untopComment.json.code
Add-Result 'video-comment' 'POST' '/comment/reply' ($(if($replyAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '添加回复' $replyAdd.http $replyAdd.json.code
Add-Result 'video-comment' 'GET' '/comment/reply/public/list/{commentId}' ($(if($replyList.json.code -eq 200){'PASSED'}else{'FAILED'})) '回复列表' $replyList.http $replyList.json.code
Add-Result 'video-comment' 'GET' '/comment/reply/public/hot/{commentId}' ($(if($replyHot.json.code -eq 200){'PASSED'}else{'FAILED'})) '热门回复' $replyHot.http $replyHot.json.code
Add-Result 'video-comment' 'POST' '/comment/reply/like/{id}' ($(if($likeReply.json.code -eq 200){'PASSED'}else{'FAILED'})) '点赞回复' $likeReply.http $likeReply.json.code
Add-Result 'video-comment' 'DELETE' '/comment/reply/like/{id}' ($(if($unlikeReply.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消点赞回复' $unlikeReply.http $unlikeReply.json.code
Add-Result 'video-comment' 'DELETE' '/comment/reply/{id}' ($(if($deleteReply.json.code -eq 200){'PASSED'}else{'FAILED'})) '删除回复' $deleteReply.http $deleteReply.json.code
# Recommend
$similar = Invoke-Api -Method GET -Url "http://localhost:9000/recommend/similar/$videoId?size=10"
$tagRecommend = Invoke-Api -Method GET -Url "http://localhost:9000/recommend/tag/$($tagUsed.id)?size=10"
$behavior = Invoke-Api -Method POST -Url 'http://localhost:9000/recommend/behavior' -Headers $userB.headers -Body @{ videoId = $videoId; behaviorType = 1 }
$interestUpdate = Invoke-Api -Method POST -Url 'http://localhost:9000/recommend/interest/update' -Headers $userB.headers
Add-Result 'video-recommend' 'GET' '/recommend/similar/{videoId}' ($(if($similar.json.code -eq 200){'PASSED'}else{'FAILED'})) '相似推荐' $similar.http $similar.json.code
Add-Result 'video-recommend' 'GET' '/recommend/tag/{tagId}' ($(if($tagRecommend.json.code -eq 200){'PASSED'}else{'FAILED'})) '标签推荐' $tagRecommend.http $tagRecommend.json.code
Add-Result 'video-recommend' 'POST' '/recommend/behavior' ($(if($behavior.json.code -eq 200){'PASSED'}else{'FAILED'})) '记录行为' $behavior.http $behavior.json.code
Add-Result 'video-recommend' 'POST' '/recommend/interest/update' ($(if($interestUpdate.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新兴趣' $interestUpdate.http $interestUpdate.json.code
# Admin detail and management
$adminInfo = Invoke-Api -Method GET -Url 'http://localhost:9000/admin/auth/info' -Headers $admin.headers
Add-Result 'video-admin' 'GET' '/admin/auth/info' ($(if($adminInfo.json.code -eq 200){'PASSED'}else{'FAILED'})) '管理员信息' $adminInfo.http $adminInfo.json.code
$adminUserDetail = Invoke-Api -Method GET -Url ('http://localhost:9000/admin/platform/user/' + $userA.userId) -Headers $admin.headers
Add-Result 'video-admin' 'GET' '/admin/platform/user/{userId}' ($(if($adminUserDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台用户详情' $adminUserDetail.http $adminUserDetail.json.code
$adminDisableUser = Invoke-Api -Method PUT -Url ('http://localhost:9000/admin/platform/user/' + $userC.userId + '/status/0') -Headers $admin.headers
Add-Result 'video-admin' 'PUT' '/admin/platform/user/{userId}/status/{status}' ($(if($adminDisableUser.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台禁用用户' $adminDisableUser.http $adminDisableUser.json.code
$capC = Get-UserCaptcha
$disabledLogin = Invoke-Api -Method POST -Url 'http://localhost:9000/auth/login' -Body @{ username=$userC.username; password=$userC.password; captcha=$capC.code; captchaKey=$capC.key }
Add-Result 'video-auth' 'POST' '/auth/login' ($(if($disabledLogin.json.code -ne 200){'PASSED'}else{'FAILED'})) '禁用用户登录被拦截' $disabledLogin.http $disabledLogin.json.code
$adminEnableUser = Invoke-Api -Method PUT -Url ('http://localhost:9000/admin/platform/user/' + $userC.userId + '/status/1') -Headers $admin.headers
Add-Result 'video-admin' 'PUT' '/admin/platform/user/{userId}/status/{status}' ($(if($adminEnableUser.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台启用用户' $adminEnableUser.http $adminEnableUser.json.code
$adminResetPwd = Invoke-Api -Method PUT -Url "http://localhost:9000/admin/platform/user/$($userC.userId)/reset-password?newPassword=NewPass@123" -Headers $admin.headers
Add-Result 'video-admin' 'PUT' '/admin/platform/user/{userId}/reset-password' ($(if($adminResetPwd.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台重置密码' $adminResetPwd.http $adminResetPwd.json.code
$capC2 = Get-UserCaptcha
$reloginC = Invoke-Api -Method POST -Url 'http://localhost:9000/auth/login' -Body @{ username=$userC.username; password='NewPass@123'; captcha=$capC2.code; captchaKey=$capC2.key }
Add-Result 'video-auth' 'POST' '/auth/login' ($(if($reloginC.json.code -eq 200){'PASSED'}else{'FAILED'})) '重置密码后登录' $reloginC.http $reloginC.json.code
$adminVideoDetail = Invoke-Api -Method GET -Url ('http://localhost:9000/admin/platform/content/video/' + $videoId) -Headers $admin.headers
Add-Result 'video-admin' 'GET' '/admin/platform/content/video/{videoId}' ($(if($adminVideoDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台视频详情' $adminVideoDetail.http $adminVideoDetail.json.code
$adminCategoryList = Invoke-Api -Method GET -Url 'http://localhost:9000/admin/platform/content/category/list' -Headers $admin.headers
Add-Result 'video-admin' 'GET' '/admin/platform/content/category/list' ($(if($adminCategoryList.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台分类列表' $adminCategoryList.http $adminCategoryList.json.code
$catCode = 'cat' + [guid]::NewGuid().ToString('N').Substring(0,6)
$adminCatAdd = Invoke-Api -Method POST -Url 'http://localhost:9000/admin/platform/content/category' -Headers $admin.headers -Body @{ name='后台测试分类'; code=$catCode; parentId=0; level=1; sort=99; status=1 }
Add-Result 'video-admin' 'POST' '/admin/platform/content/category' ($(if($adminCatAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台添加分类' $adminCatAdd.http $adminCatAdd.json.code
$adminCategoryList2 = Invoke-Api -Method GET -Url 'http://localhost:9000/admin/platform/content/category/list' -Headers $admin.headers
$adminCat = $adminCategoryList2.json.data | Where-Object { $_.code -eq $catCode } | Select-Object -First 1
if ($adminCat) {
$adminCatUpd = Invoke-Api -Method PUT -Url 'http://localhost:9000/admin/platform/content/category' -Headers $admin.headers -Body @{ id=$adminCat.id; name='后台测试分类更新'; code=$catCode; parentId=0; level=1; sort=100; status=1 }
$adminCatDel = Invoke-Api -Method DELETE -Url ('http://localhost:9000/admin/platform/content/category/' + $adminCat.id) -Headers $admin.headers
Add-Result 'video-admin' 'PUT' '/admin/platform/content/category' ($(if($adminCatUpd.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台更新分类' $adminCatUpd.http $adminCatUpd.json.code
Add-Result 'video-admin' 'DELETE' '/admin/platform/content/category/{categoryId}' ($(if($adminCatDel.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台删除分类' $adminCatDel.http $adminCatDel.json.code
}
$adminCommentDetail = Invoke-Api -Method GET -Url ('http://localhost:9000/admin/platform/comment/' + $commentId) -Headers $admin.headers
$adminCommentStats = Invoke-Api -Method GET -Url 'http://localhost:9000/admin/platform/comment/stats' -Headers $admin.headers
Add-Result 'video-admin' 'GET' '/admin/platform/comment/{commentId}' ($(if($adminCommentDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台评论详情' $adminCommentDetail.http $adminCommentDetail.json.code
Add-Result 'video-admin' 'GET' '/admin/platform/comment/stats' ($(if($adminCommentStats.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台评论统计' $adminCommentStats.http $adminCommentStats.json.code
$adminCommentDelete = Invoke-Api -Method DELETE -Url ('http://localhost:9000/admin/platform/comment/' + $commentId) -Headers $admin.headers
Add-Result 'video-admin' 'DELETE' '/admin/platform/comment/{commentId}' ($(if($adminCommentDelete.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台删除评论' $adminCommentDelete.http $adminCommentDelete.json.code
$adminDisableVideo = Invoke-Api -Method PUT -Url ('http://localhost:9000/admin/platform/content/video/disable/' + $videoId) -Headers $admin.headers
Add-Result 'video-admin' 'PUT' '/admin/platform/content/video/disable/{videoId}' ($(if($adminDisableVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台下架视频' $adminDisableVideo.http $adminDisableVideo.json.code
$dashboard = Invoke-Api -Method GET -Url 'http://localhost:9000/admin/dashboard/stats' -Headers $admin.headers
Add-Result 'video-admin' 'GET' '/admin/dashboard/stats' ($(if($dashboard.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台仪表盘' $dashboard.http $dashboard.json.code
$unfollow = Invoke-Api -Method DELETE -Url ('http://localhost:9000/user/follow/' + $userA.userId) -Headers $userB.headers
Add-Result 'video-user' 'DELETE' '/user/follow/{followId}' ($(if($unfollow.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消关注' $unfollow.http $unfollow.json.code
$out = [pscustomobject]@{
generatedAt = (Get-Date).ToString('s')
users = @($userA.username,$userB.username,$userC.username)
ids = [pscustomobject]@{ userA=$userA.userId; userB=$userB.userId; userC=$userC.userId; videoId=$videoId; commentId=$commentId; replyId=$replyId; tagUsedId=$tagUsed.id }
results = $results
}
$outPath = 'C:\\Users\\toyas\\Desktop\\本科毕业设计\\参考\\workspace\\HA-OVP\\backend\\API_TEST_RESULTS_LATEST.json'
$out | ConvertTo-Json -Depth 8 | Set-Content -Path $outPath -Encoding UTF8
$passed = ($results | Where-Object { $_.status -eq 'PASSED' }).Count
$failed = ($results | Where-Object { $_.status -eq 'FAILED' }).Count
[pscustomobject]@{ passed=$passed; failed=$failed; file=$outPath } | ConvertTo-Json -Compress