Repository navigation
Expand file tree
/
Copy pathtest-api.ps1
More file actions
227 lines (188 loc) · 7.79 KB
/
Copy pathtest-api.ps1
File metadata and controls
227 lines (188 loc) · 7.79 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# ============================================================
# Scouter-DataGateway - Testes PowerShell
# Roda o backend antes (./gradlew bootRun) - porta 8080
# ============================================================
$base = "http://localhost:8080"
# ------------------------------------------------------------
# 1. REGISTER (cria usuário) — role padrão vem SCOUT
# ------------------------------------------------------------
$registerBody = @{
username = "kaique"
email = "kaique@teste.com"
password = "senha123"
} | ConvertTo-Json
Invoke-RestMethod -Uri "$base/auth/register" `
-Method Post `
-ContentType "application/json" `
-Body $registerBody
# ------------------------------------------------------------
# 2. LOGIN (só confirma email/senha, não retorna token)
# ------------------------------------------------------------
$loginBody = @{
email = "kaique@teste.com"
password = "senha123"
} | ConvertTo-Json
Invoke-RestMethod -Uri "$base/auth/login" `
-Method Post `
-ContentType "application/json" `
-Body $loginBody
# ------------------------------------------------------------
# 3. Credenciais pro header X-Credentials (email/senha)
# ------------------------------------------------------------
$cred = "kaique@teste.com/senha123"
$headers = @{ "X-Credentials" = $cred }
# ------------------------------------------------------------
# 4. USER — /me
# ------------------------------------------------------------
Invoke-RestMethod -Uri "$base/users/me" -Method Get -Headers $headers
# Atualizar username
Invoke-RestMethod -Uri "$base/users/me/username?username=kaique_novo" `
-Method Patch -Headers $headers
# Atualizar email
Invoke-RestMethod -Uri "$base/users/me/email?email=kaique.novo@teste.com" `
-Method Patch -Headers $headers
# Volta pro email antigo (senão os próximos testes quebram o header)
$headers = @{ "X-Credentials" = "kaique.novo@teste.com/senha123" }
# ------------------------------------------------------------
# 5. USER — Admin (vai dar 401 se seu usuário não for ADMIN no banco)
# ------------------------------------------------------------
Invoke-RestMethod -Uri "$base/users" -Method Get -Headers $headers
# ------------------------------------------------------------
# 6. AUTO SCOUT — criar
# ------------------------------------------------------------
$autoBody = @{
matchTeamId = "2026caav_qm1_7563"
eventKey = "2026caav"
matchKey = "2026caav_qm1"
teamKey = "frc7563"
year = 2026
l1 = 2
l2 = 3
l3 = 1
l4 = 0
coralMisseds = 1
coralPrecision = 0.85
algaeRemoved = 2
algaeNet = 1
algaeProcessor = 1
regionScored = ""
score = 45
startline = $true
notes = "auto rapido, sem colisao"
} | ConvertTo-Json
Invoke-RestMethod -Uri "$base/scout/auto" `
-Method Post -Headers $headers `
-ContentType "application/json" -Body $autoBody
# Buscar por matchTeamId
Invoke-RestMethod -Uri "$base/scout/auto/2026caav_qm1_7563" -Method Get -Headers $headers
# Buscar por team
Invoke-RestMethod -Uri "$base/scout/auto/team/frc7563" -Method Get -Headers $headers
# Buscar por evento
Invoke-RestMethod -Uri "$base/scout/auto/event/2026caav" -Method Get -Headers $headers
# Buscar por match
Invoke-RestMethod -Uri "$base/scout/auto/match/2026caav_qm1" -Method Get -Headers $headers
# Buscar por team + match
Invoke-RestMethod -Uri "$base/scout/auto/team/frc7563/match/2026caav_qm1" -Method Get -Headers $headers
# Deletar (precisa ser admin, senão 401)
Invoke-RestMethod -Uri "$base/scout/auto/2026caav_qm1_7563" -Method Delete -Headers $headers
# ------------------------------------------------------------
# 7. TELEOP SCOUT — criar
# ------------------------------------------------------------
$teleopBody = @{
matchTeamId = "2026caav_qm1_7563"
eventKey = "2026caav"
matchKey = "2026caav_qm1"
teamKey = "frc7563"
year = 2026
l1 = 5
l2 = 4
l3 = 2
l4 = 1
coralMisseds = 3
coralPrecision = 0.78
algaeRemoved = 4
algaeNet = 2
algaeProcessor = 2
climb = "deep"
collectedCoralFloor = $true
collectedCoralStation = $true
collectedAlgaeReef = $false
defended = $false
defendedEffectiveness = $null
wasDefended = $true
defenseEffectiveness = 3
disabled = $false
tipped = $false
immobilized = $false
issues = $false
issuesNotes = ""
driverRating = 4
score = 68
notes = "boa consistencia no teleop"
} | ConvertTo-Json
Invoke-RestMethod -Uri "$base/scout/teleop" `
-Method Post -Headers $headers `
-ContentType "application/json" -Body $teleopBody
# Buscar por matchTeamId
Invoke-RestMethod -Uri "$base/scout/teleop/2026caav_qm1_7563" -Method Get -Headers $headers
# Buscar por team
Invoke-RestMethod -Uri "$base/scout/teleop/team/frc7563" -Method Get -Headers $headers
# Deletar (admin)
Invoke-RestMethod -Uri "$base/scout/teleop/2026caav_qm1_7563" -Method Delete -Headers $headers
# ------------------------------------------------------------
# 8. PIT SCOUT — criar
# ------------------------------------------------------------
$pitBody = @{
teamKey = "frc7563"
eventKey = "2026caav"
description = "Robo com garra de coral, chassi swerve"
} | ConvertTo-Json
$pitResult = Invoke-RestMethod -Uri "$base/scout/pit" `
-Method Post -Headers $headers `
-ContentType "application/json" -Body $pitBody
$pitResult # mostra o id do pit scout criado
$pitScoutId = $pitResult.id
# Buscar por team
Invoke-RestMethod -Uri "$base/scout/pit/team/frc7563" -Method Get -Headers $headers
# Buscar por evento
Invoke-RestMethod -Uri "$base/scout/pit/event/2026caav" -Method Get -Headers $headers
# Buscar por team + evento
Invoke-RestMethod -Uri "$base/scout/pit/team/frc7563/event/2026caav" -Method Get -Headers $headers
# ------------------------------------------------------------
# 9. PIT SCOUT PHOTOS — criar (usa o id retornado acima)
# ------------------------------------------------------------
$photoBody = @{
imgUrl = "https://exemplo.com/foto1.jpg"
description = "Foto do robo de frente"
} | ConvertTo-Json
Invoke-RestMethod -Uri "$base/scout/pit/$pitScoutId/photos" `
-Method Post -Headers $headers `
-ContentType "application/json" -Body $photoBody
# Listar fotos
Invoke-RestMethod -Uri "$base/scout/pit/$pitScoutId/photos" -Method Get -Headers $headers
# Deletar fotos (admin)
Invoke-RestMethod -Uri "$base/scout/pit/$pitScoutId/photos" -Method Delete -Headers $headers
# Deletar pit scout (admin)
Invoke-RestMethod -Uri "$base/scout/pit/team/frc7563/event/2026caav" -Method Delete -Headers $headers
# ------------------------------------------------------------
# 10. Testes de erro esperado
# ------------------------------------------------------------
# Sem header -> 400 (header obrigatório ausente)
try {
Invoke-RestMethod -Uri "$base/users/me" -Method Get
} catch {
Write-Host "Esperado 400:" $_.Exception.Response.StatusCode
}
# Credenciais erradas -> 401
try {
$badHeaders = @{ "X-Credentials" = "kaique@teste.com/senhaerrada" }
Invoke-RestMethod -Uri "$base/users/me" -Method Get -Headers $badHeaders
} catch {
Write-Host "Esperado 401:" $_.Exception.Response.StatusCode
}
# Id inexistente -> 404
try {
Invoke-RestMethod -Uri "$base/scout/auto/nao-existe" -Method Get -Headers $headers
} catch {
Write-Host "Esperado 404:" $_.Exception.Response.StatusCode
}