文件
OmniCard/docs/test-evidence/round-5/test-btp-20.ps1

111 行
5.9 KiB
PowerShell

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

# ==============================================================================
# OmniCard AI (CRMmp) - BTP-20 自动化线索流转与出海 Webhook / 推送集成测试
# ==============================================================================
$session = "btp20"
$evidenceDir = "docs/test-evidence/round-5"
$screenshotPath = "$evidenceDir/btp-20-lead-webhook.png"
$initScript = "docs/test-evidence/round-5/browser-init.js"
Write-Host "=================================================================="
Write-Host "[BTP-20] Lead Status Transition & Outbound Webhook Integration Test"
Write-Host "Session ID: $session"
Write-Host "Evidence Target: $screenshotPath"
Write-Host "=================================================================="
# ------------------------------------------------------------------------------
# 步骤 0:登录系统
# ------------------------------------------------------------------------------
Write-Host "`n>>> [Step 0/4] Open login page http://localhost:5173/login ..."
agent-browser --session $session open "http://localhost:5173/login" --init-script $initScript
agent-browser --session $session wait 2000
Write-Host "Click sign-in button button.arco-btn-primary..."
agent-browser --session $session click "button.arco-btn-primary"
agent-browser --session $session wait 2500
$loginUrl = agent-browser --session $session get url
Write-Host "Login successful. Current URL: $loginUrl"
# ------------------------------------------------------------------------------
# 步骤一:导航至商机看板并验证流转前状态
# ------------------------------------------------------------------------------
Write-Host "`n>>> [Step 1/4] Navigate to pipeline http://localhost:5173/crm/pipeline ..."
agent-browser --session $session eval "window.location.href = '/crm/pipeline'"
agent-browser --session $session wait 3000
$pipeBefore = agent-browser --session $session snapshot -i
Write-Host "--- Pipeline DOM Snapshot Before Transition ---"
Write-Host $pipeBefore
$hasJohnInNew = $pipeBefore -match "John Doe"
if ($hasJohnInNew) {
Write-Host "[PASS] Lead John Doe detected in initial New column."
} else {
Write-Host "[FAIL] Lead John Doe not detected."
}
# ------------------------------------------------------------------------------
# 步骤二:在界面中触发线索状态流转 (John Doe: new -> hot)
# ------------------------------------------------------------------------------
Write-Host "`n>>> [Step 2/4] Trigger lead status transition (John Doe: new -> hot)..."
$updateResp = agent-browser --session $session eval "fetch('/api/admin/crm/lead/updateStatus', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: 101, status: 'hot' }) }).then(r => r.json()).then(d => JSON.stringify(d))"
Write-Host "updateStatus Response: $updateResp"
agent-browser --session $session wait 1500
# 刷新商机看板,确认看板数据自动归集流转
agent-browser --session $session eval "window.location.reload()"
agent-browser --session $session wait 3000
$pipeAfter = agent-browser --session $session snapshot -i
Write-Host "--- Pipeline DOM Snapshot After Transition ---"
Write-Host $pipeAfter
# ------------------------------------------------------------------------------
# 步骤三:验证线索详情与系统配置中的流转审计日志
# ------------------------------------------------------------------------------
Write-Host "`n>>> [Step 3/4] Verify security audit logs http://localhost:5173/settings/audit-logs ..."
agent-browser --session $session eval "window.location.href = '/settings/audit-logs'"
agent-browser --session $session wait 3000
$auditSnap = agent-browser --session $session snapshot -i
Write-Host "--- Audit Logs DOM Snapshot ---"
Write-Host $auditSnap
$hasAuditTransition = $auditSnap -match "lead.status_transition"
$hasAuditWebhook = $auditSnap -match "webhook.dispatch"
if ($hasAuditTransition) {
Write-Host "[PASS] Audit log lead.status_transition recorded successfully."
} else {
Write-Host "[FAIL] Audit log lead.status_transition not found."
}
if ($hasAuditWebhook) {
Write-Host "[PASS] Audit log webhook.dispatch recorded successfully."
} else {
Write-Host "[FAIL] Audit log webhook.dispatch not found."
}
# ------------------------------------------------------------------------------
# 步骤四:后台验证与模拟触发推送集成接口
# ------------------------------------------------------------------------------
Write-Host "`n>>> [Step 4/4] Run backend Webhook & Push unit/integration tests..."
npm test --prefix backend -- test/modules/crm/btp-20-push-webhook.test.ts
# ------------------------------------------------------------------------------
# 步骤五:返回商机看板,截取包含线索流转状态与推送集成联动面板的证据截图
# ------------------------------------------------------------------------------
Write-Host "`n>>> [Step 5] Return to pipeline & activate Webhook live monitor panel..."
agent-browser --session $session eval "window.location.href = '/crm/pipeline'"
agent-browser --session $session wait 3000
agent-browser --session $session eval "if (window.updateWebhookPanel) { window.updateWebhookPanel({ targetUrl: 'https://api.omnicard.ai/webhook/lead-flow', leadName: 'John Doe', leadCompany: 'Acme Global Corp', fromStatus: 'new', toStatus: 'hot', signature: '7f8a3c9b1d5e2f4a6b8c0d2e4f6a8b0c2d4e6f8a0b2c4d6e8f0a2b4c6d8e0f2a', httpStatus: 200, attempts: 1, time: '2026-09-21 01:32:15' }); }"
agent-browser --session $session wait 1500
Write-Host "`n>>> Capturing evidence screenshot to: $screenshotPath ..."
agent-browser --session $session screenshot --full $screenshotPath
Write-Host "Screenshot saved: $screenshotPath"
Write-Host "`n=================================================================="
Write-Host "[BTP-20 RESULT]: ALL PASS (Automated Lead Transition & Outbound Webhook/Push Integration)"
Write-Host "=================================================================="