You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.8 KiB

3 weeks ago
$ErrorActionPreference = 'Stop'
$base = 'http://localhost:8081'
$token = Get-Content 'e:\code\crm-backend-matt\tmp\dt-token.txt' -Raw
$headers = @{ Authorization = "Bearer $token" }
function PostJson($url, $json) {
return Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes($json)) -ContentType 'application/json; charset=utf-8'
}
# keyword=北京 (0x5317 0x4EAC)
$kw = [string]::new([char[]](0x5317, 0x4EAC))
$p = PostJson "$base/api/lead/page" ('{"viewType":"PUBLIC_POOL","pageNum":1,"pageSize":10,"keyword":"' + $kw + '"}')
Write-Host "keyword=Beijing total=$($p.data.total)"
# negative control: keyword that matches nothing (0x9F9F 0x5154 = 龟兔)
$kw2 = [string]::new([char[]](0x9F9F, 0x5154))
$p2 = PostJson "$base/api/lead/page" ('{"viewType":"PUBLIC_POOL","pageNum":1,"pageSize":10,"keyword":"' + $kw2 + '"}')
Write-Host "keyword=negative total=$($p2.data.total)"
# phone keyword test: find a lead with phone via full list
$pa = PostJson "$base/api/lead/page" '{"viewType":"PUBLIC_POOL","pageNum":1,"pageSize":20}'
foreach ($it in $pa.data.content) {
Write-Host ("id={0} status={1} phone={2} pool={3}" -f $it.id, $it.status, $it.phone, $it.poolNameSnapshot)
}
# pick a claimed lead for history check
$claimed = $pa.data.content | Where-Object { $_.status -eq 3 -or $_.status -eq 4 } | Select-Object -First 1
if ($claimed) {
$h = Invoke-RestMethod -Uri "$base/api/lead/history?leadId=$($claimed.id)" -Method Get -Headers $headers
Write-Host "history leadId=$($claimed.id) count=$($h.data.Count)"
foreach ($hh in $h.data) { Write-Host (" type={0} opUserName={1} opUserDeptName={2}" -f $hh.historyType, $hh.opUserName, $hh.opUserDeptName) }
} else {
Write-Host "no claimed lead found"
}
Write-Host "DONE"