9e2584bd35288f2e43a9f87b09b10550e8ebac9d
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / services / ei / ei.service.spec.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 Nordix Foundation
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
21 import { TestBed } from '@angular/core/testing';
22
23 import { EIJob, EIProducer } from '../../interfaces/ei.types';
24 import { EIService } from './ei.service';
25
26 describe('EIService', () => {
27   let basePath = 'api/enrichment';
28   let service: EIService;
29   let httpTestingController: HttpTestingController;
30
31   beforeEach(() => TestBed.configureTestingModule({
32     imports: [
33       HttpClientTestingModule
34     ],
35     providers: [
36       EIService
37     ]
38   }));
39
40   it('should be created', () => {
41     service = TestBed.get(EIService);
42     expect(service).toBeTruthy();
43   });
44
45   describe('#getEIProducers', () => {
46     let expectedEIProducers: EIProducer[];
47
48     beforeEach(() => {
49       service = TestBed.get(EIService);
50       httpTestingController = TestBed.get(HttpTestingController);
51       expectedEIProducers = [
52         { ei_producer_id: '1', ei_producer_types: ['EI Type 1'], status: 'ENABLED' },
53         { ei_producer_id: '1', ei_producer_types: ['EI Type 1'], status: 'ENABLED' }
54       ] as EIProducer[];
55     });
56
57     it('should return all producers', () => {
58       service.getEIProducers().subscribe(
59         producers => expect(producers).toEqual(expectedEIProducers, 'should return expected EIProducers'),
60         fail
61       );
62
63       const req = httpTestingController.expectOne(basePath + '/' + service.eiProducerPath);
64       expect(req.request.method).toEqual('GET');
65
66       req.flush(expectedEIProducers); //Return expectedEITypes
67
68       httpTestingController.verify();
69     });
70   });
71
72   describe('#EIJobs', () => {
73     let expectedEIJobs: EIJob[];
74
75     beforeEach(() => {
76       service = TestBed.get(EIService);
77       httpTestingController = TestBed.get(HttpTestingController);
78       expectedEIJobs = [
79         { ei_job_identity: '1', ei_job_data: 'data', ei_type_identity: 'Type ID 1',  target_uri: 'hhtp://url', owner: 'owner'},
80         { ei_job_identity: '2', ei_job_data: 'EI Job 2', ei_type_identity: 'Type ID 2',  target_uri: 'hhtp://url', owner: 'owner'}
81       ] as EIJob[];
82     });
83
84     it('should return all jobs', () => {
85       service.getEIJobs().subscribe(
86         jobs => expect(jobs).toEqual(expectedEIJobs, 'should return expected Jobs'),
87         fail
88       );
89
90       const req = httpTestingController.expectOne(basePath + '/' + service.eiJobPath);
91       expect(req.request.method).toEqual('GET');
92
93       req.flush(expectedEIJobs); //Return expectedEIJobs
94
95       httpTestingController.verify();
96      });
97   });
98 });