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
@@ -135,17 +135,30 @@ export class TestComponent implements OnInit {
|
|
135 |
// Helper method to ensure authentication
|
136 |
private async ensureAuth(): Promise<boolean> {
|
137 |
try {
|
138 |
-
// Check if we already have a token
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
}
|
142 |
-
|
143 |
-
//
|
144 |
const response = await this.http.post('/api/login', {
|
145 |
username: 'admin',
|
146 |
password: 'admin'
|
147 |
}).toPromise() as any;
|
148 |
-
|
149 |
if (response?.token) {
|
150 |
this.authService.setToken(response.token);
|
151 |
this.authService.setUsername(response.username);
|
@@ -156,7 +169,6 @@ export class TestComponent implements OnInit {
|
|
156 |
return false;
|
157 |
}
|
158 |
}
|
159 |
-
|
160 |
initializeTests() {
|
161 |
// Authentication Tests
|
162 |
this.addTest('auth', 'Login with valid credentials', async () => {
|
@@ -301,6 +313,7 @@ export class TestComponent implements OnInit {
|
|
301 |
let projectId: number | undefined = undefined;
|
302 |
|
303 |
try {
|
|
|
304 |
if (!await this.ensureAuth()) {
|
305 |
return {
|
306 |
name: 'Create and delete project',
|
@@ -316,7 +329,11 @@ export class TestComponent implements OnInit {
|
|
316 |
name: testProjectName,
|
317 |
caption: 'Test Project for Integration Test',
|
318 |
icon: 'folder',
|
319 |
-
description: 'This is a test project'
|
|
|
|
|
|
|
|
|
320 |
}).toPromise() as any;
|
321 |
|
322 |
if (!createResponse?.id) {
|
@@ -333,7 +350,7 @@ export class TestComponent implements OnInit {
|
|
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
|
@@ -373,6 +390,7 @@ export class TestComponent implements OnInit {
|
|
373 |
let testProjectId: number | undefined;
|
374 |
|
375 |
try {
|
|
|
376 |
if (!await this.ensureAuth()) {
|
377 |
return {
|
378 |
name: 'API used in intent cannot be deleted',
|
@@ -390,14 +408,25 @@ export class TestComponent implements OnInit {
|
|
390 |
method: 'POST',
|
391 |
timeout_seconds: 10,
|
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) {
|
@@ -472,7 +501,9 @@ export class TestComponent implements OnInit {
|
|
472 |
// Now we can delete the API since the project is gone
|
473 |
await this.apiService.deleteAPI(testApiName).toPromise();
|
474 |
}
|
475 |
-
} catch {
|
|
|
|
|
476 |
}
|
477 |
});
|
478 |
|
|
|
135 |
// Helper method to ensure authentication
|
136 |
private async ensureAuth(): Promise<boolean> {
|
137 |
try {
|
138 |
+
// Check if we already have a valid token
|
139 |
+
const token = this.authService.getToken();
|
140 |
+
if (token) {
|
141 |
+
// Try to make a simple authenticated request to verify token is still valid
|
142 |
+
try {
|
143 |
+
await this.apiService.getEnvironment().toPromise();
|
144 |
+
return true;
|
145 |
+
} catch (error: any) {
|
146 |
+
if (error.status === 401) {
|
147 |
+
// Token expired, need to re-login
|
148 |
+
this.authService.logout();
|
149 |
+
} else {
|
150 |
+
// Other error, assume auth is ok
|
151 |
+
return true;
|
152 |
+
}
|
153 |
+
}
|
154 |
}
|
155 |
+
|
156 |
+
// Login with test credentials
|
157 |
const response = await this.http.post('/api/login', {
|
158 |
username: 'admin',
|
159 |
password: 'admin'
|
160 |
}).toPromise() as any;
|
161 |
+
|
162 |
if (response?.token) {
|
163 |
this.authService.setToken(response.token);
|
164 |
this.authService.setUsername(response.username);
|
|
|
169 |
return false;
|
170 |
}
|
171 |
}
|
|
|
172 |
initializeTests() {
|
173 |
// Authentication Tests
|
174 |
this.addTest('auth', 'Login with valid credentials', async () => {
|
|
|
313 |
let projectId: number | undefined = undefined;
|
314 |
|
315 |
try {
|
316 |
+
// Ensure we're authenticated
|
317 |
if (!await this.ensureAuth()) {
|
318 |
return {
|
319 |
name: 'Create and delete project',
|
|
|
329 |
name: testProjectName,
|
330 |
caption: 'Test Project for Integration Test',
|
331 |
icon: 'folder',
|
332 |
+
description: 'This is a test project',
|
333 |
+
default_language: 'Turkish',
|
334 |
+
supported_languages: ['tr'],
|
335 |
+
timezone: 'Europe/Istanbul',
|
336 |
+
region: 'tr-TR'
|
337 |
}).toPromise() as any;
|
338 |
|
339 |
if (!createResponse?.id) {
|
|
|
350 |
throw new Error('Created project not found in project list');
|
351 |
}
|
352 |
|
353 |
+
// Delete project
|
354 |
await this.apiService.deleteProject(projectId!).toPromise();
|
355 |
|
356 |
// Verify project was soft deleted
|
|
|
390 |
let testProjectId: number | undefined;
|
391 |
|
392 |
try {
|
393 |
+
// Ensure we're authenticated
|
394 |
if (!await this.ensureAuth()) {
|
395 |
return {
|
396 |
name: 'API used in intent cannot be deleted',
|
|
|
408 |
method: 'POST',
|
409 |
timeout_seconds: 10,
|
410 |
headers: { 'Content-Type': 'application/json' },
|
411 |
+
body_template: {},
|
412 |
+
retry: {
|
413 |
+
retry_count: 3,
|
414 |
+
backoff_seconds: 2,
|
415 |
+
strategy: 'static'
|
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,
|
423 |
+
caption: 'Test Project',
|
424 |
+
icon: 'folder',
|
425 |
+
description: 'Test project for API deletion test',
|
426 |
+
default_language: 'Turkish',
|
427 |
+
supported_languages: ['tr'],
|
428 |
+
timezone: 'Europe/Istanbul',
|
429 |
+
region: 'tr-TR'
|
430 |
}).toPromise() as any;
|
431 |
|
432 |
if (!createProjectResponse?.id) {
|
|
|
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 |
|