-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp_api_test.ps1
More file actions
40 lines (36 loc) · 1.66 KB
/
Copy pathtmp_api_test.ps1
File metadata and controls
40 lines (36 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
$base='http://localhost:4000'
$ts = [int](Get-Date -UFormat %s)
$agentUsername = "agent$ts"
$agent = @{ username = $agentUsername; name = 'Test Agent'; password = 'pass123'; role = 'agent'; skills = 'traffic, sanitation' }
Write-Host "Registering user $agentUsername"
try {
$reg = Invoke-RestMethod -Uri ($base + '/api/auth/register') -Method Post -ContentType 'application/json' -Body (ConvertTo-Json $agent)
Write-Host "REGISTER_OK: " (ConvertTo-Json $reg -Compress)
} catch {
Write-Host "REGISTER_FAILED: " $_.Exception.Message
if ($_.Exception.Response) { $_.Exception.Response | ConvertTo-Json -Compress | Write-Host }
exit 1
}
# Login
$creds = @{ username = $agentUsername; password = 'pass123' }
try {
$login = Invoke-RestMethod -Uri ($base + '/api/auth/login') -Method Post -ContentType 'application/json' -Body (ConvertTo-Json $creds)
Write-Host "LOGIN_OK: " (ConvertTo-Json $login -Compress)
} catch {
Write-Host "LOGIN_FAILED: " $_.Exception.Message
if ($_.Exception.Response) { $_.Exception.Response | ConvertTo-Json -Compress | Write-Host }
exit 1
}
$token = $login.token
# Create case
$case = @{ title = 'Test case from agent'; description = 'Created during smoke test'; location = 'Testville' }
try {
$hdr = @{ Authorization = "Bearer $token" }
$created = Invoke-RestMethod -Uri ($base + '/api/cases') -Method Post -ContentType 'application/json' -Body (ConvertTo-Json $case) -Headers $hdr
Write-Host "CREATE_OK: " (ConvertTo-Json $created -Compress)
} catch {
Write-Host "CREATE_FAILED: " $_.Exception.Message
if ($_.Exception.Response) { $_.Exception.Response | ConvertTo-Json -Compress | Write-Host }
exit 1
}
Write-Host 'SMOKE TESTS COMPLETED'