Skip to content

Commit

Permalink
new tests added for new function in users.ts for editing password
Browse files Browse the repository at this point in the history
Refs: BLAIS5-4525
  • Loading branch information
SidraJaved committed Dec 24, 2024
1 parent f258831 commit 8893ad3
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/api/http/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { cleanup } from "@testing-library/react";
import { mock_server_request_function, mock_server_request_Return_JSON } from "../../tests/utils";
import { addNewUser, deleteUser, getAllUsers } from "./users";
import { addNewUser, deleteUser, editPassword, getAllUsers } from "./users";
import { NewUser, User } from "blaise-api-node-client";

const userList: User[] = [
Expand Down Expand Up @@ -162,3 +162,54 @@ describe("Function deleteUser(username: string) ", () => {
cleanup();
});
});

describe("Function editPassword(username: string, newPassword: string) ", () => {

const username = "testUser";
let newPassword = "password123";

Check failure on line 169 in src/api/http/users.test.ts

View workflow job for this annotation

GitHub Actions / lint (20.x)

'newPassword' is never reassigned. Use 'const' instead

it("It should return true if the password has been updated successfully", async () => {
mock_server_request_Return_JSON(204, {});

const response = await editPassword(username, newPassword);
expect(response).toBeTruthy();
});

it("It should return false if a password is not provided", async () => {
const invalidPassword = "";

mock_server_request_Return_JSON(204, {});

const response = await editPassword(username, invalidPassword);
expect(response).toBeFalsy();
});

it("It should return false if a 404 is returned from the server", async () => {
mock_server_request_Return_JSON(404, []);

const success = await editPassword(username, newPassword);
expect(success).toBeFalsy();
});

it("It should return false if request returns an error code", async () => {
mock_server_request_Return_JSON(500, {});

const success = await editPassword(username, newPassword);
expect(success).toBeFalsy();
});

it("It should return false if request call fails", async () => {

mock_server_request_function(jest.fn(() => {
throw new Error("Network error");
}));

const success = await editPassword(username, newPassword);
expect(success).toBeFalsy();
});

afterAll(() => {
jest.clearAllMocks();
cleanup();
});
});

0 comments on commit 8893ad3

Please sign in to comment.