-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcurrentUser.test.ts
41 lines (32 loc) · 1.08 KB
/
currentUser.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import api from "../redux/api/api";
import { ICurrentUser } from "../redux/reducers/notificationSlice";
import { getCurrentUser } from "../utils/currentuser";
jest.mock("../redux/api/api");
const mockUser: ICurrentUser = {
id: 1,
name: "John Doe",
username: "johndoe",
password: "securepassword",
lastPasswordUpdateTime: new Date("2023-01-01T00:00:00Z"),
roleId: 2,
isActive: true,
isVerified: true,
createdAt: new Date("2022-01-01T00:00:00Z"),
updatedAt: new Date("2023-01-01T00:00:00Z"),
};
describe("getCurrentUser", () => {
beforeEach(() => {
(api.get as jest.Mock).mockReset();
});
it("should return user data when API call is successful", async () => {
(api.get as jest.Mock).mockResolvedValue({ data: mockUser });
const result = await getCurrentUser();
expect(result).toEqual(mockUser);
});
it("should return null when API call fails", async () => {
(api.get as jest.Mock).mockRejectedValue(new Error("Network Error"));
const result = await getCurrentUser();
expect(result).toBeNull();
});
});