ciyidogan commited on
Commit
35f09a0
·
verified ·
1 Parent(s): de0719d

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

Browse files
flare-ui/src/app/components/test/test.component.ts CHANGED
@@ -132,7 +132,7 @@ export class TestComponent implements OnInit {
132
 
133
  return {
134
  name: 'Login with valid credentials',
135
- status: response.token ? 'PASS' : 'FAIL',
136
  duration_ms: 120
137
  };
138
  } catch (error) {
@@ -168,6 +168,7 @@ export class TestComponent implements OnInit {
168
  }
169
  });
170
 
 
171
  // API Endpoint Tests
172
  this.addTest('api', 'GET /api/environment', async () => {
173
  const start = Date.now();
@@ -175,7 +176,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 +197,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} projects`
200
  };
201
  } catch (error) {
202
  return {
@@ -216,7 +217,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} APIs`
220
  };
221
  } catch (error) {
222
  return {
@@ -228,6 +229,50 @@ export class TestComponent implements OnInit {
228
  }
229
  });
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  // Validation Tests
232
  this.addTest('validation', 'Regex validation - valid pattern', async () => {
233
  const start = Date.now();
 
132
 
133
  return {
134
  name: 'Login with valid credentials',
135
+ status: response?.token ? 'PASS' : 'FAIL',
136
  duration_ms: 120
137
  };
138
  } catch (error) {
 
168
  }
169
  });
170
 
171
+ // API Endpoint Tests
172
  // API Endpoint Tests
173
  this.addTest('api', 'GET /api/environment', async () => {
174
  const start = Date.now();
 
176
  const response = await this.apiService.getEnvironment().toPromise();
177
  return {
178
  name: 'GET /api/environment',
179
+ status: response?.work_mode ? 'PASS' : 'FAIL', // Add optional chaining
180
  duration_ms: Date.now() - start
181
  };
182
  } catch (error) {
 
197
  name: 'GET /api/projects',
198
  status: Array.isArray(response) ? 'PASS' : 'FAIL',
199
  duration_ms: Date.now() - start,
200
+ details: `Retrieved ${response?.length || 0} projects` // Add optional chaining
201
  };
202
  } catch (error) {
203
  return {
 
217
  name: 'GET /api/apis',
218
  status: Array.isArray(response) ? 'PASS' : 'FAIL',
219
  duration_ms: Date.now() - start,
220
+ details: `Retrieved ${response?.length || 0} APIs` // Add optional chaining
221
  };
222
  } catch (error) {
223
  return {
 
229
  }
230
  });
231
 
232
+ // Integration Tests
233
+ this.addTest('integration', 'Create and delete project', async () => {
234
+ const start = Date.now();
235
+ let projectId: number | null = null;
236
+
237
+ try {
238
+ // Create project
239
+ const createResponse = await this.apiService.createProject({
240
+ name: `test_project_${Date.now()}`,
241
+ caption: 'Test Project'
242
+ }).toPromise() as any;
243
+
244
+ if (!createResponse?.id) {
245
+ throw new Error('Project creation failed');
246
+ }
247
+
248
+ projectId = createResponse.id;
249
+
250
+ // Delete project
251
+ await this.apiService.deleteProject(projectId).toPromise();
252
+
253
+ return {
254
+ name: 'Create and delete project',
255
+ status: 'PASS',
256
+ duration_ms: Date.now() - start,
257
+ details: 'Project lifecycle test passed'
258
+ };
259
+ } catch (error: any) {
260
+ // Try to clean up if project was created
261
+ if (projectId !== null) { // Check for null explicitly
262
+ try {
263
+ await this.apiService.deleteProject(projectId).toPromise();
264
+ } catch {}
265
+ }
266
+
267
+ return {
268
+ name: 'Create and delete project',
269
+ status: 'FAIL',
270
+ error: error.message || 'Test failed',
271
+ duration_ms: Date.now() - start
272
+ };
273
+ }
274
+ });
275
+
276
  // Validation Tests
277
  this.addTest('validation', 'Regex validation - valid pattern', async () => {
278
  const start = Date.now();