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 { ConsumerService } from "./consumer.service";
21 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
22 import { TestBed } from '@angular/core/testing';
23 import { JobInfo, ConsumerStatus, OperationalState } from '@app/interfaces/consumer.types';
25 describe('ConsumerService', () => {
26 let basePath = '/data-consumer/v1';
27 let service: ConsumerService;
28 let httpTestingController: HttpTestingController;
29 let expectedEIJobs: string[];
30 let expectedConsumerStatus: ConsumerStatus;
31 let expectedJobInfo: JobInfo;
33 beforeEach(() => TestBed.configureTestingModule({
35 HttpClientTestingModule
43 service = TestBed.inject(ConsumerService);
44 httpTestingController = TestBed.inject(HttpTestingController);
45 expectedEIJobs = ['job1', 'job2'];
46 expectedConsumerStatus = {
47 info_job_status: OperationalState.ENABLED,
53 job_definition: 'data',
54 info_type_id: 'type1',
55 job_result_uri: 'uri',
57 status_notification_uri: 'status_uri'
61 it('should be created', () => {
62 service = TestBed.inject(ConsumerService);
63 expect(service).toBeTruthy();
66 it('should get all the jobs ids', () => {
67 service.getJobIds().subscribe(
68 jobs => expect(jobs).toEqual(expectedEIJobs, 'should return expected Jobs'),
72 const req = httpTestingController.expectOne(basePath + '/' + service.jobsPath);
73 expect(req.request.method).toEqual('GET');
75 req.flush(expectedEIJobs); //Return expected jobs ids
77 httpTestingController.verify();
81 it('should return consumer status', () => {
82 service.getConsumerStatus('job1').subscribe(
83 consumerStatus => expect(consumerStatus).toEqual(expectedConsumerStatus, 'should return expected status'),
87 const req = httpTestingController.expectOne(basePath + '/' + service.jobsPath + '/job1/' + service.consumerStatusPath);
88 expect(req.request.method).toEqual('GET');
90 req.flush(expectedConsumerStatus); //Return expected status
92 httpTestingController.verify();
95 it('should return the job info', () => {
96 service.getJobInfo('job1').subscribe(
97 jobInfo => expect(jobInfo).toEqual(expectedJobInfo, 'should return expected job info'),
101 const req = httpTestingController.expectOne(basePath + '/' + service.jobsPath + '/job1');
102 expect(req.request.method).toEqual('GET');
104 req.flush(expectedJobInfo); //Return expected job info
106 httpTestingController.verify();