Spaces:
Building
Building
Update flare-ui/src/app/components/test/test.component.ts
Browse files
flare-ui/src/app/components/test/test.component.ts
CHANGED
@@ -175,7 +175,7 @@ export class TestComponent implements OnInit {
|
|
175 |
const response = await this.apiService.getEnvironment().toPromise();
|
176 |
return {
|
177 |
name: 'GET /api/environment',
|
178 |
-
status: response?.work_mode ? 'PASS' : 'FAIL',
|
179 |
duration_ms: Date.now() - start
|
180 |
};
|
181 |
} catch (error) {
|
@@ -196,7 +196,7 @@ export class TestComponent implements OnInit {
|
|
196 |
name: 'GET /api/projects',
|
197 |
status: Array.isArray(response) ? 'PASS' : 'FAIL',
|
198 |
duration_ms: Date.now() - start,
|
199 |
-
details: `Retrieved ${response?.length || 0} projects`
|
200 |
};
|
201 |
} catch (error) {
|
202 |
return {
|
@@ -216,7 +216,7 @@ export class TestComponent implements OnInit {
|
|
216 |
name: 'GET /api/apis',
|
217 |
status: Array.isArray(response) ? 'PASS' : 'FAIL',
|
218 |
duration_ms: Date.now() - start,
|
219 |
-
details: `Retrieved ${response?.length || 0} APIs`
|
220 |
};
|
221 |
} catch (error) {
|
222 |
return {
|
@@ -228,24 +228,26 @@ export class TestComponent implements OnInit {
|
|
228 |
}
|
229 |
});
|
230 |
|
231 |
-
// Integration Tests
|
232 |
this.addTest('integration', 'Create and delete project', async () => {
|
233 |
const start = Date.now();
|
234 |
-
let
|
235 |
|
236 |
try {
|
237 |
// Create project
|
238 |
-
|
239 |
name: `test_project_${Date.now()}`,
|
240 |
caption: 'Test Project'
|
241 |
-
}).toPromise();
|
242 |
|
243 |
-
if (!
|
244 |
-
throw new Error('Project creation failed
|
245 |
}
|
246 |
|
247 |
-
|
248 |
-
|
|
|
|
|
249 |
|
250 |
return {
|
251 |
name: 'Create and delete project',
|
@@ -255,12 +257,10 @@ export class TestComponent implements OnInit {
|
|
255 |
};
|
256 |
} catch (error: any) {
|
257 |
// Try to clean up if project was created
|
258 |
-
if (
|
259 |
try {
|
260 |
-
await this.apiService.deleteProject(
|
261 |
-
} catch
|
262 |
-
console.error('Cleanup failed:', cleanupError);
|
263 |
-
}
|
264 |
}
|
265 |
|
266 |
return {
|
@@ -272,6 +272,28 @@ export class TestComponent implements OnInit {
|
|
272 |
}
|
273 |
});
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
// Validation Tests
|
276 |
this.addTest('validation', 'Regex validation - valid pattern', async () => {
|
277 |
const start = Date.now();
|
@@ -312,72 +334,6 @@ export class TestComponent implements OnInit {
|
|
312 |
}
|
313 |
});
|
314 |
|
315 |
-
// Integration Tests
|
316 |
-
this.addTest('integration', 'Create and delete project', async () => {
|
317 |
-
const start = Date.now();
|
318 |
-
let projectId: number | null = null;
|
319 |
-
|
320 |
-
try {
|
321 |
-
// Create project
|
322 |
-
const createResponse = await this.apiService.createProject({
|
323 |
-
name: `test_project_${Date.now()}`,
|
324 |
-
caption: 'Test Project'
|
325 |
-
}).toPromise() as any;
|
326 |
-
|
327 |
-
if (!createResponse.id) {
|
328 |
-
throw new Error('Project creation failed');
|
329 |
-
}
|
330 |
-
|
331 |
-
projectId = createResponse.id;
|
332 |
-
|
333 |
-
// Delete project
|
334 |
-
await this.apiService.deleteProject(projectId).toPromise();
|
335 |
-
|
336 |
-
return {
|
337 |
-
name: 'Create and delete project',
|
338 |
-
status: 'PASS',
|
339 |
-
duration_ms: Date.now() - start,
|
340 |
-
details: 'Project lifecycle test passed'
|
341 |
-
};
|
342 |
-
} catch (error: any) {
|
343 |
-
// Try to clean up if project was created
|
344 |
-
if (projectId) {
|
345 |
-
try {
|
346 |
-
await this.apiService.deleteProject(projectId).toPromise();
|
347 |
-
} catch {}
|
348 |
-
}
|
349 |
-
|
350 |
-
return {
|
351 |
-
name: 'Create and delete project',
|
352 |
-
status: 'FAIL',
|
353 |
-
error: error.message || 'Test failed',
|
354 |
-
duration_ms: Date.now() - start
|
355 |
-
};
|
356 |
-
}
|
357 |
-
});
|
358 |
-
|
359 |
-
this.addTest('integration', 'API used in intent cannot be deleted', async () => {
|
360 |
-
const start = Date.now();
|
361 |
-
try {
|
362 |
-
// Try to delete an API that's used in intents
|
363 |
-
await this.apiService.deleteAPI('book_flight_api').toPromise();
|
364 |
-
|
365 |
-
return {
|
366 |
-
name: 'API used in intent cannot be deleted',
|
367 |
-
status: 'FAIL',
|
368 |
-
error: 'Expected error but API was deleted',
|
369 |
-
duration_ms: Date.now() - start
|
370 |
-
};
|
371 |
-
} catch (error: any) {
|
372 |
-
return {
|
373 |
-
name: 'API used in intent cannot be deleted',
|
374 |
-
status: error.status === 400 ? 'PASS' : 'FAIL',
|
375 |
-
duration_ms: Date.now() - start,
|
376 |
-
details: 'Correctly prevented deletion of API in use'
|
377 |
-
};
|
378 |
-
}
|
379 |
-
});
|
380 |
-
|
381 |
// Update test counts
|
382 |
this.categories.forEach(cat => {
|
383 |
cat.displayName = `${cat.displayName} (${cat.tests.length} tests)`;
|
@@ -397,7 +353,8 @@ export class TestComponent implements OnInit {
|
|
397 |
}
|
398 |
|
399 |
toggleAll() {
|
400 |
-
|
|
|
401 |
}
|
402 |
|
403 |
async runAllTests() {
|
|
|
175 |
const response = await this.apiService.getEnvironment().toPromise();
|
176 |
return {
|
177 |
name: 'GET /api/environment',
|
178 |
+
status: response?.work_mode ? 'PASS' : 'FAIL',
|
179 |
duration_ms: Date.now() - start
|
180 |
};
|
181 |
} catch (error) {
|
|
|
196 |
name: 'GET /api/projects',
|
197 |
status: Array.isArray(response) ? 'PASS' : 'FAIL',
|
198 |
duration_ms: Date.now() - start,
|
199 |
+
details: `Retrieved ${response?.length || 0} projects`
|
200 |
};
|
201 |
} catch (error) {
|
202 |
return {
|
|
|
216 |
name: 'GET /api/apis',
|
217 |
status: Array.isArray(response) ? 'PASS' : 'FAIL',
|
218 |
duration_ms: Date.now() - start,
|
219 |
+
details: `Retrieved ${response?.length || 0} APIs`
|
220 |
};
|
221 |
} catch (error) {
|
222 |
return {
|
|
|
228 |
}
|
229 |
});
|
230 |
|
231 |
+
// Integration Tests
|
232 |
this.addTest('integration', 'Create and delete project', async () => {
|
233 |
const start = Date.now();
|
234 |
+
let projectId: number | undefined;
|
235 |
|
236 |
try {
|
237 |
// Create project
|
238 |
+
const createResponse = await this.apiService.createProject({
|
239 |
name: `test_project_${Date.now()}`,
|
240 |
caption: 'Test Project'
|
241 |
+
}).toPromise() as any;
|
242 |
|
243 |
+
if (!createResponse?.id) {
|
244 |
+
throw new Error('Project creation failed');
|
245 |
}
|
246 |
|
247 |
+
projectId = createResponse.id;
|
248 |
+
|
249 |
+
// Delete project
|
250 |
+
await this.apiService.deleteProject(projectId).toPromise();
|
251 |
|
252 |
return {
|
253 |
name: 'Create and delete project',
|
|
|
257 |
};
|
258 |
} catch (error: any) {
|
259 |
// Try to clean up if project was created
|
260 |
+
if (projectId !== undefined) {
|
261 |
try {
|
262 |
+
await this.apiService.deleteProject(projectId).toPromise();
|
263 |
+
} catch {}
|
|
|
|
|
264 |
}
|
265 |
|
266 |
return {
|
|
|
272 |
}
|
273 |
});
|
274 |
|
275 |
+
this.addTest('integration', 'API used in intent cannot be deleted', async () => {
|
276 |
+
const start = Date.now();
|
277 |
+
try {
|
278 |
+
// Try to delete an API that's used in intents
|
279 |
+
await this.apiService.deleteAPI('book_flight_api').toPromise();
|
280 |
+
|
281 |
+
return {
|
282 |
+
name: 'API used in intent cannot be deleted',
|
283 |
+
status: 'FAIL',
|
284 |
+
error: 'Expected error but API was deleted',
|
285 |
+
duration_ms: Date.now() - start
|
286 |
+
};
|
287 |
+
} catch (error: any) {
|
288 |
+
return {
|
289 |
+
name: 'API used in intent cannot be deleted',
|
290 |
+
status: error.status === 400 ? 'PASS' : 'FAIL',
|
291 |
+
duration_ms: Date.now() - start,
|
292 |
+
details: 'Correctly prevented deletion of API in use'
|
293 |
+
};
|
294 |
+
}
|
295 |
+
});
|
296 |
+
|
297 |
// Validation Tests
|
298 |
this.addTest('validation', 'Regex validation - valid pattern', async () => {
|
299 |
const start = Date.now();
|
|
|
334 |
}
|
335 |
});
|
336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
// Update test counts
|
338 |
this.categories.forEach(cat => {
|
339 |
cat.displayName = `${cat.displayName} (${cat.tests.length} tests)`;
|
|
|
353 |
}
|
354 |
|
355 |
toggleAll() {
|
356 |
+
const newState = !this.allSelected;
|
357 |
+
this.categories.forEach(c => c.selected = newState);
|
358 |
}
|
359 |
|
360 |
async runAllTests() {
|