diff --git a/frontend/bec_atlas/src/app/core/remote-data.service.spec.ts b/frontend/bec_atlas/src/app/core/remote-data.service.spec.ts index 07fb193..bc4424c 100644 --- a/frontend/bec_atlas/src/app/core/remote-data.service.spec.ts +++ b/frontend/bec_atlas/src/app/core/remote-data.service.spec.ts @@ -1,6 +1,7 @@ import { TestBed } from '@angular/core/testing'; import { + DeploymentDataService, RemoteDataService, ScanDataService, SessionDataService, @@ -13,6 +14,7 @@ import { import { AppConfigService } from '../app-config.service'; import { ScanDataResponse } from './model/scan-data'; import { ScanUserData } from './model/scan-user-data'; +import { Deployment } from './model/deployment'; describe('RemoteDataService', () => { let service: RemoteDataService; @@ -242,4 +244,64 @@ describe('RemoteDataService', () => { const result = await promise; expect(result).toBe(mockResponse); }); + + it('should get deployments', async () => { + const mockDeployments: Deployment[] = [ + { + _id: '1', + realm_id: 'realm1', + name: 'Deployment 1', + owner_groups: ['group1'], + access_groups: ['group2'], + config_templates: ['template1'], + }, + { + _id: '2', + realm_id: 'realm2', + name: 'Deployment 2', + owner_groups: ['group3'], + access_groups: ['group4'], + config_templates: ['template2'], + }, + ]; + + const deploymentService = TestBed.inject(DeploymentDataService); + const promise = deploymentService.getDeployments(); + + const req = httpTesting.expectOne((request) => + request.url.includes('deployments') + ); + expect(req.request.method).toBe('GET'); + expect(req.request.params.keys().length).toBe(0); + + req.flush(mockDeployments); + + const result = await promise; + expect(result).toEqual(mockDeployments); + }); + + it('should get deployment by id', async () => { + const mockDeployment: Deployment = { + _id: '1', + realm_id: 'realm1', + name: 'Deployment 1', + owner_groups: ['group1'], + access_groups: ['group2'], + config_templates: ['template1'], + }; + + const deploymentService = TestBed.inject(DeploymentDataService); + const promise = deploymentService.getDeployment('1'); + + const req = httpTesting.expectOne((request) => + request.url.includes('deployments/id') + ); + expect(req.request.method).toBe('GET'); + expect(req.request.params.get('deployment_id')).toBe('1'); + + req.flush(mockDeployment); + + const result = await promise; + expect(result).toEqual(mockDeployment); + }); }); diff --git a/frontend/bec_atlas/src/app/core/remote-data.service.ts b/frontend/bec_atlas/src/app/core/remote-data.service.ts index 0e2f952..f7ef987 100644 --- a/frontend/bec_atlas/src/app/core/remote-data.service.ts +++ b/frontend/bec_atlas/src/app/core/remote-data.service.ts @@ -125,19 +125,23 @@ export class RealmDataService extends RemoteDataService { providedIn: 'root', }) export class DeploymentDataService extends RemoteDataService { - getDeployments() { + getDeployments(): Promise> { let headers = new HttpHeaders(); headers = headers.set('Content-Type', 'application/json; charset=utf-8'); - return this.get>('deployments', {}, headers); + return firstValueFrom( + this.get>('deployments', {}, headers) + ); } - getDeployment(deploymentId: string) { + getDeployment(deploymentId: string): Promise { let headers = new HttpHeaders(); headers = headers.set('Content-Type', 'application/json; charset=utf-8'); - return this.get( - 'deployments/id', - { deployment_id: deploymentId }, - headers + return firstValueFrom( + this.get( + 'deployments/id', + { deployment_id: deploymentId }, + headers + ) ); } } diff --git a/frontend/bec_atlas/src/app/deployment.service.ts b/frontend/bec_atlas/src/app/deployment.service.ts index 47615c5..c6b2a05 100644 --- a/frontend/bec_atlas/src/app/deployment.service.ts +++ b/frontend/bec_atlas/src/app/deployment.service.ts @@ -13,13 +13,19 @@ export class DeploymentService { if (!deployment) { return; } - this.deploymentDataService - .getDeployment(deployment) - .subscribe((deployment) => { - if (deployment) { - this.selectedDeployment.next(deployment); - } - }); + this.update_deployment(deployment); + } + + async update_deployment(deploymentId: string | null): Promise { + if (!deploymentId) { + this.selectedDeployment.next(null); + return; + } + + let deployment_info = await this.deploymentDataService.getDeployment( + deploymentId + ); + this.selectedDeployment.next(deployment_info); } selectDeployment(deployment: Deployment | null): void {