mirror of
https://github.com/bec-project/bec_atlas.git
synced 2025-07-14 07:01:48 +02:00
refactor: moved deployment data service to promise
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
DeploymentDataService,
|
||||||
RemoteDataService,
|
RemoteDataService,
|
||||||
ScanDataService,
|
ScanDataService,
|
||||||
SessionDataService,
|
SessionDataService,
|
||||||
@ -13,6 +14,7 @@ import {
|
|||||||
import { AppConfigService } from '../app-config.service';
|
import { AppConfigService } from '../app-config.service';
|
||||||
import { ScanDataResponse } from './model/scan-data';
|
import { ScanDataResponse } from './model/scan-data';
|
||||||
import { ScanUserData } from './model/scan-user-data';
|
import { ScanUserData } from './model/scan-user-data';
|
||||||
|
import { Deployment } from './model/deployment';
|
||||||
|
|
||||||
describe('RemoteDataService', () => {
|
describe('RemoteDataService', () => {
|
||||||
let service: RemoteDataService;
|
let service: RemoteDataService;
|
||||||
@ -242,4 +244,64 @@ describe('RemoteDataService', () => {
|
|||||||
const result = await promise;
|
const result = await promise;
|
||||||
expect(result).toBe(mockResponse);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -125,19 +125,23 @@ export class RealmDataService extends RemoteDataService {
|
|||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class DeploymentDataService extends RemoteDataService {
|
export class DeploymentDataService extends RemoteDataService {
|
||||||
getDeployments() {
|
getDeployments(): Promise<Array<Deployment>> {
|
||||||
let headers = new HttpHeaders();
|
let headers = new HttpHeaders();
|
||||||
headers = headers.set('Content-Type', 'application/json; charset=utf-8');
|
headers = headers.set('Content-Type', 'application/json; charset=utf-8');
|
||||||
return this.get<Array<Deployment>>('deployments', {}, headers);
|
return firstValueFrom(
|
||||||
|
this.get<Array<Deployment>>('deployments', {}, headers)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDeployment(deploymentId: string) {
|
getDeployment(deploymentId: string): Promise<Deployment> {
|
||||||
let headers = new HttpHeaders();
|
let headers = new HttpHeaders();
|
||||||
headers = headers.set('Content-Type', 'application/json; charset=utf-8');
|
headers = headers.set('Content-Type', 'application/json; charset=utf-8');
|
||||||
return this.get<Deployment>(
|
return firstValueFrom(
|
||||||
'deployments/id',
|
this.get<Deployment>(
|
||||||
{ deployment_id: deploymentId },
|
'deployments/id',
|
||||||
headers
|
{ deployment_id: deploymentId },
|
||||||
|
headers
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,19 @@ export class DeploymentService {
|
|||||||
if (!deployment) {
|
if (!deployment) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.deploymentDataService
|
this.update_deployment(deployment);
|
||||||
.getDeployment(deployment)
|
}
|
||||||
.subscribe((deployment) => {
|
|
||||||
if (deployment) {
|
async update_deployment(deploymentId: string | null): Promise<void> {
|
||||||
this.selectedDeployment.next(deployment);
|
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 {
|
selectDeployment(deployment: Deployment | null): void {
|
||||||
|
Reference in New Issue
Block a user