| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826 |
- <#
- .SYNOPSIS
- 健康服务人员助手 · M5 上线试点 · 端到端冒烟脚本(backend-engineer 产出)
- .DESCRIPTION
- 配套 docs/M5_seed.sql 使用:先在试点库执行种子,再启动后端(STORAGE_TYPE=local),最后跑本脚本。
- 覆盖 17 步全链路:管理端登录 → 机构核验 → 身份自举+加成员 → 建批次/发布 → 报名 → 发码签到
- → 学时补跑 → 学时台账 → 派单建单(建单留痕+金额恒等)→ 指派(资质闸口放行/拒绝)→ 四层评价 → 晋升 + 证据包
- → 履约链(到岗/完成/客户确认)→ 客户评价 → 六契约端点。
- .NOTES
- 1) 毕业口径红线 1:学时一律「分钟」整数(120 而非 2.0),本脚本在 S6/S8/S17 强校验。
- 1b) 毕业口径红线 2:金额恒等 amount = platform_fee + staff_income(整数分),S9 反例强校验。
- 2) 登录自举:wechat test-mode(application.yml wechat.test-mode=true)下 openid = 'test_' + code,
- 命中 seed 预置的 test_m5t1 / test_m5none / test_m5stu 三个用户,无需人工取 userId。
- 3) 组织派单只走 assign,不调 /api/order/accept —— claimOrder 的 CAS 是
- `status='pending' AND worker_id=#{userId}`,语义为「自接单」(建单时 worker_id 已=self);
- 组织建单 worker_id=NULL,assignOrder 指派即置 accepted,不存在 accept 窗口(Q2 裁决:不改)。
- 4) STORAGE_TYPE=local:默认 storage.type=jdcloud 会写生产 OSS bucket「aimate」;
- 冒烟/测试启动必须 STORAGE_TYPE=local 让证据包落 ./uploads,严禁污染生产 OSS。
- 5) 兼容 PowerShell 5.1,仅依赖 Invoke-RestMethod(不依赖 curl.exe / PS7)。
- 6) S13-S17 履约链非幂等(状态机单向):S9 每轮新单驱动,反例单另建一次性 accepted 单;
- S9 金额恒等反例会再建一单(死于 MoneyCheck.check,不落库)。
- .EXAMPLE
- powershell -ExecutionPolicy Bypass -File docs/M5_smoke.ps1 -BaseUrl http://127.0.0.1:9083
- #>
- [CmdletBinding()]
- param(
- [string]$BaseUrl = 'http://127.0.0.1:9083',
- # 管理端账号(DatabaseInitializer 启动自举 admin/admin123)
- [string]$AdminUser = 'admin',
- [string]$AdminPass = 'admin123',
- # 服务人员/学员 userId(可选)。留空 = 由 wechat-login 自举自动发现(推荐,配合 seed)。
- # 如需显式注入(部署时替换 token 占位,勿留假 id):
- # -T1WorkerUserId :T1_WORKER_USER_ID: -NoneWorkerUserId :NONE_WORKER_USER_ID: -StudentUserId :STUDENT_USER_ID:
- [string]$T1WorkerUserId = '',
- [string]$NoneWorkerUserId = '',
- [string]$StudentUserId = '',
- # 证据包轮询
- [int]$PollTimes = 10,
- [int]$PollIntervalSec = 2
- )
- $ErrorActionPreference = 'Stop'
- $script:BaseUrl = $BaseUrl
- $script:Step = 0
- $script:FailCount = 0
- # ============================================================
- # helpers
- # ============================================================
- function Invoke-Api {
- <# 统一 API 调用。后端契约:HTTP 200 + body{code,message,data},业务失败 code!=200。
- 鉴权:Authorization 头直接放 token(admin token 已带 'admin:' 前缀,user token 为裸 JWT)。#>
- param(
- [Parameter(Mandatory=$true)][string]$Method,
- [Parameter(Mandatory=$true)][string]$Path,
- [string]$Token = '',
- [object]$Body = $null
- )
- $url = $script:BaseUrl.TrimEnd('/') + $Path
- $headers = @{ 'Accept' = 'application/json' }
- if ($Token -ne '') { $headers['Authorization'] = $Token }
- $invoke = @{ Uri = $url; Method = $Method; Headers = $headers; UseBasicParsing = $true; TimeoutSec = 30 }
- if ($null -ne $Body) {
- $invoke['Body'] = $Body | ConvertTo-Json -Depth 20 -Compress
- $invoke['ContentType'] = 'application/json; charset=utf-8'
- }
- try {
- # PATCH(UTF-8): 后端 Content-Type=application/json 无 charset,PS5.1 IRM 按 Latin-1 解码致中文乱码,
- # 令 S10 资质不符 / S4 批次号已存在 的中文 -match 失配。仅对 message 做 Latin-1→UTF-8 roundtrip 修复,
- # 其余结构保持 IRM 原生解析(避免 Invoke-WebRequest 对部分响应流读取为空)。
- $r = Invoke-RestMethod @invoke
- if ($r -and $r.message) {
- $m = [string]$r.message
- try {
- $fixed = [Text.Encoding]::UTF8.GetString([Text.Encoding]::GetEncoding(28591).GetBytes($m))
- if ($fixed -match '[\u4e00-\u9fff]') { $r.message = $fixed }
- } catch {}
- }
- return $r
- }
- catch {
- # HTTP 非 2xx:尝试读响应体(后端可能直接返回 Result JSON)
- if ($_.Exception.Response) {
- try {
- $sr = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
- $errBody = $sr.ReadToEnd()
- if ($errBody) {
- $parsed = $errBody | ConvertFrom-Json
- if ($null -ne $parsed -and $null -ne $parsed.code) { return $parsed }
- }
- } catch {}
- }
- return [pscustomobject]@{ code = -1; message = ('TRANSPORT_ERROR: ' + $_.Exception.Message); data = $null }
- }
- }
- function Get-Arr($v) {
- if ($null -eq $v) { return @() }
- return @($v)
- }
- function Assert-Fail {
- <# 断言失败:标红并立即退出(冒烟门禁语义)#>
- param([string]$StepName, $Resp, [string]$Detail)
- $httpCode = -1
- if ($null -ne $Resp -and $null -ne $Resp.code) { $httpCode = [int]$Resp.code }
- $msg = '(no message)'
- if ($null -ne $Resp -and $null -ne $Resp.message) { $msg = [string]$Resp.message }
- Write-Host ("S{0} [FAIL] {1} HTTP={2} {3} | msg={4}" -f $script:Step, $StepName, $httpCode, $Detail, $msg) -ForegroundColor Red
- $script:FailCount = $script:FailCount + 1
- exit 1
- }
- function Assert-Pass {
- param([string]$StepName, $Resp, [string]$Detail)
- $httpCode = -1
- if ($null -ne $Resp -and $null -ne $Resp.code) { $httpCode = [int]$Resp.code }
- Write-Host ("S{0} [PASS] {1} HTTP={2} {3}" -f $script:Step, $StepName, $httpCode, $Detail) -ForegroundColor Green
- }
- function Assert-True {
- param([bool]$Cond, [string]$StepName, $Resp, [string]$Detail)
- if ($Cond) { Assert-Pass -StepName $StepName -Resp $Resp -Detail $Detail }
- else { Assert-Fail -StepName $StepName -Resp $Resp -Detail $Detail }
- }
- function Begin-Step([string]$Name) {
- $script:Step = $script:Step + 1
- Write-Host ("`n===== S{0} {1} =====" -f $script:Step, $Name) -ForegroundColor Cyan
- }
- function Fix-MojibakeText([string]$s) {
- <# IRM 对 application/json 无 charset 的中文响应按 Latin-1 解码致乱码(S10 同源缺陷)。
- 仅对已知含中文的出参字段做 Latin-1→UTF-8 roundtrip;调用方仅用修复值做展示/打印,
- 不做 -match 断言(编码不可控时宁可只断言字段存在性)。#>
- if ([string]::IsNullOrEmpty($s)) { return '' }
- try {
- $fixed = [Text.Encoding]::UTF8.GetString([Text.Encoding]::GetEncoding(28591).GetBytes($s))
- if ($fixed -match '[\u4e00-\u9fff]') { return $fixed }
- } catch {}
- return $s
- }
- function Test-MinuteInteger($v) {
- <# 分钟整数红线:值必须为非负整数(拒绝小时/浮点/负数)#>
- if ($null -eq $v) { return $false }
- $n = 0
- if (-not [long]::TryParse([string]$v, [ref]$n)) { return $false }
- if ($n -lt 0) { return $false }
- $d = [double]$v
- return ($d -eq [math]::Floor($d))
- }
- # ============================================================
- # S1 管理端登录
- # ============================================================
- Begin-Step '管理端登录 /api/admin/auth/login'
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/auth/login' -Body @{ username = $AdminUser; password = $AdminPass }
- $adminToken = ''
- if ($resp.code -eq 200 -and $resp.data -and $resp.data.token) { $adminToken = [string]$resp.data.token }
- Assert-True ([bool]($resp.code -eq 200 -and $adminToken -ne '')) 'admin login 取 token' $resp ("tokenLen=" + $adminToken.Length)
- # ============================================================
- # S2 机构核验 + 三身份登录自举
- # ============================================================
- Begin-Step '机构核验 /api/admin/org/list + 身份自举 /api/auth/wechat-login'
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/list' -Token $adminToken -Body @{}
- Assert-True ($resp.code -eq 200) 'org/list 可用' $resp ''
- $orgId = $null
- foreach ($row in (Get-Arr $resp.data.list)) {
- if ($row.orgCode -eq 'PILOT-HS-001') { $orgId = [long]$row.id; break }
- }
- if ($null -eq $orgId) {
- Assert-Fail '捕获种子机构 PILOT-HS-001' $resp '未找到 org_code=PILOT-HS-001,请先执行 docs/M5_seed.sql'
- }
- Assert-Pass '捕获种子机构 PILOT-HS-001' $resp ("orgId=" + $orgId)
- # 身份自举:test-mode openid='test_'+code 命中 seed 预置用户
- $loginUser = {
- param([string]$code)
- $r = Invoke-Api -Method 'POST' -Path '/api/auth/wechat-login' -Body @{ code = $code }
- if ($r.code -ne 200 -or -not $r.data -or -not $r.data.token -or -not $r.data.userId) {
- Assert-Fail ("wechat-login 自举 code=" + $code) $r 'token/userId 缺失'
- }
- return [pscustomobject]@{ token = [string]$r.data.token; userId = [long]$r.data.userId }
- }
- $uT1 = & $loginUser 'm5t1' # T1 已认证服务人员(seed: org_admin)
- $uNone = & $loginUser 'm5none' # 未认证服务人员(seed: dispatcher)
- $uStu = & $loginUser 'm5stu' # 培训学员
- # 显式参数覆盖(部署期注入时以参数为准)
- if ($T1WorkerUserId -ne '') { $uT1.userId = [long]$T1WorkerUserId }
- if ($NoneWorkerUserId -ne '') { $uNone.userId = [long]$NoneWorkerUserId }
- if ($StudentUserId -ne '') { $uStu.userId = [long]$StudentUserId }
- $t1Token = $uT1.token; $t1UserId = $uT1.userId
- $noneToken = $uNone.token; $noneUserId = $uNone.userId
- $stuToken = $uStu.token; $stuUserId = $uStu.userId
- Assert-Pass '三身份自举 m5t1/m5none/m5stu' $resp ("T1=$t1UserId none=$noneUserId stu=$stuUserId")
- # ============================================================
- # S3 组织加成员(m5t1 以 org_admin 身份加成员;已是成员则跳过,保持 org_admin 身份)
- # ============================================================
- Begin-Step '组织加成员 /api/admin/org/member/add(org_admin 身份,非 admin token)'
- # 幂等守卫(重跑不挂):train_org_member 单角色(uk org_id+user_id),把 m5t1 自加为
- # lecturer 会消耗掉 org_admin 身份——而守卫 requireOrgAdmin 恰依赖 org_admin,重跑必失败。
- # 已是机构成员即证明加成员链路可用,跳过自加以保持 org_admin(后续 S6 发码走机构管理者权限)。
- $clist = Invoke-Api -Method 'POST' -Path '/api/admin/org/member/list' -Token $adminToken -Body @{ orgId = $orgId }
- $t1AlreadyMember = $false
- foreach ($row in (Get-Arr $clist.data)) {
- if ($row.userId -ne $null -and [long]$row.userId -eq $t1UserId) { $t1AlreadyMember = $true; break }
- }
- if (-not $t1AlreadyMember) {
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/member/add' -Token $t1Token -Body @{
- orgId = $orgId; userId = $t1UserId; role = 'lecturer'
- }
- Assert-True ($resp.code -eq 200) 'm5t1 以 org_admin 自加为 lecturer' $resp ''
- } else {
- Assert-True $true 'm5t1 已是机构成员(跳过自加,保持 org_admin 身份)' $clist ("memberId=" + $t1UserId)
- }
- # member/list 复核
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/member/list' -Token $adminToken -Body @{ orgId = $orgId }
- $found = $false
- foreach ($row in (Get-Arr $resp.data)) {
- if ([long]$row.userId -eq $t1UserId) { $found = $true; break }
- }
- Assert-True ($resp.code -eq 200 -and $found) 'member/list 含 m5t1' $resp ("memberId=" + $t1UserId)
- # ============================================================
- # S4 课程自举 + 建批次 + 发布
- # ============================================================
- Begin-Step '课程自举 /api/admin/course/list → 建批次 /api/admin/cohort/create → publish'
- $courseId = $null
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/course/list' -Token $adminToken -Body @{}
- foreach ($c in (Get-Arr $resp.data)) {
- if ($c.level -eq 'L9') { $courseId = [long]$c.id; break }
- }
- if ($null -eq $courseId) {
- # seed 已建 L9;此处兜底(与 seed 的 uk_level 幂等配合:仅查不到才建)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/course/create' -Token $adminToken -Body @{
- level = 'L9'; name = 'M5试点·健康服务人员认证实训'; status = 'active'
- price = 0; memberPrice = 0
- }
- if ($resp.code -ne 200 -or -not $resp.data -or -not $resp.data.id) {
- Assert-Fail 'L9 课程缺失且创建失败' $resp '请确认 docs/M5_seed.sql 已执行'
- }
- $courseId = [long]$resp.data.id
- }
- Assert-Pass 'L9 课程就绪' $resp ("courseId=" + $courseId)
- $cohortName = 'M5试点-健康服务人员实训批次01'
- $cohortCode = 'M5-COHORT-001'
- $cohortId = $null
- # 先按 courseId 查已有批次(幂等:复用,避免 uk_code 冲突)
- $resp = Invoke-Api -Method 'POST' -Path '/api/cohort/list' -Token $adminToken -Body @{ courseId = $courseId; page = 1; size = 20 }
- foreach ($c in (Get-Arr $resp.data)) {
- if ($c.code -eq $cohortCode) { $cohortId = [long]$c.cohortId; break }
- }
- if ($null -eq $cohortId) {
- # 学时一律分钟整数:理论 2400(=40h)、实践 1200(=20h)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/create' -Token $adminToken -Body @{
- courseId = $courseId
- name = $cohortName
- code = $cohortCode
- capacity = 50
- place = '浠艾福试点实训基地'
- lecturerId = $t1UserId # 讲师=m5t1,供 S6 讲师侧发码走讲师兜底
- creditHours = 3600 # 3600 分钟 = 60h
- creditTheoryHours = 2400 # 2400 分钟(红线:分钟整数)
- creditPracticeHours = 1200 # 1200 分钟(红线:分钟整数)
- startAt = '2026-12-01 09:00:00'
- endAt = '2026-12-31 18:00:00'
- signupDeadline = '2026-11-30 23:59:59'
- }
- if ($resp.code -ne 200 -or -not $resp.data -or -not $resp.data.cohortId) {
- # 批次号唯一冲突:可能存在上一轮遗留的 draft 批次(/api/cohort/list 只列 published,查不到)
- $msg = if ($resp.message) { [string]$resp.message } else { '' }
- if ($msg -match '批次号已存在') {
- Assert-Fail '存在未发布的 draft 批次 M5-COHORT-001' $resp '请手动 publish 该批次,或换批次号后重跑(避免 uk_code 冲突)'
- }
- Assert-Fail '建批次失败' $resp ''
- }
- $cohortId = [long]$resp.data.cohortId
- }
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/detail' -Token $adminToken -Body @{ cohortId = $cohortId }
- Assert-True ($resp.code -eq 200 -and $resp.data) '批次详情可查' $resp ("cohortId=" + $cohortId)
- $theory = [long]$resp.data.creditTheoryHours
- $practice = [long]$resp.data.creditPracticeHours
- Assert-True (($theory -eq 2400) -and ($practice -eq 1200)) '批次学时=理论2400/实践1200(分钟)' $resp ("theory=$theory practice=$practice")
- if ($resp.data.status -eq 'draft') {
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/publish' -Token $adminToken -Body @{ cohortId = $cohortId }
- Assert-True ($resp.code -eq 200 -and $resp.data.status -eq 'published') '发布批次 draft→published' $resp ''
- } else {
- Assert-True ($resp.data.status -eq 'published') '批次已处于 published(幂等复用)' $resp ("status=" + $resp.data.status)
- }
- # ============================================================
- # S5 学员报名 + 幂等复跑
- # ============================================================
- Begin-Step '学员报名 /api/cohort/signup(幂等)'
- $resp = Invoke-Api -Method 'POST' -Path '/api/cohort/signup' -Token $stuToken -Body @{ cohortId = $cohortId }
- Assert-True ($resp.code -eq 200 -and $resp.data) '学员首次报名' $resp ("signupId=" + $resp.data.signupId + " status=" + $resp.data.status)
- $signupId = [long]$resp.data.signupId
- # 幂等复跑:二次报名应返回「已报名」的成功体,而非业务报错
- $resp2 = Invoke-Api -Method 'POST' -Path '/api/cohort/signup' -Token $stuToken -Body @{ cohortId = $cohortId }
- Assert-True ($resp2.code -eq 200 -and $resp2.data.signupId -eq $signupId) '报名幂等(二次调用返回同 signupId)' $resp2 ("signupId=" + $resp2.data.signupId)
- # 管理端审核通过 pending→approved(签到前置);已 approved 则跳过(重跑幂等)
- if ([string]$resp.data.status -eq 'pending') {
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/auditSignup' -Token $adminToken -Body @{ signupId = $signupId; pass = $true }
- Assert-True ($resp.code -eq 200 -and $resp.data.status -eq 'approved') '报名审核 approved' $resp ("status=" + $resp.data.status)
- } else {
- Assert-True ([string]$resp.data.status -eq 'approved') '报名已 approved(重跑幂等,跳过审核)' $resp ("status=" + $resp.data.status)
- }
- # 报名列表复核
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/signupList' -Token $adminToken -Body @{ cohortId = $cohortId; page = 1; size = 10 }
- $approvedCnt = 0
- foreach ($row in (Get-Arr $resp.data.list)) {
- if ($row.status -eq 'approved') { $approvedCnt = $approvedCnt + 1 }
- }
- Assert-True ($resp.code -eq 200 -and $approvedCnt -ge 1) 'signupList 含 approved' $resp ("approved=" + $approvedCnt)
- # ============================================================
- # S6 发码(讲师侧)+ 学员签到
- # ============================================================
- Begin-Step '发码 /api/attendance/session/code → 学员签到 /api/attendance/scan'
- $sessionId = "${cohortId}:1"
- $resp = Invoke-Api -Method 'POST' -Path '/api/attendance/session/code' -Token $t1Token -Body @{
- sessionId = $sessionId; sessionHours = 120; category = 'theory'
- }
- if ($resp.code -ne 200) {
- # 兜底:复用历史批次可能未设 lecturerId=m5t1(讲师兜底失效)→ 用 admin 放行
- Write-Host ("S{0} [WARN] 讲师发码失败({1}),回退 admin 发码" -f $script:Step, $resp.message) -ForegroundColor Yellow
- $resp = Invoke-Api -Method 'POST' -Path '/api/attendance/session/code' -Token $adminToken -Body @{
- sessionId = $sessionId; sessionHours = 120; category = 'theory'
- }
- }
- Assert-True ($resp.code -eq 200 -and $resp.data -and $resp.data.code) '讲师/组织者发码' $resp ("sessionId=" + $sessionId)
- $attendCode = [string]$resp.data.code
- $codeHours = [long]$resp.data.hours
- Assert-True ($codeHours -eq 120) '签到码 sessionHours=120(分钟整数红线)' $resp ("hours=$codeHours")
- # 学员扫码签到(幂等):断言 hours=120 且入 pending 台账
- $resp = Invoke-Api -Method 'POST' -Path '/api/attendance/scan' -Token $stuToken -Body @{ code = $attendCode }
- $attHours = if ($resp.data -and $null -ne $resp.data.hours) { [long]$resp.data.hours } else { -1 }
- $attStatus = if ($resp.data -and $resp.data.status) { [string]$resp.data.status } else { '' }
- Assert-True ($resp.code -eq 200 -and $attHours -eq 120) '学员签到 hours=120' $resp ("attendanceId=" + $resp.data.attendanceId + " hours=$attHours status=$attStatus")
- Assert-True ($attStatus -eq 'pending') '签到台账 status=pending(T+3 生效)' $resp ("status=$attStatus")
- # 幂等复扫:不重复入账
- $resp2 = Invoke-Api -Method 'POST' -Path '/api/attendance/scan' -Token $stuToken -Body @{ code = $attendCode }
- $dupHours = if ($resp2.data -and $null -ne $resp2.data.hours) { [long]$resp2.data.hours } else { -1 }
- $dupFlag = if ($resp2.data -and $null -ne $resp2.data.alreadyExists) { [bool]$resp2.data.alreadyExists } else { $false }
- Assert-True ($resp2.code -eq 200 -and $dupHours -eq 120 -and $dupFlag) '签到幂等(alreadyExists=true)' $resp2 ("alreadyExists=$dupFlag")
- # ============================================================
- # S7 admin 补跑学时(T+3 到期生效 + 异议回滚 + cfc 重推)
- # ============================================================
- Begin-Step 'admin 补跑 /api/admin/credit/scan'
- # 注意:签到当刻 effective_at = now + 3 天,补跑不会把新台账置 effective(符合 T+3 设计)。
- # 本步断言的是「补跑端点可执行、返回计数」,而非 effectiveCount 必须≥1。
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/credit/scan' -Token $adminToken -Body @{}
- $effCnt = -1
- if ($resp.code -eq 200 -and $resp.data -and $null -ne $resp.data.effectiveCount) { $effCnt = [long]$resp.data.effectiveCount }
- Assert-True ($resp.code -eq 200) 'credit/scan 可执行(T+3 未到期容差:effectiveCount 可为 0)' $resp ("effectiveCount=$effCnt")
- # 待生效台账复核(admin 视角)
- # 注意:Invoke-RestMethod 对单元素 JSON 数组会解包成单个对象,$pendRows.Count 取空 →
- # 必须 @() 强制数组化再取 Count(PS 5.1 解析坑,非产品缺陷)。
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/credit/ledgerPending' -Token $adminToken -Body @{ page = 1; size = 10 }
- $pendRows = @($resp.data.list)
- Assert-True ($resp.code -eq 200 -and $pendRows.Count -ge 1) 'admin 待生效台账非空' $resp ("rows=" + $pendRows.Count)
- # ============================================================
- # S8 学员查学时(分钟整数红线)
- # ============================================================
- Begin-Step '学员学时 /api/credit/mine(分钟整数红线)'
- $resp = Invoke-Api -Method 'POST' -Path '/api/credit/mine' -Token $stuToken -Body @{}
- if ($resp.code -ne 200 -or -not $resp.data) { Assert-Fail 'credit/mine 可用' $resp '' }
- $total = [long]$resp.data.totalHours
- $theoryH = [long]$resp.data.theoryHours
- $practice = [long]$resp.data.practiceHours
- $effH = [long]$resp.data.effectiveHours
- $pendH = [long]$resp.data.pendingHours
- $allInt = (Test-MinuteInteger $total) -and (Test-MinuteInteger $theoryH) -and (Test-MinuteInteger $practice) -and (Test-MinuteInteger $effH) -and (Test-MinuteInteger $pendH)
- Assert-True $allInt '学时五字段均为分钟整数(非小时/浮点)' $resp ("total=$total theory=$theoryH practice=$practice effective=$effH pending=$pendH")
- Assert-True ($pendH -ge 120) '待生效学时 ≥ 120 分钟(签到入账)' $resp ("pending=$pendH")
- # 待生效明细
- $resp = Invoke-Api -Method 'POST' -Path '/api/credit/pending' -Token $stuToken -Body @{}
- $ok = $resp.code -eq 200
- $matched = $false
- foreach ($row in (Get-Arr $resp.data)) {
- if ([long]$row.hours -eq 120 -and $row.status -eq 'pending') { $matched = $true; break }
- }
- Assert-True ($ok -and $matched) 'credit/pending 含 120 分钟 pending 明细' $resp ''
- # ============================================================
- # S9 派单建单(建单留痕:dispatchId 必非空)
- # ============================================================
- Begin-Step '派单建单 /api/admin/org/dispatch/create(断言 dispatchId 非空)'
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/create' -Token $adminToken -Body @{
- orgId = $orgId
- familyName = '王阿姨家'
- contactPhone = '13900000009'
- address = '湖北省黄冈市浠水县试点路 1 号'
- serviceType = 'cleaning'
- orderDate = '2026-12-05'
- amount = 18000 # 整数分
- platformFee = 1800 # 整数分
- remark = 'M5 冒烟建单'
- }
- if ($resp.code -ne 200 -or -not $resp.data) { Assert-Fail '组织建单失败' $resp '' }
- $orderId = [long]$resp.data.orderId
- $orderNo = [string]$resp.data.orderNo
- $dispatchId = $resp.data.dispatchId
- Assert-True ($null -ne $dispatchId -and [long]$dispatchId -gt 0) '建单留痕 dispatchId 非空(created 行同事务落库)' $resp ("orderId=$orderId orderNo=$orderNo dispatchId=$dispatchId")
- Assert-True ([string]$resp.data.status -eq 'pending') '建单只置 pending(不置 accepted)' $resp ("status=" + $resp.data.status)
- # 金额恒等红线(HEAD 5aad440 已落地 MoneyCheck.check):amount<platformFee → 硬拒绝「金额口径不正确」
- $negMoney = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/create' -Token $adminToken -Body @{
- orgId = $orgId; familyName = '金额反例户'; contactPhone = '13900000111'
- address = '湖北省黄冈市浠水县试点路 3 号'; serviceType = 'cleaning'
- orderDate = '2026-12-05'; amount = 1000; platformFee = 1800; remark = 'M5 金额恒等反例'
- }
- $negMoneyMsg = if ($negMoney.message) { [string]$negMoney.message } else { '' }
- Assert-True (($negMoney.code -ne 200) -and ($negMoneyMsg -match '金额口径不正确')) '金额恒等反例 amount(1000)<platformFee(1800) 被拒' $negMoney ("msg=$negMoneyMsg")
- # 派单列表可见 + 金额恒等正例(staff_income = amount - platform_fee = 16200)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/list' -Token $adminToken -Body @{ orgId = $orgId; page = 1; size = 10 }
- $seen = $false
- $identityOk = $false
- foreach ($row in (Get-Arr $resp.data.list)) {
- if ([long]$row.id -eq $orderId) {
- $seen = $true
- $identityOk = ([long]$row.amount -eq 18000 -and [long]$row.platformFee -eq 1800 -and [long]$row.staffIncome -eq 16200)
- break
- }
- }
- Assert-True ($resp.code -eq 200 -and $seen) 'dispatch/list 可见新单' $resp ''
- Assert-True $identityOk '金额恒等正例 staff_income(16200) = amount(18000) - platform_fee(1800)' $resp ''
- # ============================================================
- # S10 指派(资质闸口:m5none 拒绝 / m5t1 放行);只走 assign 不走 accept
- # ============================================================
- Begin-Step '指派 /api/admin/org/dispatch/assign(资质闸口放行/拒绝)'
- # 反例:未认证 m5none → 资质不符
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/assign' -Token $adminToken -Body @{
- orderId = $orderId; workerId = $noneUserId; serviceType = 'cleaning'
- }
- $rejectMsg = if ($resp.message) { [string]$resp.message } else { '' }
- Assert-True (($resp.code -ne 200) -and ($rejectMsg -match '资质不符')) '未认证 m5none 被资质闸口拒绝' $resp ("msg=$rejectMsg")
- # 正例:T1 m5t1 → 放行($T1WorkerUserId 空则已由自举补齐,必非空)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/assign' -Token $adminToken -Body @{
- orderId = $orderId; workerId = $t1UserId; serviceType = 'cleaning'; remark = '指派 T1 服务人员'
- }
- Assert-True ($resp.code -eq 200 -and [string]$resp.data.status -eq 'accepted' -and [long]$resp.data.workerId -eq $t1UserId) 'T1 m5t1 指派放行 → accepted' $resp ("workerId=" + $resp.data.workerId + " status=" + $resp.data.status)
- # 可选服务人员候选(含 m5t1,含 rating=450)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/workers' -Token $adminToken -Body @{ orgId = $orgId }
- $hasT1 = $false
- foreach ($w in (Get-Arr $resp.data.list)) {
- if ([long]$w.userId -eq $t1UserId -and $w.authLevel -eq 'T1') { $hasT1 = $true; break }
- }
- Assert-True ($resp.code -eq 200 -and $hasT1) 'workers 候选含 T1 m5t1' $resp ''
- # 组织派单只走 assign 不调 accept(Q2 裁决:claimOrder 仅自接单场景)
- # worker 侧可见该单(accepted 分组)
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/mine' -Token $t1Token -Body @{}
- $mineOk = $resp.code -eq 200
- Assert-True $mineOk 'worker /api/order/mine 可查' $resp ''
- # ============================================================
- # S11 四层评价(机构绩效)
- # ============================================================
- Begin-Step '机构绩效评价 /api/eval/org → 汇总 /api/eval/mine'
- $resp = Invoke-Api -Method 'POST' -Path '/api/eval/org' -Token $t1Token -Body @{
- userId = $t1UserId; score = 90; dimension = 'punctuality'; comment = 'M5 冒烟绩效评价'
- }
- Assert-True ($resp.code -eq 200 -and $resp.data) 'eval/org 提交' $resp ("evalId=" + $resp.data.evalId)
- $resp = Invoke-Api -Method 'POST' -Path '/api/eval/mine' -Token $t1Token -Body @{}
- $hasComposite = $false
- $hasOrg = $false
- if ($resp.code -eq 200 -and $resp.data) {
- if ($null -ne $resp.data.PSObject.Properties['composite']) { $hasComposite = $true }
- if ($resp.data.org -and [long]$resp.data.org.count -ge 1) { $hasOrg = $true }
- }
- $compVal = 0
- if ($hasComposite) { $compVal = [double]$resp.data.composite }
- Assert-True ($hasComposite -and $hasOrg -and $compVal -gt 0) 'eval/mine composite>0 且 org 评价计数≥1' $resp ("composite=$compVal")
- # ============================================================
- # S12 晋升 + 证据包
- # ============================================================
- Begin-Step '晋升规则/记录 /api/admin/promotion + 闸口 /api/promotion/unlock + 证据包 /api/evidence'
- # T2 规则(seed 预置:serve_count>=10 且 rating>=450)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/promotion/rule/list' -Token $adminToken -Body @{ page = 1; size = 20 }
- $hasT2Rule = $false
- foreach ($r in (Get-Arr $resp.data.list)) {
- if ($r.authLevel -eq 'T2' -and [int]$r.enabled -eq 1) { $hasT2Rule = $true; break }
- }
- Assert-True ($resp.code -eq 200 -and $hasT2Rule) 'T2 晋升规则存在且启用(seed 预置)' $resp ''
- # T1 晋升断言:rating=450 达标、serve_count 不足 → unmet 应只含 serve_count
- $resp = Invoke-Api -Method 'POST' -Path '/api/promotion/apply' -Token $t1Token -Body @{ authLevel = 'T2' }
- $unmetMetrics = @()
- if ($resp.code -eq 200 -and $resp.data -and $resp.data.unmet) { $unmetMetrics = Get-Arr $resp.data.unmet | ForEach-Object { [string]$_.metric } }
- $expectUnmet = ($resp.code -eq 200) -and ($resp.data.eligible -eq $false) -and ($unmetMetrics -contains 'serve_count') -and (-not ($unmetMetrics -contains 'rating'))
- Assert-True $expectUnmet 'apply T2 未达标:unmet 仅 serve_count(rating 450 已达标)' $resp ("eligible=" + $resp.data.eligible + " unmet=[" + ($unmetMetrics -join ',') + "]")
- # 晋升履历
- $resp = Invoke-Api -Method 'POST' -Path '/api/promotion/records' -Token $t1Token -Body @{ page = 1; size = 10 }
- Assert-True ($resp.code -eq 200 -and $null -ne $resp.data) 'promotion/records 可查' $resp ''
- # 闸口:T1 放行 / 未认证拒绝
- $resp = Invoke-Api -Method 'POST' -Path '/api/promotion/unlock' -Token $t1Token -Body @{ serviceType = 'cleaning' }
- Assert-True ($resp.code -eq 200 -and $resp.data.allowed -eq $true) 'unlock T1 allowed=true(闸口双值容错放行)' $resp ("authLevel=" + $resp.data.authLevel)
- $resp = Invoke-Api -Method 'POST' -Path '/api/promotion/unlock' -Token $noneToken -Body @{ serviceType = 'cleaning' }
- Assert-True ($resp.code -eq 200 -and $resp.data.allowed -eq $false) 'unlock m5none allowed=false' $resp ("reason=" + $resp.data.reason)
- # 证据包:发起 + 轮询
- $resp = Invoke-Api -Method 'POST' -Path '/api/evidence/export' -Token $t1Token -Body @{ type = 'training' }
- if ($resp.code -ne 200 -or -not $resp.data -or -not $resp.data.taskNo) { Assert-Fail '发起证据包导出失败' $resp '' }
- $taskNo = [string]$resp.data.taskNo
- Assert-Pass '发起培训证据包导出' $resp ("taskNo=$taskNo status=" + $resp.data.status)
- $taskStatus = ''
- $taskProgress = -1
- $fileUrl = ''
- $seenStates = @()
- for ($i = 0; $i -lt [Math]::Max($PollTimes, 1); $i++) {
- Start-Sleep -Seconds $PollIntervalSec
- $sr2 = Invoke-Api -Method 'POST' -Path '/api/evidence/status' -Token $t1Token -Body @{ taskNo = $taskNo }
- if ($sr2.code -eq 200 -and $sr2.data) {
- $taskStatus = [string]$sr2.data.status
- $taskProgress = [long]$sr2.data.progress
- $fileUrl = if ($sr2.data.fileUrl) { [string]$sr2.data.fileUrl } else { '' }
- if (-not ($seenStates -contains $taskStatus)) { $seenStates = $seenStates + $taskStatus }
- if ($taskStatus -in @('done', 'failed')) { break }
- }
- }
- $stateOk = ($seenStates.Count -gt 0) -and (($seenStates | Where-Object { $_ -in @('pending','processing','done') }).Count -gt 0)
- Assert-True $stateOk '证据包状态流转 ∈ {pending,processing,done}' $resp ("seen=[" + ($seenStates -join ',') + "] progress=$taskProgress")
- if ($taskStatus -eq 'done') {
- Assert-True (($taskProgress -eq 100) -and ($fileUrl -ne '')) '证据包 done:progress=100 且 fileUrl 非空' $resp ("fileUrl=$fileUrl")
- } else {
- Write-Host ("S{0} [INFO] 轮询结束时 status={1}(异步导出未完成,不阻断;可手动复跑观察 done)" -f $script:Step, $taskStatus) -ForegroundColor Yellow
- }
- # ============================================================
- # S13-S17 履约链 + 评价 + 六契约端点(M5 试点上线冒烟扩写)
- # 前提:S9 建单 + S10 指派成功($orderId 已由 worker=本人置 accepted)。
- # 契约来源(2026-11-26 实读源码,非文档假设):
- # /api/order/arrive body{lat,lng,photo} accepted→arrived;文案「请先接单再打卡」
- # /api/order/finish body{items,photos} arrived/doing→done,返回 6 位 clientConfirmCode
- # /api/order/confirm body{code} done→confirmed;错码「确认码不正确」;重复「当前工单无需确认」
- # /api/eval/submit body{orderId,score(1-5),comment} ★only-after-confirmed,uk(order_id) 幂等,必须本人
- # 六契约端点实为管理端前缀:/api/admin/org/member/disable、/api/admin/cohort/list、
- # /api/admin/attendance/list、/api/admin/credit/account/list、
- # /api/admin/credit/ledger/detail、/api/admin/credit/ledger/objected
- # 注意:本步非幂等(状态机单向),重跑同一库须重新 dispatch/create 一单。
- # ============================================================
- $skipFulfillment = ($null -eq $orderId -or [long]$orderId -le 0)
- if ($skipFulfillment) {
- Write-Host "`n[WARN] S9/S10 未产出可用工单(orderId 为空),跳过 S13-S17 履约链与契约端点。" -ForegroundColor Yellow
- }
- # ============================================================
- # S13 履约① 到岗打卡 /api/order/arrive
- # ============================================================
- if (-not $skipFulfillment) {
- Begin-Step '履约① 到岗打卡 /api/order/arrive(accepted→arrived)'
- # 反例:未到岗直接 finish → 状态门禁拒绝(门禁先于业务写入,本调用不改库)
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/finish' -Token $t1Token -Body @{
- orderId = $orderId; items = @(); photos = ''
- }
- $badFinish = if ($resp.message) { [string]$resp.message } else { '' }
- Assert-True (($resp.code -ne 200) -and ($badFinish -match '请先完成到岗打卡')) '反例:未到岗即 finish 被门禁拒绝' $resp ("msg=$badFinish")
- # 正例:定位 + 门牌照
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/arrive' -Token $t1Token -Body @{
- orderId = $orderId; lat = 30.521; lng = 114.393; photo = 'm5/smoke-arrive.jpg'
- }
- Assert-True ($resp.code -eq 200 -and $resp.data -eq $true) 'worker 本人打卡' $resp ''
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/detail' -Token $t1Token -Body @{ orderId = $orderId }
- Assert-True ($resp.code -eq 200 -and [string]$resp.data.status -eq 'arrived') '工单状态 → arrived' $resp ("status=" + $resp.data.status)
- Assert-True ($resp.data.arriveAt) 'arriveAt 服务端时间戳已落库' $resp ("arriveAt=" + $resp.data.arriveAt)
- Assert-True ($resp.data.arrivePhoto) 'arrivePhoto 门牌照已落库' $resp ("arrivePhoto=" + $resp.data.arrivePhoto)
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/mine' -Token $t1Token -Body @{}
- # 契约实测:mine 分组键为 today/pending/doing/done,accepted/arrived/doing 统一归入 'doing'(进行中),
- # 无独立 'arrived' 分组;断言按 doing 分组复核。
- $seenMine = $false
- foreach ($g in (Get-Arr $resp.data)) {
- if ($g.key -eq 'doing') {
- foreach ($it in (Get-Arr $g.list)) { if ([long]$it.id -eq $orderId) { $seenMine = $true; break } }
- }
- }
- Assert-True ($resp.code -eq 200 -and $seenMine) 'worker /api/order/mine 该单出现在 doing(进行中)分组' $resp ''
- # 归属越权反例:m5none 非该单 worker(arrive 与 detail 均按 worker_id 本人校验)
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/arrive' -Token $noneToken -Body @{
- orderId = $orderId; lat = 30.5; lng = 114.4
- }
- Assert-True ($resp.code -ne 200) '反例:非本人(m5none)打卡被拒' $resp ("msg=" + $resp.message)
- }
- # ============================================================
- # S14 履约② 完成服务 /api/order/finish(生成 6 位客户确认码)
- # ============================================================
- if (-not $skipFulfillment) {
- Begin-Step '履约② 完成服务 /api/order/finish(arrived→done + 6 位确认码)'
- $items = @(@{ name = '深度保洁'; done = 1 }, @{ name = '消毒'; done = 1 })
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/finish' -Token $t1Token -Body @{
- orderId = $orderId
- items = $items
- photos = 'm5/smoke-fin1.jpg,m5/smoke-fin2.jpg'
- }
- $confirmCode = ''
- if ($resp.data -and $resp.data.clientConfirmCode) { $confirmCode = [string]$resp.data.clientConfirmCode }
- # 批③ 5e097cf 修复点验证:finish 响应体须回显**更新后**的 status/finishAt
- # (此前 finish 用 toVO(updateById 前实体) 造 VO,响应体 status 仍为 arrived、finishAt 为空;
- # 已改为 selectById 重取实体构造 VO)。此处直接断言响应体,不再只靠 detail 复核。
- Assert-True ($resp.code -eq 200) 'worker 完成服务受理' $resp ("clientConfirmCode=$confirmCode")
- Assert-True ([string]$resp.data.status -eq 'done') 'finish 响应体 status == done(5e097cf 修复点验证)' $resp ("status=" + $resp.data.status)
- Assert-True ($resp.data.finishAt) 'finish 响应体 finishAt 非空(5e097cf 修复点验证)' $resp ("finishAt=" + $resp.data.finishAt)
- Assert-True ($confirmCode.Length -eq 6 -and $confirmCode -match '^[0-9]{6}$') '生成 6 位数字客户确认码' $resp ("clientConfirmCode=$confirmCode")
- $finPhotos = @($resp.data.finishPhotos)
- Assert-True ($finPhotos.Count -eq 2) 'finishPhotos 回显 2 张' $resp ("count=" + $finPhotos.Count)
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/detail' -Token $t1Token -Body @{ orderId = $orderId }
- $detailCode = if ($resp.data.clientConfirmCode) { [string]$resp.data.clientConfirmCode } else { '' }
- Assert-True ($resp.code -eq 200 -and $resp.data.status -eq 'done' -and $detailCode -eq $confirmCode) '工单详情复核:done + 同码' $resp ("code=$detailCode")
- Assert-True ($resp.data.finishAt) '详情 finishAt 服务端时间戳已落库' $resp ("finishAt=" + $resp.data.finishAt)
- }
- # ============================================================
- # S15 履约③ 客户确认 /api/order/confirm(正反例)
- # ============================================================
- if (-not $skipFulfillment) {
- Begin-Step '履约③ 客户确认 /api/order/confirm(done→confirmed 正反例)'
- # 反例:错码 → 拒绝(不落状态)
- $wrongCode = if ($confirmCode -match '^1') { '200000' } else { '100000' }
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/confirm' -Token $t1Token -Body @{
- orderId = $orderId; code = $wrongCode
- }
- $badCodeMsg = if ($resp.message) { [string]$resp.message } else { '' }
- Assert-True (($resp.code -ne 200) -and ($badCodeMsg -match '确认码不正确')) '反例:错误确认码被拒' $resp ("msg=$badCodeMsg")
- $chk = Invoke-Api -Method 'POST' -Path '/api/order/detail' -Token $t1Token -Body @{ orderId = $orderId }
- Assert-True ([string]$chk.data.status -eq 'done') '错码后状态未漂移(仍 done)' $chk ("status=" + $chk.data.status)
- # 正例:正确码 → confirmed
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/confirm' -Token $t1Token -Body @{
- orderId = $orderId; code = $confirmCode
- }
- Assert-True ($resp.code -eq 200 -and $resp.data -eq $true) '正确确认码核销 → confirmed' $resp ''
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/detail' -Token $t1Token -Body @{ orderId = $orderId }
- Assert-True ([string]$resp.data.status -eq 'confirmed') '工单详情 → confirmed(终态)' $resp ("status=" + $resp.data.status)
- # 反例:重复确认 → 当前工单无需确认
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/confirm' -Token $t1Token -Body @{
- orderId = $orderId; code = $confirmCode
- }
- $dupMsg = if ($resp.message) { [string]$resp.message } else { '' }
- Assert-True (($resp.code -ne 200) -and ($dupMsg -match '当前工单无需确认')) '反例:重复确认被拒(终态不可重入)' $resp ("msg=$dupMsg")
- # 终态入账:已确认单计入累计所得(金额为整数分,staff_income=16200 分)
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/earnings' -Token $t1Token -Body @{}
- Assert-True ($resp.code -eq 200 -and $resp.data.totalIncome -ge 16200) 'earnings.totalIncome 计入已确认单(16200 分)' $resp ("totalIncome=" + $resp.data.totalIncome)
- }
- # ============================================================
- # S16 评价 /api/eval/submit(only-after-confirmed,正反例)
- # ============================================================
- if (-not $skipFulfillment) {
- Begin-Step '评价 /api/eval/submit(EVA-TC-001 正例 / 002 反例)'
- # 正例:confirmed 后可评
- $resp = Invoke-Api -Method 'POST' -Path '/api/eval/submit' -Token $t1Token -Body @{
- orderId = $orderId; score = 5; comment = 'M5 冒烟履约评价'
- }
- $evalId = if ($resp.data -and $resp.data.evalId) { [long]$resp.data.evalId } else { -1 }
- Assert-True ($resp.code -eq 200 -and $resp.data -and $resp.data.score -eq 5 -and $resp.data.orderId -eq $orderId) 'EVA-TC-001:confirmed 后提交成功' $resp ("evalId=" + $resp.data.evalId + " evalType=" + $resp.data.evalType)
- # 幂等:二次提交返回同一条(uk(order_id) once-per-order)
- $resp2 = Invoke-Api -Method 'POST' -Path '/api/eval/submit' -Token $t1Token -Body @{
- orderId = $orderId; score = 4; comment = '二次提交'
- }
- $evalId2 = if ($resp2.data -and $resp2.data.evalId) { [long]$resp2.data.evalId } else { -2 }
- Assert-True ($resp2.code -eq 200 -and $evalId2 -eq $evalId) '评价幂等(同 orderId 返回同 evalId,不覆盖首评)' $resp2 ("evalId=$evalId/$evalId2")
- # 汇总可见(含本人履约评价计数)
- $resp = Invoke-Api -Method 'POST' -Path '/api/eval/mine' -Token $t1Token -Body @{}
- Assert-True ($resp.code -eq 200 -and $resp.data) 'eval/mine 可查(履约评价并入汇总)' $resp ''
- # --- 一次性反例工单:accepted(未 confirmed)→ 评价必须拒绝 ---
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/create' -Token $adminToken -Body @{
- orgId = $orgId; familyName = 'M5冒烟评价反例户'; contactPhone = '13900000099'
- address = '湖北省黄冈市浠水县试点路 2 号'; serviceType = 'cleaning'
- orderDate = '2026-12-05'; amount = 1000; platformFee = 100; remark = 'M5 冒烟一次性反例单'
- }
- if ($resp.code -ne 200 -or -not $resp.data) { Assert-Fail '反例单建单失败' $resp '' }
- $negOrderId = [long]$resp.data.orderId
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/assign' -Token $adminToken -Body @{
- orderId = $negOrderId; workerId = $t1UserId; serviceType = 'cleaning'; remark = '指派反例单'
- }
- Assert-True ($resp.code -eq 200 -and [string]$resp.data.status -eq 'accepted') '反例单指派 → accepted(未 confirmed)' $resp ("negOrderId=$negOrderId")
- # 履约门禁反例:accepted 未打卡即 finish → 拒绝(同时证明本单停在 accepted)
- $resp = Invoke-Api -Method 'POST' -Path '/api/order/finish' -Token $t1Token -Body @{
- orderId = $negOrderId; items = @(); photos = ''
- }
- Assert-True ($resp.code -ne 200) '反例单:未打卡即 finish 被拒(停在 accepted)' $resp ("msg=" + $resp.message)
- # EVA-TC-002:未 confirmed 工单不可评价
- $resp = Invoke-Api -Method 'POST' -Path '/api/eval/submit' -Token $t1Token -Body @{
- orderId = $negOrderId; score = 5; comment = '反例:未确认即评'
- }
- $negMsg = if ($resp.message) { [string]$resp.message } else { '' }
- Assert-True (($resp.code -ne 200) -and ($negMsg -match '工单未确认')) 'EVA-TC-002:未 confirmed 工单评价被拒' $resp ("msg=$negMsg")
- # 评分越界反例
- $resp = Invoke-Api -Method 'POST' -Path '/api/eval/submit' -Token $t1Token -Body @{
- orderId = $orderId; score = 6
- }
- $scoreMsg = if ($resp.message) { [string]$resp.message } else { '' }
- Assert-True (($resp.code -ne 200) -and ($scoreMsg -match '评分须为1-5星')) '反例:score=6 越界被拒' $resp ("msg=$scoreMsg")
- }
- # ============================================================
- # S17 六契约端点(管理端前缀实测):各 200 + 关键字段
- # ============================================================
- Begin-Step '六契约端点(member/disable、cohort/list、attendance/list、credit 三端点)'
- # ① /api/admin/org/member/disable:重复禁用 → 幂等成功(不动 S3 依赖的 m5t1 org_admin 身份)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/member/disable' -Token $adminToken -Body @{
- orgId = $orgId; userId = $noneUserId
- }
- Assert-True ($resp.code -eq 200 -and $resp.data -eq $true) 'member/disable 重复调用幂等成功' $resp ("memberUserId=$noneUserId")
- # ② /api/admin/cohort/list:每行含 enrolledCount(契约别名,与 signedCount 同源)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/list' -Token $adminToken -Body @{
- courseId = $courseId; page = 1; size = 10
- }
- $hasEnrolled = $false
- foreach ($row in (Get-Arr $resp.data.list)) {
- if ($null -ne $row.PSObject.Properties['enrolledCount']) { $hasEnrolled = $true; break }
- }
- Assert-True ($resp.code -eq 200 -and $hasEnrolled) 'cohort/list 行含 enrolledCount' $resp ("total=" + $resp.data.total)
- # ③ /api/admin/attendance/list:行含 userName(按签到 cohort 过滤,避免命中历史测试批次)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/attendance/list' -Token $adminToken -Body @{
- cohortId = $cohortId; page = 1; size = 10
- }
- $hasName = $false
- $showName = ''
- foreach ($row in (Get-Arr $resp.data.list)) {
- if ($null -ne $row.PSObject.Properties['userName']) { $hasName = $true; $showName = [string]$row.userName; break }
- }
- Assert-True ($resp.code -eq 200 -and $hasName) 'attendance/list 行含 userName' $resp ("userName=" + (Fix-MojibakeText $showName))
- # ④ /api/admin/credit/account/list:行含 userId/year/totalHours(学时分钟整数)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/credit/account/list' -Token $adminToken -Body @{
- year = 2026; page = 1; size = 10
- }
- $accOk = $false
- if ($resp.code -eq 200 -and $resp.data) {
- $accOk = ($null -ne $resp.data.PSObject.Properties['list'])
- foreach ($row in (Get-Arr $resp.data.list)) {
- if ($row.userId -and $row.year -and $null -ne $row.totalHours) { $accOk = $true; break }
- }
- }
- Assert-True $accOk 'credit/account/list 行含 userId/year/totalHours' $resp ("total=" + $resp.data.total)
- # ⑤ /api/admin/credit/ledger/detail:单学员单年度明细(hours 分钟整数红线)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/credit/ledger/detail' -Token $adminToken -Body @{
- userId = $stuUserId; year = 2026
- }
- $rows = Get-Arr $resp.data
- $detailOk = ($rows.Count -ge 1)
- foreach ($row in $rows) {
- if (-not (Test-MinuteInteger $row.hours)) { $detailOk = $false }
- }
- Assert-True ($resp.code -eq 200 -and $detailOk) 'credit/ledger/detail 返回明细且 hours 为分钟整数' $resp ("rows=" + $rows.Count)
- # ⑥ /api/admin/credit/ledger/objected:列表模式 + 处置模式(双模,同一路径)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/credit/ledger/objected' -Token $adminToken -Body @{ page = 1; size = 10 }
- $hasList = ($resp.code -eq 200 -and $resp.data -and ($null -ne $resp.data.PSObject.Properties['list']))
- Assert-True $hasList 'ledger/objected 列表模式返回 {total,page,size,list}' $resp ("total=" + $resp.data.total)
- # 处置分支:故意传不存在的台账 id → 业务拒绝且不改库(避免处置真实异议台账)
- $resp = Invoke-Api -Method 'POST' -Path '/api/admin/credit/ledger/objected' -Token $adminToken -Body @{
- id = 999999999; approved = $false; reason = 'M5 冒烟双模探针'
- }
- $dispMsg = if ($resp.message) { [string]$resp.message } else { '' }
- Assert-True (($resp.code -ne 200) -and ($dispMsg -match '学时记录不存在')) 'ledger/objected 处置分支:不存在台账被拒(双模路由命中)' $resp ("msg=$dispMsg")
- Write-Host ("S{0} [PASS] 六契约端点各 200 + 关键字段齐全" -f $script:Step) -ForegroundColor Green
- # ============================================================
- # 总结
- # ============================================================
- Write-Host "`n========================================" -ForegroundColor Cyan
- if ($skipFulfillment) {
- Write-Host ("冒烟完成:S1-S12 通过,S13-S17 跳过(无可用工单)。orgId=$orgId cohortId=$cohortId") -ForegroundColor Yellow
- } else {
- Write-Host ("冒烟完成:17 步全部通过(orgId=$orgId cohortId=$cohortId orderId=$orderId dispatchId=$dispatchId code=$confirmCode negOrderId=$negOrderId)") -ForegroundColor Green
- Write-Host "关键断言:学时分钟整数 ✓ 建单留痕 dispatchId ✓ 资质闸口放行/拒绝 ✓" -ForegroundColor Green
- Write-Host "履约链:arrived → done(6 位确认码) → confirmed → 可评价;错码/重复/未确认/越权均拒绝 ✓" -ForegroundColor Green
- }
- Write-Host "========================================" -ForegroundColor Cyan
- exit 0
|