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=13d86988f38e7482fa920a36678964200ddbca1d;hb=8cf8165763380e8779c9420099faf2197fa161d4;hp=6814d8af631fa66c57cfebed649c72f058c7fc3c;hpb=f7c54883fabc2ffd90a32197d06b04369357219b;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 6814d8a..13d8698 100644 --- a/webapp-frontend/src/app/services/ei/ei.service.spec.ts +++ b/webapp-frontend/src/app/services/ei/ei.service.spec.ts @@ -17,15 +17,131 @@ * limitations under the License. * ========================LICENSE_END=================================== */ +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing' import { TestBed } from '@angular/core/testing'; +import { EIJob, ProducerStatus, OperationalState, ProducerRegistrationInfo } from '@interfaces/ei.types'; import { EIService } from './ei.service'; -describe('PolicyService', () => { - beforeEach(() => TestBed.configureTestingModule({})); +describe('EIService', () => { + let basePath = '/ei-producer/v1'; + let service: EIService; + let httpTestingController: HttpTestingController; + + beforeEach(() => TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule + ], + providers: [ + EIService + ] + })); it('should be created', () => { - const service: EIService = TestBed.get(EIService); + service = TestBed.inject(EIService); expect(service).toBeTruthy(); }); + + describe('#getProducerIds', () => { + let expectedEIProducerIds: string[]; + + beforeEach(() => { + service = TestBed.inject(EIService); + httpTestingController = TestBed.inject(HttpTestingController); + expectedEIProducerIds = [ 'producer1', 'producer2' ] as string[]; + }); + + it('should return all producer IDs', () => { + service.getProducerIds().subscribe( + producers => expect(producers).toEqual(expectedEIProducerIds, 'should return expected EIProducer IDs'), + fail + ); + + const req = httpTestingController.expectOne(basePath + '/' + service.eiProducersPath); + expect(req.request.method).toEqual('GET'); + + req.flush(expectedEIProducerIds); //Return expected producer IDs + + httpTestingController.verify(); + }); + }); + + describe('#getJobsForProducer', () => { + let expectedEIJobs: EIJob[]; + + beforeEach(() => { + 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'} + ] as EIJob[]; + }); + + it('should return all jobs', () => { + service.getJobsForProducer('producer1').subscribe( + jobs => expect(jobs).toEqual(expectedEIJobs, 'should return expected Jobs'), + fail + ); + + const req = httpTestingController.expectOne(basePath + '/' + service.eiProducersPath + '/producer1/' + service.eiJobsPath); + expect(req.request.method).toEqual('GET'); + + req.flush(expectedEIJobs); //Return expectedEIJobs + + 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 = { + operational_state: 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(); + }); + }); });