blob: ede54465ddc5724112a0d9e4a033ae45d5e32781 [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 UserService from "./UserService";
20
21describe("Verify Login", () => {
22 let response;
23 let expectedResponse;
24 describe("Login Username Check", () => {
25 expectedResponse = { name: "name" };
26 beforeEach(async () => {
27 global.fetch = jest.fn(() =>
28 Promise.resolve({
29 text: () => Promise.resolve({ name: "name" }),
30 status: "Success",
31 ok: true,
32 })
33 );
34 response = await UserService.login();
35 });
36 it("Test login returns correct username", () => {
37 expect(response).toEqual(expectedResponse);
38 });
39 });
40 describe("Anonymouse Login Check", () => {
41 beforeEach(async () => {
42 global.fetch = jest.fn(() =>
43 Promise.resolve({
44 status: "Failed",
45 ok: false,
46 })
47 );
48 response = await UserService.login();
49 });
50 it("Test login returns Anonymous user", () => {
51 expect(response).toEqual("Anonymous");
52 });
53 });
54});
55describe("Verify GetUserInfo", () => {
56 let response;
57 let expectedResponse;
58 describe("Test Correct Username", () => {
59 expectedResponse = { name: "name" };
60 beforeEach(async () => {
61 global.fetch = jest.fn(() =>
62 Promise.resolve({
63 json: () => Promise.resolve({ name: "name" }),
64 status: "Success",
65 ok: true,
66 })
67 );
68 response = await UserService.getUserInfo();
69 });
70 it("Test getUserInfo returns correct username", () => {
71 expect(response).toEqual(expectedResponse);
72 });
73 });
74 describe("Empty User Check", () => {
75 beforeEach(async () => {
76 global.fetch = jest.fn(() =>
77 Promise.resolve({
78 status: "Failed",
79 ok: false,
80 })
81 );
82 response = await UserService.getUserInfo();
83 });
84 it("Test getUserInfo returns empty response", () => {
85 expect(response).toEqual({});
86 });
87 });
88});