Move Enrichment Producer Logic from backend
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / ei-coordinator / ei-job.datasource.spec.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2021 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 { TestBed } from '@angular/core/testing';
21 import { BehaviorSubject, of } from 'rxjs';
22
23 import { EIJobDataSource } from './ei-job.datasource';
24 import { EIService } from '../services/ei/ei.service';
25 import { NotificationService } from '../services/ui/notification.service';
26 import { ToastrModule } from 'ngx-toastr';
27 import { EIJob } from '../interfaces/ei.types';
28
29 describe('EIJobDataSource', () => {
30     let dataSource: EIJobDataSource;
31     let eiServiceSpy: any;
32
33     let job = { ei_job_identity: '1', ei_job_data: 'data', ei_type_identity: 'Type ID 1',  target_uri: 'hhtp://url', owner: 'owner'};
34
35     beforeEach(() => {
36         eiServiceSpy = jasmine.createSpyObj('EIService', ['getProducerIds', 'getJobsForProducer']);
37
38         eiServiceSpy.getProducerIds.and.returnValue(of([ 'producer1', 'producer2']));
39         eiServiceSpy.getJobsForProducer.and.returnValue(of([job]));
40         TestBed.configureTestingModule({
41             imports: [ToastrModule.forRoot()],
42             providers: [
43                 { provide: EIService, useValue: eiServiceSpy },
44                 NotificationService
45             ]
46         });
47     });
48
49     it('should create', () => {
50         dataSource = TestBed.get(EIJobDataSource);
51         expect(dataSource).toBeTruthy();
52     });
53
54     it('#getJobs', () => {
55         dataSource.getJobs();
56         const jobsSubject: BehaviorSubject<EIJob[]> = dataSource.eiJobsSubject;
57         const value = jobsSubject.getValue();
58         expect(value).toEqual([ job, job ]);
59         expect(dataSource.rowCount).toEqual(2);
60     });
61 });