Files
HAOVP/backend/run_content_comment_recommend_batch.ps1
T

325 lines
23 KiB
PowerShell

$ErrorActionPreference = 'Stop'
function Invoke-Api {
param(
[string]$Method,
[string]$Url,
[hashtable]$Headers = @{},
$Body = $null,
[int]$TimeoutSec = 25
)
try {
$params = @{
Method = $Method
Uri = $Url
Headers = $Headers
UseBasicParsing = $true
SkipHttpErrorCheck = $true
TimeoutSec = $TimeoutSec
}
if ($null -ne $Body) {
if ($Body -is [string]) {
$params.ContentType = 'application/json'
$params.Body = $Body
} else {
$params.ContentType = 'application/json'
$params.Body = ($Body | ConvertTo-Json -Depth 20)
}
}
$resp = Invoke-WebRequest @params
$json = $null
if ($resp.Content) {
try { $json = $resp.Content | ConvertFrom-Json -Depth 50 } catch {}
}
[pscustomobject]@{ http = [int]$resp.StatusCode; json = $json; raw = $resp.Content }
} catch {
[pscustomobject]@{ http = -1; json = $null; raw = $_.Exception.Message }
}
}
function Add-Result {
param(
[System.Collections.Generic.List[object]]$Results,
[string]$Module,
[string]$Method,
[string]$Path,
[string]$Status,
[string]$Note,
[object]$Resp
)
$apiCode = $null
if ($Resp -and $Resp.json -and $null -ne $Resp.json.code) { $apiCode = $Resp.json.code }
$Results.Add([pscustomobject]@{
module = $Module
method = $Method
path = $Path
status = $Status
http = if ($Resp) { $Resp.http } else { $null }
apiCode = $apiCode
note = $Note
})
if ($script:ResultPath) {
[pscustomobject]@{ generatedAt = (Get-Date).ToString('s'); results = $Results } |
ConvertTo-Json -Depth 8 |
Set-Content -Path $script:ResultPath -Encoding utf8BOM
}
}
function Get-UserCaptcha {
$cap = Invoke-Api -Method GET -Url 'http://localhost:9000/auth/captcha'
if ($cap.http -ne 200 -or -not $cap.json) { throw "获取用户验证码失败: $($cap.raw)" }
$key = $cap.json.data.captchaKey
$code = docker exec redis redis-cli -a redis_EsJ8FX --raw GET ('captcha:' + $key)
[pscustomobject]@{ key = $key; code = $code.Trim('"').Trim() }
}
function Get-AdminCaptcha {
$cap = Invoke-Api -Method GET -Url 'http://localhost:9000/admin/auth/captcha'
if ($cap.http -ne 200 -or -not $cap.json) { throw "获取后台验证码失败: $($cap.raw)" }
$key = $cap.json.data.captchaKey
$code = docker exec redis redis-cli -a redis_EsJ8FX -n 5 --raw GET ('admin:captcha:' + $key)
[pscustomobject]@{ key = $key; code = $code.Trim('"').Trim() }
}
function Register-LoginUser {
param([string]$Prefix)
$password = 'Pass@123456'
$username = $Prefix + [guid]::NewGuid().ToString('N').Substring(0,8)
$digits = -join ((48..57) | Get-Random -Count 9 | ForEach-Object { [char]$_ })
$cap = Get-UserCaptcha
$register = Invoke-Api -Method POST -Url 'http://localhost:9000/auth/register' -Body @{
username = $username
password = $password
confirmPassword = $password
email = "$username@example.com"
phone = '13' + $digits
captcha = $cap.code
captchaKey = $cap.key
}
$cap2 = Get-UserCaptcha
$login = Invoke-Api -Method POST -Url 'http://localhost:9000/auth/login' -Body @{
username = $username
password = $password
captcha = $cap2.code
captchaKey = $cap2.key
}
$headers = @{ Authorization = 'Bearer ' + $login.json.data.accessToken }
$current = Invoke-Api -Method GET -Url 'http://localhost:9000/auth/current' -Headers $headers
[pscustomobject]@{
username = $username
password = $password
headers = $headers
userId = [long]$current.json.data.id
}
}
function Get-AdminSession {
$cap = Get-AdminCaptcha
$login = Invoke-Api -Method POST -Url 'http://localhost:9000/admin/auth/login' -Body @{
username = 'admin'
password = 'admin123'
captcha = $cap.code
captchaKey = $cap.key
}
[pscustomobject]@{
headers = @{ Authorization = 'Bearer ' + $login.json.data.token }
login = $login
}
}
$results = [System.Collections.Generic.List[object]]::new()
$script:ResultPath = 'C:\Users\toyas\Desktop\本科毕业设计\参考\workspace\HA-OVP\backend\API_TEST_RESULTS_content_comment_recommend.json'
$userA = Register-LoginUser -Prefix 'ca'
$userB = Register-LoginUser -Prefix 'cb'
$admin = Get-AdminSession
# Categories
$catTree = Invoke-Api -Method GET -Url 'http://localhost:9000/content/category/tree'
Add-Result $results 'video-content' 'GET' '/content/category/tree' ($(if($catTree.json.code -eq 200){'PASSED'}else{'FAILED'})) '分类树' $catTree
$catList = Invoke-Api -Method GET -Url 'http://localhost:9000/content/category/list'
Add-Result $results 'video-content' 'GET' '/content/category/list' ($(if($catList.json.code -eq 200){'PASSED'}else{'FAILED'})) '分类列表' $catList
$firstCategory = @($catList.json.data) | Select-Object -First 1
$categoryId = [long]$firstCategory.id
$publicCatCode = 'pubcat' + [guid]::NewGuid().ToString('N').Substring(0,6)
$publicCatAdd = Invoke-Api -Method POST -Url 'http://localhost:9000/content/category' -Headers $userA.headers -Body @{ name='公开分类'; code=$publicCatCode; parentId=0; level=1; sort=98; status=1 }
Add-Result $results 'video-content' 'POST' '/content/category' ($(if($publicCatAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '新增分类' $publicCatAdd
$catList2 = Invoke-Api -Method GET -Url 'http://localhost:9000/content/category/list'
$publicCat = @($catList2.json.data | Where-Object { $_.code -eq $publicCatCode }) | Select-Object -First 1
if ($publicCat) {
$publicCatUpd = Invoke-Api -Method PUT -Url 'http://localhost:9000/content/category' -Headers $userA.headers -Body @{ id=$publicCat.id; name='公开分类更新'; code=$publicCatCode; parentId=0; level=1; sort=99; status=1 }
$publicCatDel = Invoke-Api -Method DELETE -Url "http://localhost:9000/content/category/$($publicCat.id)" -Headers $userA.headers
Add-Result $results 'video-content' 'PUT' '/content/category' ($(if($publicCatUpd.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新分类' $publicCatUpd
Add-Result $results 'video-content' 'DELETE' '/content/category/{id}' ($(if($publicCatDel.json.code -eq 200){'PASSED'}else{'FAILED'})) '删除分类' $publicCatDel
}
# Tags
$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 $results 'video-content' 'POST' '/content/tag' ($(if($tagUsedAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '添加标签(used)' $tagUsedAdd
Add-Result $results 'video-content' 'POST' '/content/tag' ($(if($tagTempAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '添加标签(temp)' $tagTempAdd
Add-Result $results 'video-content' 'GET' '/content/tag/list' ($(if($tagList.json.code -eq 200){'PASSED'}else{'FAILED'})) '标签列表' $tagList
Add-Result $results 'video-content' 'GET' '/content/tag/page' ($(if($tagPage.json.code -eq 200){'PASSED'}else{'FAILED'})) '标签分页' $tagPage
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 $results 'video-content' 'PUT' '/content/tag' ($(if($tagUpdate.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新标签' $tagUpdate
}
# Favorite list
$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 $results 'video-content' 'POST' '/content/favorite' ($(if($favCreate.json.code -eq 200){'PASSED'}else{'FAILED'})) '创建收藏夹' $favCreate
Add-Result $results 'video-content' 'GET' '/content/favorite/list' ($(if($favList.json.code -eq 200){'PASSED'}else{'FAILED'})) '收藏夹列表' $favList
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 }
Add-Result $results 'video-content' 'PUT' '/content/favorite' ($(if($favUpdate.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新收藏夹' $favUpdate
}
# Video create + publish
$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 $results 'video-content' 'POST' '/content/video' ($(if($createVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '创建视频' $createVideo
$adminVideoReview = Invoke-Api -Method POST -Url "http://localhost:9000/admin/platform/content/video/review/$videoId?status=1&reason=ok" -Headers $admin.headers
Add-Result $results 'video-admin' 'POST' '/admin/platform/content/video/review/{videoId}' ($(if($adminVideoReview.json.code -eq 200){'PASSED'}else{'FAILED'})) '后台审核视频' $adminVideoReview
# Video read/update/interaction
$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"
$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 $results 'video-content' 'GET' '/content/video/public/{id}' ($(if($videoPublicDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '公开视频详情' $videoPublicDetail
Add-Result $results 'video-content' 'GET' '/content/video/{id}' ($(if($videoAuthedDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '登录后视频详情' $videoAuthedDetail
Add-Result $results 'video-content' 'GET' '/content/video/public/list' ($(if($videoPublicList.json.code -eq 200){'PASSED'}else{'FAILED'})) '公开视频列表' $videoPublicList
Add-Result $results 'video-content' 'GET' '/content/video/list' ($(if($videoAuthedList.json.code -eq 200){'PASSED'}else{'FAILED'})) '登录后视频列表' $videoAuthedList
Add-Result $results 'video-content' 'GET' '/content/video/user/{userId}' ($(if($videoUserList.json.code -eq 200){'PASSED'}else{'FAILED'})) '用户视频列表' $videoUserList
Add-Result $results 'video-content' 'PUT' '/content/video' ($(if($videoUpdate.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新视频' $videoUpdate
Add-Result $results 'video-content' 'GET' '/content/tag/video/{videoId}' ($(if($videoTags.json.code -eq 200){'PASSED'}else{'FAILED'})) '视频标签' $videoTags
Add-Result $results 'video-content' 'POST' '/content/video/like/{videoId}' ($(if($likeVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '点赞视频' $likeVideo
Add-Result $results 'video-content' 'DELETE' '/content/video/like/{videoId}' ($(if($unlikeVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消点赞视频' $unlikeVideo
Add-Result $results 'video-content' 'POST' '/content/video/coin/{videoId}' ($(if($coinVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '投币视频' $coinVideo
Add-Result $results 'video-content' 'POST' '/content/video/share/{videoId}' ($(if($shareVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '分享视频' $shareVideo
Add-Result $results 'video-content' 'POST' '/content/video/play' ($(if($playVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '播放记录' $playVideo
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
$favDelete = Invoke-Api -Method DELETE -Url "http://localhost:9000/content/favorite/$($fav.id)" -Headers $userB.headers
Add-Result $results 'video-content' 'POST' '/content/video/favorite' ($(if($favVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '收藏视频' $favVideo
Add-Result $results 'video-content' 'GET' '/content/favorite/{favoriteId}/videos' ($(if($favVideos.json.code -eq 200){'PASSED'}else{'FAILED'})) '收藏夹视频列表' $favVideos
Add-Result $results 'video-content' 'DELETE' '/content/video/favorite/{videoId}' ($(if($unfavVideo.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消收藏视频' $unfavVideo
Add-Result $results 'video-content' 'DELETE' '/content/favorite/{id}' ($(if($favDelete.json.code -eq 200){'PASSED'}else{'FAILED'})) '删除收藏夹' $favDelete
}
# Danmaku/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 $results 'video-content' 'POST' '/content/danmaku' ($(if($danmakuSend.json.code -eq 200){'PASSED'}else{'FAILED'})) '发送弹幕' $danmakuSend
Add-Result $results 'video-content' 'GET' '/content/danmaku/all/{videoId}' ($(if($danmakuAll.json.code -eq 200){'PASSED'}else{'FAILED'})) '全部弹幕' $danmakuAll
Add-Result $results 'video-content' 'GET' '/content/danmaku/time' ($(if($danmakuTime.json.code -eq 200){'PASSED'}else{'FAILED'})) '时间段弹幕' $danmakuTime
Add-Result $results 'video-content' 'GET' '/content/stat/daily/{videoId}' ($(if($statDaily.json.code -eq 200){'PASSED'}else{'FAILED'})) '视频日统计' $statDaily
Add-Result $results 'video-content' 'GET' '/content/stat/play/trend/{videoId}' ($(if($statTrend.json.code -eq 200){'PASSED'}else{'FAILED'})) '播放趋势' $statTrend
Add-Result $results 'video-content' 'GET' '/content/stat/interaction/{videoId}' ($(if($statInteraction.json.code -eq 200){'PASSED'}else{'FAILED'})) '互动统计' $statInteraction
# 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 $results 'video-comment' 'POST' '/comment' ($(if($commentAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '添加评论' $commentAdd
Add-Result $results 'video-comment' 'GET' '/comment/public/list' ($(if($commentList.json.code -eq 200){'PASSED'}else{'FAILED'})) '评论列表' $commentList
Add-Result $results 'video-comment' 'GET' '/comment/public/detail/{id}' ($(if($commentDetail.json.code -eq 200){'PASSED'}else{'FAILED'})) '评论详情' $commentDetail
Add-Result $results 'video-comment' 'GET' '/comment/public/stat/{videoId}' ($(if($commentStat.json.code -eq 200){'PASSED'}else{'FAILED'})) '评论统计' $commentStat
Add-Result $results 'video-comment' 'POST' '/comment/like/{id}' ($(if($likeComment.json.code -eq 200){'PASSED'}else{'FAILED'})) '点赞评论' $likeComment
Add-Result $results 'video-comment' 'DELETE' '/comment/like/{id}' ($(if($unlikeComment.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消点赞评论' $unlikeComment
Add-Result $results 'video-comment' 'POST' '/comment/top/{id}' ($(if($topComment.json.code -eq 200){'PASSED'}else{'FAILED'})) '置顶评论' $topComment
Add-Result $results 'video-comment' 'DELETE' '/comment/top/{id}' ($(if($untopComment.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消置顶评论' $untopComment
Add-Result $results 'video-comment' 'POST' '/comment/reply' ($(if($replyAdd.json.code -eq 200){'PASSED'}else{'FAILED'})) '添加回复' $replyAdd
Add-Result $results 'video-comment' 'GET' '/comment/reply/public/list/{commentId}' ($(if($replyList.json.code -eq 200){'PASSED'}else{'FAILED'})) '回复列表' $replyList
Add-Result $results 'video-comment' 'GET' '/comment/reply/public/hot/{commentId}' ($(if($replyHot.json.code -eq 200){'PASSED'}else{'FAILED'})) '热门回复' $replyHot
Add-Result $results 'video-comment' 'POST' '/comment/reply/like/{id}' ($(if($likeReply.json.code -eq 200){'PASSED'}else{'FAILED'})) '点赞回复' $likeReply
Add-Result $results 'video-comment' 'DELETE' '/comment/reply/like/{id}' ($(if($unlikeReply.json.code -eq 200){'PASSED'}else{'FAILED'})) '取消点赞回复' $unlikeReply
Add-Result $results 'video-comment' 'DELETE' '/comment/reply/{id}' ($(if($deleteReply.json.code -eq 200){'PASSED'}else{'FAILED'})) '删除回复' $deleteReply
# Recommend
$homeRecommend = Invoke-Api -Method GET -Url 'http://localhost:9000/recommend/home'
$hot = Invoke-Api -Method GET -Url 'http://localhost:9000/recommend/hot'
$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 $results 'video-recommend' 'GET' '/recommend/home' ($(if($homeRecommend.json.code -eq 200){'PASSED'}else{'FAILED'})) '首页推荐' $homeRecommend
Add-Result $results 'video-recommend' 'GET' '/recommend/hot' ($(if($hot.json.code -eq 200){'PASSED'}else{'FAILED'})) '热门推荐' $hot
Add-Result $results 'video-recommend' 'GET' '/recommend/similar/{videoId}' ($(if($similar.json.code -eq 200){'PASSED'}else{'FAILED'})) '相似推荐' $similar
Add-Result $results 'video-recommend' 'GET' '/recommend/tag/{tagId}' ($(if($tagRecommend.json.code -eq 200){'PASSED'}else{'FAILED'})) '标签推荐' $tagRecommend
Add-Result $results 'video-recommend' 'POST' '/recommend/behavior' ($(if($behavior.json.code -eq 200){'PASSED'}else{'FAILED'})) '记录行为' $behavior
Add-Result $results 'video-recommend' 'POST' '/recommend/interest/update' ($(if($interestUpdate.json.code -eq 200){'PASSED'}else{'FAILED'})) '更新兴趣' $interestUpdate
$out = [pscustomobject]@{
generatedAt = (Get-Date).ToString('s')
ids = [pscustomobject]@{
userA = $userA.userId
userB = $userB.userId
videoId = $videoId
commentId = $commentId
replyId = $replyId
tagUsedId = $tagUsed.id
}
results = $results
}
$outPath = $script:ResultPath
$out | ConvertTo-Json -Depth 8 | Set-Content -Path $outPath -Encoding utf8BOM
$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