blob: bd68582bcf819c810f251bc8d9052243e455c194 [file] [log] [blame]
Lathishf4f497d2022-01-11 15:53:39 +05301/*
2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
18 */
19import LoopService from "./LoopService";
20
21describe("Verify GetLoopNames", () => {
22 let response;
23 let loopNameJson;
24 describe("Non-Empty Json Check", () => {
25 loopNameJson = { name: "loop1" };
26 global.fetch = jest.fn(() =>
27 Promise.resolve({
28 json: () => Promise.resolve({ name: "loop1" }),
29 status: "Success",
30 ok: true,
31 })
32 );
33 beforeEach(async () => {
34 response = await LoopService.getLoopNames();
35 });
36 it("Test getLoopNames returns correct json", () => {
37 expect(response).toEqual(loopNameJson);
38 });
39 });
40 describe("Empty Json Check", () => {
41 loopNameJson = {};
42 global.fetch = jest.fn(() =>
43 Promise.resolve({
44 json: () => Promise.resolve({}),
45 status: "Failed",
46 ok: false,
47 })
48 );
49 beforeEach(async () => {
50 response = await LoopService.getLoopNames();
51 });
52 it("Test getLoopNames returns empty json", () => {
53 expect(response).toEqual(loopNameJson);
54 });
55 });
56 describe("Error during API call", () => {
57 loopNameJson = {};
58 beforeEach(async () => {
59 response = await LoopService.getLoopNames();
60 });
61 it("Test getLoopNames returns empty json", () => {
62 expect(response).toEqual(loopNameJson);
63 });
64 });
65});
66
67describe("Verify CreateLoop", () => {
68 let response;
69 let loopNameJson;
70 let loopName = "loop1";
71 let templateName = "template1";
72 describe("Non-Empty Json Check", () => {
73 loopNameJson = { name: "loop1" };
74 beforeEach(async () => {
75 global.fetch = jest.fn(() =>
76 Promise.resolve({
77 json: () => Promise.resolve({ name: "loop1" }),
78 status: "Success",
79 ok: true,
80 })
81 );
82 response = await LoopService.createLoop(loopName, templateName);
83 });
84
85 it("Test createLoop returns correct json", () => {
86 expect(response).toEqual(loopNameJson);
87 });
88 });
89 describe("Error during API call", () => {
90 let emptyResponse = "";
91 beforeEach(async () => {
92 global.fetch = jest.fn(() =>
93 Promise.resolve({
94 json: () => Promise.resolve(""),
95 })
96 );
97 response = await LoopService.createLoop("", "");
98 });
99 it("Test createLoop returns empty", () => {
100 expect(response).toEqual(emptyResponse);
101 });
102 });
103});
104describe("Verify GetLoop", () => {
105 let actualResponse;
106 let expected;
107 let name = "loop1";
108 describe("Non-Empty Json Check", () => {
109 beforeEach(async () => {
110 expected = { name: "loop1" };
111 global.fetch = jest.fn(() =>
112 Promise.resolve({
113 json: () => Promise.resolve({ name: "loop1" }),
114 status: "Success",
115 ok: true,
116 })
117 );
118 actualResponse = await LoopService.getLoop(name);
119 });
120
121 it("Test getLoop returns correct json", () => {
122 expect(actualResponse).toEqual(expected);
123 });
124 });
125 describe("Error during API call", () => {
126 beforeEach(async () => {
127 expected = {};
128 global.fetch = jest.fn(() =>
129 Promise.resolve({
130 json: () => Promise.resolve({}),
131 })
132 );
133 actualResponse = await LoopService.getLoop(name);
134 });
135 it("Test getLoop returns empty", () => {
136 expect(actualResponse).toEqual(expected);
137 });
138 });
139});
140describe("Verify SetMicroServiceProperties", () => {
141 let actualResponse;
142 let expected;
143 let name = "loop1";
144 let jsonData = {};
145 describe("Non-Empty Text Check", () => {
146 beforeEach(async () => {
147 expected = "data";
148 global.fetch = jest.fn(() =>
149 Promise.resolve({
150 text: () => Promise.resolve("data"),
151 status: "Success",
152 ok: true,
153 })
154 );
155 actualResponse = await LoopService.setMicroServiceProperties(
156 name,
157 jsonData
158 );
159 });
160
161 it("Test setMicroServiceProperties returns correct text", () => {
162 expect(actualResponse).toEqual(expected);
163 });
164 });
165 describe("Error during API call", () => {
166 beforeEach(async () => {
167 expected = "";
168 global.fetch = jest.fn(() =>
169 Promise.resolve({
170 json: () => Promise.resolve(""),
171 })
172 );
173 actualResponse = await LoopService.setMicroServiceProperties(
174 name,
175 jsonData
176 );
177 });
178 it("Test setMicroServiceProperties returns empty", () => {
179 expect(actualResponse).toEqual(expected);
180 });
181 });
182});
183describe("Verify SetOperationalPolicyProperties", () => {
184 let actualResponse;
185 let expected;
186 let name = "loop1";
187 let jsonData = {};
188 describe("Non-Empty Text Check", () => {
189 beforeEach(async () => {
190 expected = "data";
191 global.fetch = jest.fn(() =>
192 Promise.resolve({
193 text: () => Promise.resolve("data"),
194 status: "Success",
195 ok: true,
196 })
197 );
198 actualResponse = await LoopService.setOperationalPolicyProperties(
199 name,
200 jsonData
201 );
202 });
203
204 it("Test setOperationalPolicyProperties returns correct text", () => {
205 expect(actualResponse).toEqual(expected);
206 });
207 });
208 describe("Error during API call", () => {
209 beforeEach(async () => {
210 expected = "";
211 global.fetch = jest.fn(() =>
212 Promise.resolve({
213 json: () => Promise.resolve(""),
214 })
215 );
216 actualResponse = await LoopService.setOperationalPolicyProperties(
217 name,
218 jsonData
219 );
220 });
221 it("Test setOperationalPolicyProperties returns empty", () => {
222 expect(actualResponse).toEqual(expected);
223 });
224 });
225});
226describe("Verify UpdateGlobalProperties", () => {
227 let actualResponse;
228 let expected;
229 let name = "loop1";
230 let jsonData = {};
231 describe("Non-Empty Text Check", () => {
232 beforeEach(async () => {
233 expected = "data";
234 global.fetch = jest.fn(() =>
235 Promise.resolve({
236 text: () => Promise.resolve("data"),
237 status: "Success",
238 ok: true,
239 })
240 );
241 actualResponse = await LoopService.updateGlobalProperties(name, jsonData);
242 });
243
244 it("Test updateGlobalProperties returns correct text", () => {
245 expect(actualResponse).toEqual(expected);
246 });
247 });
248 describe("Error during API call", () => {
249 beforeEach(async () => {
250 expected = "";
251 global.fetch = jest.fn(() =>
252 Promise.resolve({
253 json: () => Promise.resolve(""),
254 })
255 );
256 actualResponse = await LoopService.updateGlobalProperties(name, jsonData);
257 });
258 it("Test updateGlobalProperties returns empty", () => {
259 expect(actualResponse).toEqual(expected);
260 });
261 });
262});
263describe("Verify RefreshOperationalPolicyJson", () => {
264 let actualResponse;
265 let expected;
266 let name = "loop1";
267 let policyName = "policy";
268 describe("Non-Empty Json Check", () => {
269 beforeEach(async () => {
270 expected = { name: "loop1" };
271 global.fetch = jest.fn(() =>
272 Promise.resolve({
273 json: () => Promise.resolve({ name: "loop1" }),
274 status: "Success",
275 ok: true,
276 })
277 );
278 actualResponse = await LoopService.refreshOperationalPolicyJson(
279 name,
280 policyName
281 );
282 });
283
284 it("Test refreshOperationalPolicyJson returns correct json", () => {
285 expect(actualResponse).toEqual(expected);
286 });
287 });
288 describe("Error during API call", () => {
289 beforeEach(async () => {
290 expected = {};
291 global.fetch = jest.fn(() =>
292 Promise.resolve({
293 json: () => Promise.resolve({}),
294 })
295 );
296 actualResponse = await LoopService.refreshOperationalPolicyJson(
297 name,
298 policyName
299 );
300 });
301 it("Test refreshOperationalPolicyJson returns empty", () => {
302 expect(actualResponse).toEqual(expected);
303 });
304 });
305});
306describe("Verify RefreshMicroServicePolicyJson", () => {
307 let actualResponse;
308 let expected;
309 let name = "loop1";
310 let policyName = "policy";
311 describe("Non-Empty Json Check", () => {
312 beforeEach(async () => {
313 expected = { name: "loop1" };
314 global.fetch = jest.fn(() =>
315 Promise.resolve({
316 json: () => Promise.resolve({ name: "loop1" }),
317 status: "Success",
318 ok: true,
319 })
320 );
321 actualResponse = await LoopService.refreshMicroServicePolicyJson(
322 name,
323 policyName
324 );
325 });
326
327 it("Test refreshMicroServicePolicyJson returns correct json", () => {
328 expect(actualResponse).toEqual(expected);
329 });
330 });
331 describe("Error during API call", () => {
332 beforeEach(async () => {
333 expected = {};
334 global.fetch = jest.fn(() =>
335 Promise.resolve({
336 json: () => Promise.resolve({}),
337 })
338 );
339 actualResponse = await LoopService.refreshMicroServicePolicyJson(
340 name,
341 policyName
342 );
343 });
344 it("Test refreshMicroServicePolicyJson returns empty", () => {
345 expect(actualResponse).toEqual(expected);
346 });
347 });
348});
349describe("Verify AddOperationalPolicyType", () => {
350 let actualResponse;
351 let expected;
352 let name = "loop1";
353 let type = "type";
354 let version = "version";
355 describe("Non-Empty Json Check", () => {
356 beforeEach(async () => {
357 expected = { name: "loop1" };
358 global.fetch = jest.fn(() =>
359 Promise.resolve({
360 json: () => Promise.resolve({ name: "loop1" }),
361 status: "Success",
362 ok: true,
363 })
364 );
365 actualResponse = await LoopService.addOperationalPolicyType(
366 name,
367 type,
368 version
369 );
370 });
371
372 it("Test addOperationalPolicyType returns correct json", () => {
373 expect(actualResponse).toEqual(expected);
374 });
375 });
376 describe("Error during API call", () => {
377 beforeEach(async () => {
378 expected = new Error("error");
379 global.fetch = jest.fn(() =>
380 Promise.resolve({
381 text: () => Promise.resolve(expected),
382 })
383 );
384 actualResponse = await LoopService.addOperationalPolicyType(
385 name,
386 type,
387 version
388 );
389 });
390 it("Test addOperationalPolicyType returns empty", () => {
391 expect(actualResponse).toEqual(expected);
392 });
393 });
394});
395describe("Verify RemoveOperationalPolicyType", () => {
396 let actualResponse;
397 let expected;
398 let name = "loop1";
399 let type = "type";
400 let version = "version";
401 let policyName = "policy";
402 describe("Non-Empty Json Check", () => {
403 beforeEach(async () => {
404 expected = { name: "loop1" };
405 global.fetch = jest.fn(() =>
406 Promise.resolve({
407 json: () => Promise.resolve({ name: "loop1" }),
408 status: "Success",
409 ok: true,
410 })
411 );
412 actualResponse = await LoopService.removeOperationalPolicyType(
413 name,
414 type,
415 version,
416 policyName
417 );
418 });
419
420 it("Test removeOperationalPolicyType returns correct json", () => {
421 expect(actualResponse).toEqual(expected);
422 });
423 });
424 describe("Error during API call", () => {
425 beforeEach(async () => {
426 expected = {};
427 global.fetch = jest.fn(() =>
428 Promise.resolve({
429 json: () => Promise.resolve({}),
430 })
431 );
432 actualResponse = await LoopService.removeOperationalPolicyType(
433 name,
434 type,
435 version,
436 policyName
437 );
438 });
439 it("Test removeOperationalPolicyType returns empty", () => {
440 expect(actualResponse).toEqual(expected);
441 });
442 });
443});