ciyidogan commited on
Commit
605a49e
·
verified ·
1 Parent(s): b823b0d

Update flare-ui/src/app/components/test/test.component.ts

Browse files
flare-ui/src/app/components/test/test.component.ts CHANGED
@@ -299,7 +299,7 @@ export class TestComponent implements OnInit {
299
  this.addTest('integration', 'Create and delete project', async () => {
300
  const start = Date.now();
301
  let projectId: number | undefined = undefined;
302
-
303
  try {
304
  if (!await this.ensureAuth()) {
305
  return {
@@ -309,7 +309,7 @@ export class TestComponent implements OnInit {
309
  duration_ms: Date.now() - start
310
  };
311
  }
312
-
313
  // Create test project
314
  const testProjectName = `test_project_${Date.now()}`;
315
  const createResponse = await this.apiService.createProject({
@@ -318,13 +318,13 @@ export class TestComponent implements OnInit {
318
  icon: 'folder',
319
  description: 'This is a test project'
320
  }).toPromise() as any;
321
-
322
  if (!createResponse?.id) {
323
  throw new Error('Project creation failed - no ID returned');
324
  }
325
-
326
  projectId = createResponse.id;
327
-
328
  // Verify project was created
329
  const projects = await this.apiService.getProjects().toPromise() as any[];
330
  const createdProject = projects.find(p => p.id === projectId);
@@ -332,10 +332,10 @@ export class TestComponent implements OnInit {
332
  if (!createdProject) {
333
  throw new Error('Created project not found in project list');
334
  }
335
-
336
- // Delete project
337
- await this.apiService.deleteProject(projectId).toPromise();
338
-
339
  // Verify project was soft deleted
340
  const projectsAfterDelete = await this.apiService.getProjects().toPromise() as any[];
341
  const deletedProject = projectsAfterDelete.find(p => p.id === projectId);
@@ -343,7 +343,7 @@ export class TestComponent implements OnInit {
343
  if (deletedProject) {
344
  throw new Error('Project still visible after deletion');
345
  }
346
-
347
  return {
348
  name: 'Create and delete project',
349
  status: 'PASS',
@@ -357,7 +357,7 @@ export class TestComponent implements OnInit {
357
  await this.apiService.deleteProject(projectId).toPromise();
358
  } catch {}
359
  }
360
-
361
  return {
362
  name: 'Create and delete project',
363
  status: 'FAIL',
@@ -366,12 +366,12 @@ export class TestComponent implements OnInit {
366
  };
367
  }
368
  });
369
-
370
  this.addTest('integration', 'API used in intent cannot be deleted', async () => {
371
  const start = Date.now();
372
  let testApiName: string | undefined;
373
  let testProjectId: number | undefined;
374
-
375
  try {
376
  if (!await this.ensureAuth()) {
377
  return {
@@ -381,7 +381,7 @@ export class TestComponent implements OnInit {
381
  duration_ms: Date.now() - start
382
  };
383
  }
384
-
385
  // 1. Create test API
386
  testApiName = `test_api_${Date.now()}`;
387
  await this.apiService.createAPI({
@@ -392,19 +392,27 @@ export class TestComponent implements OnInit {
392
  headers: { 'Content-Type': 'application/json' },
393
  body_template: {}
394
  }).toPromise();
395
-
396
  // 2. Create test project with version that uses the API
397
  const testProjectName = `test_project_${Date.now()}`;
398
  const createProjectResponse = await this.apiService.createProject({
399
  name: testProjectName,
400
  caption: 'Test Project'
401
  }).toPromise() as any;
402
-
 
 
 
 
403
  testProjectId = createProjectResponse.id;
404
-
405
  // 3. Update the version to add an intent that uses our API
406
  const version = createProjectResponse.versions[0];
407
- await this.apiService.updateVersion(testProjectId, version.id, {
 
 
 
 
408
  caption: version.caption,
409
  general_prompt: 'Test prompt',
410
  llm: version.llm,
@@ -421,7 +429,7 @@ export class TestComponent implements OnInit {
421
  }],
422
  last_update_date: version.last_update_date
423
  }).toPromise();
424
-
425
  // 4. Try to delete the API - this should fail
426
  try {
427
  await this.apiService.deleteAPI(testApiName).toPromise();
@@ -457,7 +465,7 @@ export class TestComponent implements OnInit {
457
  } finally {
458
  // Cleanup
459
  try {
460
- if (testProjectId) {
461
  await this.apiService.deleteProject(testProjectId).toPromise();
462
  }
463
  if (testApiName) {
@@ -467,7 +475,7 @@ export class TestComponent implements OnInit {
467
  } catch {}
468
  }
469
  });
470
-
471
  // Validation Tests
472
  this.addTest('validation', 'Regex validation - valid pattern', async () => {
473
  const start = Date.now();
 
299
  this.addTest('integration', 'Create and delete project', async () => {
300
  const start = Date.now();
301
  let projectId: number | undefined = undefined;
302
+
303
  try {
304
  if (!await this.ensureAuth()) {
305
  return {
 
309
  duration_ms: Date.now() - start
310
  };
311
  }
312
+
313
  // Create test project
314
  const testProjectName = `test_project_${Date.now()}`;
315
  const createResponse = await this.apiService.createProject({
 
318
  icon: 'folder',
319
  description: 'This is a test project'
320
  }).toPromise() as any;
321
+
322
  if (!createResponse?.id) {
323
  throw new Error('Project creation failed - no ID returned');
324
  }
325
+
326
  projectId = createResponse.id;
327
+
328
  // Verify project was created
329
  const projects = await this.apiService.getProjects().toPromise() as any[];
330
  const createdProject = projects.find(p => p.id === projectId);
 
332
  if (!createdProject) {
333
  throw new Error('Created project not found in project list');
334
  }
335
+
336
+ // Delete project (projectId is guaranteed to be a number here)
337
+ await this.apiService.deleteProject(projectId!).toPromise();
338
+
339
  // Verify project was soft deleted
340
  const projectsAfterDelete = await this.apiService.getProjects().toPromise() as any[];
341
  const deletedProject = projectsAfterDelete.find(p => p.id === projectId);
 
343
  if (deletedProject) {
344
  throw new Error('Project still visible after deletion');
345
  }
346
+
347
  return {
348
  name: 'Create and delete project',
349
  status: 'PASS',
 
357
  await this.apiService.deleteProject(projectId).toPromise();
358
  } catch {}
359
  }
360
+
361
  return {
362
  name: 'Create and delete project',
363
  status: 'FAIL',
 
366
  };
367
  }
368
  });
369
+
370
  this.addTest('integration', 'API used in intent cannot be deleted', async () => {
371
  const start = Date.now();
372
  let testApiName: string | undefined;
373
  let testProjectId: number | undefined;
374
+
375
  try {
376
  if (!await this.ensureAuth()) {
377
  return {
 
381
  duration_ms: Date.now() - start
382
  };
383
  }
384
+
385
  // 1. Create test API
386
  testApiName = `test_api_${Date.now()}`;
387
  await this.apiService.createAPI({
 
392
  headers: { 'Content-Type': 'application/json' },
393
  body_template: {}
394
  }).toPromise();
395
+
396
  // 2. Create test project with version that uses the API
397
  const testProjectName = `test_project_${Date.now()}`;
398
  const createProjectResponse = await this.apiService.createProject({
399
  name: testProjectName,
400
  caption: 'Test Project'
401
  }).toPromise() as any;
402
+
403
+ if (!createProjectResponse?.id) {
404
+ throw new Error('Project creation failed');
405
+ }
406
+
407
  testProjectId = createProjectResponse.id;
408
+
409
  // 3. Update the version to add an intent that uses our API
410
  const version = createProjectResponse.versions[0];
411
+ if (!version) {
412
+ throw new Error('No version found in created project');
413
+ }
414
+
415
+ await this.apiService.updateVersion(testProjectId!, version.id, {
416
  caption: version.caption,
417
  general_prompt: 'Test prompt',
418
  llm: version.llm,
 
429
  }],
430
  last_update_date: version.last_update_date
431
  }).toPromise();
432
+
433
  // 4. Try to delete the API - this should fail
434
  try {
435
  await this.apiService.deleteAPI(testApiName).toPromise();
 
465
  } finally {
466
  // Cleanup
467
  try {
468
+ if (testProjectId !== undefined) {
469
  await this.apiService.deleteProject(testProjectId).toPromise();
470
  }
471
  if (testApiName) {
 
475
  } catch {}
476
  }
477
  });
478
+
479
  // Validation Tests
480
  this.addTest('validation', 'Regex validation - valid pattern', async () => {
481
  const start = Date.now();