2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
21 import { TestBed } from '@angular/core/testing';
23 import { ProducerStatus, OperationalState, ProducerRegistrationInfo } from '@interfaces/producer.types';
24 import { ProducerService } from './producer.service';
26 describe('ProducerService', () => {
27 let basePath = '/data-producer/v1';
28 let service: ProducerService;
29 let httpTestingController: HttpTestingController;
31 beforeEach(() => TestBed.configureTestingModule({
33 HttpClientTestingModule
40 it('should be created', () => {
41 service = TestBed.inject(ProducerService);
42 expect(service).toBeTruthy();
45 describe('#getProducerIds', () => {
46 let expectedEIProducerIds: string[];
49 service = TestBed.inject(ProducerService);
50 httpTestingController = TestBed.inject(HttpTestingController);
51 expectedEIProducerIds = [ 'producer1', 'producer2' ] as string[];
54 it('should return all producer IDs', () => {
55 service.getProducerIds().subscribe(
56 producers => expect(producers).toEqual(expectedEIProducerIds, 'should return expected EIProducer IDs'),
60 const req = httpTestingController.expectOne(basePath + '/' + service.producersPath);
61 expect(req.request.method).toEqual('GET');
63 req.flush(expectedEIProducerIds); //Return expected producer IDs
65 httpTestingController.verify();
69 describe('#getProducer', () => {
70 let expectedProducer: ProducerRegistrationInfo;
73 service = TestBed.inject(ProducerService);
74 httpTestingController = TestBed.inject(HttpTestingController);
76 supported_info_types: [ 'type1', 'type2' ]
77 } as ProducerRegistrationInfo;
80 it('should return producer', () => {
81 service.getProducer('producer1').subscribe(
82 producer => expect(producer).toEqual(expectedProducer, 'should return expected producer'),
86 const req = httpTestingController.expectOne(basePath + '/' + service.producersPath + '/producer1');
87 expect(req.request.method).toEqual('GET');
89 req.flush(expectedProducer); //Return expected producer
91 httpTestingController.verify();
95 describe('#getProducerStatus', () => {
96 let expectedProducerStatus: ProducerStatus;
99 service = TestBed.inject(ProducerService);
100 httpTestingController = TestBed.inject(HttpTestingController);
101 expectedProducerStatus = {
102 operational_state: OperationalState.ENABLED
106 it('should return producer status', () => {
107 service.getProducerStatus('producer1').subscribe(
108 producerStatus => expect(producerStatus).toEqual(expectedProducerStatus, 'should return expected producer'),
112 const req = httpTestingController.expectOne(basePath + '/' + service.producersPath + '/producer1/' + service.producerStatusPath);
113 expect(req.request.method).toEqual('GET');
115 req.flush(expectedProducerStatus); //Return expected status
117 httpTestingController.verify();