ciyidogan commited on
Commit
cc2c168
·
verified ·
1 Parent(s): 59b5a86

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

Browse files
flare-ui/src/app/components/test/test.component.ts CHANGED
@@ -416,7 +416,7 @@ export class TestComponent implements OnInit {
416
  }
417
  }).toPromise();
418
 
419
- // 2. Create test project with version that uses the API
420
  const testProjectName = `test_project_${Date.now()}`;
421
  const createProjectResponse = await this.apiService.createProject({
422
  name: testProjectName,
@@ -435,13 +435,14 @@ export class TestComponent implements OnInit {
435
 
436
  testProjectId = createProjectResponse.id;
437
 
438
- // 3. Update the version to add an intent that uses our API
439
  const version = createProjectResponse.versions[0];
440
  if (!version) {
441
  throw new Error('No version found in created project');
442
  }
443
 
444
- await this.apiService.updateVersion(testProjectId!, version.id, {
 
445
  caption: version.caption,
446
  general_prompt: 'Test prompt',
447
  llm: version.llm,
@@ -452,18 +453,18 @@ export class TestComponent implements OnInit {
452
  detection_prompt: 'Test detection',
453
  examples: ['test example'],
454
  parameters: [],
455
- action: testApiName, // This is where we use the API
456
  fallback_timeout_prompt: 'Timeout',
457
  fallback_error_prompt: 'Error'
458
  }],
459
  last_update_date: version.last_update_date
460
  }).toPromise();
461
 
462
- // 4. Try to delete the API - this should fail
463
  try {
464
  await this.apiService.deleteAPI(testApiName).toPromise();
465
 
466
- // If we reach here, deletion succeeded when it shouldn't have
467
  return {
468
  name: 'API used in intent cannot be deleted',
469
  status: 'FAIL',
@@ -471,9 +472,18 @@ export class TestComponent implements OnInit {
471
  duration_ms: Date.now() - start
472
  };
473
  } catch (deleteError: any) {
474
- // Check if we got the expected error
 
475
  const isExpectedError = deleteError.status === 400 &&
476
- deleteError.error?.detail?.includes('API is used');
 
 
 
 
 
 
 
 
477
 
478
  return {
479
  name: 'API used in intent cannot be deleted',
@@ -481,29 +491,29 @@ export class TestComponent implements OnInit {
481
  duration_ms: Date.now() - start,
482
  details: isExpectedError
483
  ? 'Correctly prevented deletion of API in use'
484
- : `Unexpected error: Status ${deleteError.status}, Detail: ${deleteError.error?.detail || deleteError.message}`
485
  };
486
  }
487
- } catch (error: any) {
488
  return {
489
  name: 'API used in intent cannot be deleted',
490
  status: 'FAIL',
491
- error: `Test setup failed: ${error.message}`,
492
  duration_ms: Date.now() - start
493
  };
494
  } finally {
495
- // Cleanup
496
  try {
497
  if (testProjectId !== undefined) {
498
  await this.apiService.deleteProject(testProjectId).toPromise();
499
  }
 
 
 
500
  if (testApiName) {
501
- // Now we can delete the API since the project is gone
502
  await this.apiService.deleteAPI(testApiName).toPromise();
503
  }
504
- } catch (cleanupError) {
505
- // Ignore cleanup errors
506
- }
507
  }
508
  });
509
 
 
416
  }
417
  }).toPromise();
418
 
419
+ // 2. Create test project
420
  const testProjectName = `test_project_${Date.now()}`;
421
  const createProjectResponse = await this.apiService.createProject({
422
  name: testProjectName,
 
435
 
436
  testProjectId = createProjectResponse.id;
437
 
438
+ // 3. Get the first version
439
  const version = createProjectResponse.versions[0];
440
  if (!version) {
441
  throw new Error('No version found in created project');
442
  }
443
 
444
+ // 4. Update the version to add an intent that uses our API
445
+ await this.apiService.updateVersion(testProjectId, version.id, {
446
  caption: version.caption,
447
  general_prompt: 'Test prompt',
448
  llm: version.llm,
 
453
  detection_prompt: 'Test detection',
454
  examples: ['test example'],
455
  parameters: [],
456
+ action: testApiName,
457
  fallback_timeout_prompt: 'Timeout',
458
  fallback_error_prompt: 'Error'
459
  }],
460
  last_update_date: version.last_update_date
461
  }).toPromise();
462
 
463
+ // 5. Try to delete the API - this should fail with 400
464
  try {
465
  await this.apiService.deleteAPI(testApiName).toPromise();
466
 
467
+ // If deletion succeeded, test failed
468
  return {
469
  name: 'API used in intent cannot be deleted',
470
  status: 'FAIL',
 
472
  duration_ms: Date.now() - start
473
  };
474
  } catch (deleteError: any) {
475
+ // Check if we got the expected 400 error
476
+ const errorMessage = deleteError.error?.detail || deleteError.message || '';
477
  const isExpectedError = deleteError.status === 400 &&
478
+ errorMessage.includes('API is used');
479
+
480
+ if (!isExpectedError) {
481
+ console.error('Delete API Error Details:', {
482
+ status: deleteError.status,
483
+ error: deleteError.error,
484
+ message: errorMessage
485
+ });
486
+ }
487
 
488
  return {
489
  name: 'API used in intent cannot be deleted',
 
491
  duration_ms: Date.now() - start,
492
  details: isExpectedError
493
  ? 'Correctly prevented deletion of API in use'
494
+ : `Unexpected error: Status ${deleteError.status}, Message: ${errorMessage}`
495
  };
496
  }
497
+ } catch (setupError: any) {
498
  return {
499
  name: 'API used in intent cannot be deleted',
500
  status: 'FAIL',
501
+ error: `Test setup failed: ${setupError.message || setupError}`,
502
  duration_ms: Date.now() - start
503
  };
504
  } finally {
505
+ // Cleanup: first delete project, then API
506
  try {
507
  if (testProjectId !== undefined) {
508
  await this.apiService.deleteProject(testProjectId).toPromise();
509
  }
510
+ } catch {}
511
+
512
+ try {
513
  if (testApiName) {
 
514
  await this.apiService.deleteAPI(testApiName).toPromise();
515
  }
516
+ } catch {}
 
 
517
  }
518
  });
519