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===================================
20 import { TestBed } from "@angular/core/testing";
22 import { PolicyService } from "./policy.service";
24 HttpClientTestingModule,
25 HttpTestingController,
26 } from "@angular/common/http/testing";
34 } from "@interfaces/policy.types";
35 import { Ric, Rics } from "@app/interfaces/ric";
37 describe("PolicyService", () => {
38 let apiVersion2 = "v2";
39 let basePath = "/a1-policy/";
40 let policyService: PolicyService;
41 let httpTestingController: HttpTestingController;
43 TestBed.configureTestingModule({
44 imports: [HttpClientTestingModule],
45 providers: [PolicyService],
50 policyService = TestBed.inject(PolicyService);
51 httpTestingController = TestBed.inject(HttpTestingController);
55 httpTestingController.verify();
58 it("#getPolicyTypes should return policy types", () => {
59 const expectedPolicytypes = {
60 policytype_ids: ["", "1"],
67 expect(policytypes).toEqual(
69 "should return expected PolicyTypes"
73 const req = httpTestingController.expectOne(
74 basePath + apiVersion2 + "/" + policyService.policyTypesPath
76 expect(req.request.method).toEqual("GET");
78 req.flush(expectedPolicytypes);
81 it("#getPolicyType", () => {
82 const policyTypeId = "1";
83 const expectedPolicyType = { policy_schema: "schema" } as PolicyType;
86 .getPolicyType(policyTypeId)
89 expect(policyType).toEqual(
91 "should return expected policy type"
96 const req = httpTestingController.expectOne(
100 policyService.policyTypesPath +
104 expect(req.request.method).toEqual("GET");
106 req.flush(expectedPolicyType);
109 it("#getPolicyInstancesByType should return policy instances", () => {
110 const policyTypeId = "1";
111 const expectedPolicyInstances = {
112 policy_ids: ["2100", "2000"],
113 } as PolicyInstances;
116 .getPolicyInstancesByType(policyTypeId)
119 expect(policyinstances).toEqual(
120 expectedPolicyInstances,
121 "should return expected Policy Instances"
126 const req = httpTestingController.expectOne(
130 policyService.policyPath +
135 expect(req.request.method).toEqual("GET");
137 req.flush(expectedPolicyInstances);
140 it("#getPolicyInstance should return one policy instance", () => {
141 const policyId = "2000";
142 const expectedPolicyInstance = {
147 service_id: "service1",
152 .getPolicyInstance(policyId)
155 expect(policyinstance).toEqual(
156 expectedPolicyInstance,
157 "should return expected Policy Instances"
162 const req = httpTestingController.expectOne(
163 basePath + apiVersion2 + "/" + policyService.policyPath + "/" + policyId
165 expect(req.request.method).toEqual("GET");
167 req.flush(expectedPolicyInstance);
170 it("#getPolicyStatus should return policy status", () => {
171 const policyId = "2000";
172 const expectedPolicyStatus = {
173 last_modified: "modified",
177 .getPolicyStatus(policyId)
180 expect(policyinstance).toEqual(
181 expectedPolicyStatus,
182 "should return expected Policy status"
187 const req = httpTestingController.expectOne(
191 policyService.policyPath +
196 expect(req.request.method).toEqual("GET");
198 req.flush(expectedPolicyStatus);
201 it("#putPolicy should return ok response", () => {
202 const createPolicyInstance = { policy_id: "2000" } as CreatePolicyInstance;
205 .putPolicy(createPolicyInstance)
208 expect(response.status).toEqual(
210 "should return expected response"
215 const req = httpTestingController.expectOne(
216 basePath + apiVersion2 + "/" + policyService.policyPath
218 expect(req.request.method).toEqual("PUT");
223 it("#deletePolicy should return ok response", () => {
224 const policyId = "2000";
227 .deletePolicy(policyId)
230 expect(response.status).toEqual(
232 "should return expected response"
237 const req = httpTestingController.expectOne(
238 basePath + apiVersion2 + "/" + policyService.policyPath + "/2000"
240 expect(req.request.method).toEqual("DELETE");
245 it("#getRics should return rics", () => {
246 const policyTypeId = "2000";
247 const expectedRic = { ric_id: "1" } as Ric;
248 const expectedRics = {
253 .getRics(policyTypeId)
256 expect(rics).toEqual(
258 "should return expected Rics"
263 const req = httpTestingController.expectOne(
266 "/rics?policytype_id=2000"
268 expect(req.request.method).toEqual("GET");
270 req.flush(expectedRics);