2 * ========================LICENSE_START=================================
5 * Copyright (C) 2021 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===================================
21 import { TestBed } from '@angular/core/testing';
22 import { BehaviorSubject, of } from 'rxjs';
23 import { ToastrModule } from 'ngx-toastr';
24 import { PolicyTypeDataSource } from './policy-type.datasource';
25 import { PolicyService } from '@services/policy/policy.service';
26 import { PolicyTypeSchema } from '@interfaces/policy.types';
28 describe('PolicyTypeDataSource', () => {
29 let policyTypeDataSource: PolicyTypeDataSource;
30 let policyServiceSpy: any;
34 "$schema": "http://json-schema.org/draft-07/schema#",
35 "description": "Type 1 policy type",
36 "additionalProperties": false,
43 policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getPolicyTypes', 'getPolicyType']);
45 policyServiceSpy.getPolicyTypes.and.returnValue(of({ policytype_ids: ['1', '2'] }));
46 policyServiceSpy.getPolicyType.and.returnValue(of(policySchema));
47 TestBed.configureTestingModule({
48 imports: [ToastrModule.forRoot()],
50 { provide: PolicyService, useValue: policyServiceSpy }
55 describe('#getPolicyTypes', () => {
56 let expectedPolicyTypeValue: PolicyTypeSchema[];
58 expectedPolicyTypeValue = [
62 'schemaObject': policySchema.policy_schema
67 'schemaObject': policySchema.policy_schema
72 it('should create', () => {
73 policyTypeDataSource = TestBed.inject(PolicyTypeDataSource);
74 expect(policyTypeDataSource).toBeTruthy();
77 it('should return all policy type with Schema', () => {
78 policyTypeDataSource.getPolicyTypes();
79 const jobsSubject: BehaviorSubject<PolicyTypeSchema[]> = policyTypeDataSource.policyTypeSubject;
80 const value = jobsSubject.getValue();
81 expect(value).toEqual(expectedPolicyTypeValue);