X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fservices%2Fei%2Fei.service.spec.ts;h=6ced48c8534a986ce439f31cbd3ac27ef1f71731;hb=refs%2Fchanges%2F68%2F5668%2F5;hp=ca77d0c5a68a2ecbd0a0735aa36702bed508e0f0;hpb=87ffca501cf3dca8dfb050b56f5c3bf9b742b651;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/services/ei/ei.service.spec.ts b/webapp-frontend/src/app/services/ei/ei.service.spec.ts index ca77d0c..6ced48c 100644 --- a/webapp-frontend/src/app/services/ei/ei.service.spec.ts +++ b/webapp-frontend/src/app/services/ei/ei.service.spec.ts @@ -20,7 +20,7 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing' import { TestBed } from '@angular/core/testing'; -import { EIJob } from '../../interfaces/ei.types'; +import { EIJob, ProducerStatus, OperationalState, ProducerRegistrationInfo } from '../../interfaces/ei.types'; import { EIService } from './ei.service'; describe('EIService', () => { @@ -38,17 +38,17 @@ describe('EIService', () => { })); it('should be created', () => { - service = TestBed.get(EIService); + service = TestBed.inject(EIService); expect(service).toBeTruthy(); }); - describe('#getEIProducers', () => { - let expectedEIProducerIds: String[]; + describe('#getProducerIds', () => { + let expectedEIProducerIds: string[]; beforeEach(() => { - service = TestBed.get(EIService); - httpTestingController = TestBed.get(HttpTestingController); - expectedEIProducerIds = [ 'producer1', 'producer2' ] as String[]; + service = TestBed.inject(EIService); + httpTestingController = TestBed.inject(HttpTestingController); + expectedEIProducerIds = [ 'producer1', 'producer2' ] as string[]; }); it('should return all producer IDs', () => { @@ -66,12 +66,12 @@ describe('EIService', () => { }); }); - describe('#EIJobs', () => { + describe('#getJobsForProducer', () => { let expectedEIJobs: EIJob[]; beforeEach(() => { - service = TestBed.get(EIService); - httpTestingController = TestBed.get(HttpTestingController); + service = TestBed.inject(EIService); + httpTestingController = TestBed.inject(HttpTestingController); expectedEIJobs = [ { ei_job_identity: '1', ei_job_data: 'data', ei_type_identity: 'Type ID 1', target_uri: 'hhtp://url', owner: 'owner'}, { ei_job_identity: '2', ei_job_data: 'EI Job 2', ei_type_identity: 'Type ID 2', target_uri: 'hhtp://url', owner: 'owner'} @@ -92,4 +92,56 @@ describe('EIService', () => { httpTestingController.verify(); }); }); + + describe('#getProducer', () => { + let expectedProducer: ProducerRegistrationInfo; + + beforeEach(() => { + service = TestBed.inject(EIService); + httpTestingController = TestBed.inject(HttpTestingController); + expectedProducer = { + supported_ei_types: [ 'type1', 'type2' ] + } as ProducerRegistrationInfo; + }); + + it('should return producer', () => { + service.getProducer('producer1').subscribe( + producer => expect(producer).toEqual(expectedProducer, 'should return expected producer'), + fail + ); + + const req = httpTestingController.expectOne(basePath + '/' + service.eiProducersPath + '/producer1'); + expect(req.request.method).toEqual('GET'); + + req.flush(expectedProducer); //Return expected producer + + httpTestingController.verify(); + }); + }); + + describe('#getProducerStatus', () => { + let expectedProducerStatus: ProducerStatus; + + beforeEach(() => { + service = TestBed.inject(EIService); + httpTestingController = TestBed.inject(HttpTestingController); + expectedProducerStatus = { + opState: OperationalState.ENABLED + } as ProducerStatus; + }); + + it('should return producer status', () => { + service.getProducerStatus('producer1').subscribe( + producerStatus => expect(producerStatus).toEqual(expectedProducerStatus, 'should return expected producer'), + fail + ); + + const req = httpTestingController.expectOne(basePath + '/' + service.eiProducersPath + '/producer1/' + service.eiProducerStatusPath); + expect(req.request.method).toEqual('GET'); + + req.flush(expectedProducerStatus); //Return expected status + + httpTestingController.verify(); + }); + }); });