Skip to content

Commit 67982ae

Browse files
committed
Merge remote-tracking branch 'origin/dev' into fix-notification
2 parents 9fc752c + 5308eaf commit 67982ae

File tree

11 files changed

+390
-110
lines changed

11 files changed

+390
-110
lines changed

Diff for: jest.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export default {
88
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)$":
99
"<rootDir>/src/__test__/__mock__/fileMock.ts",
1010
"\\.(css|less)$": "identity-obj-proxy",
11+
"~src/(.*)": "<rootDir>/src/$1",
1112
},
1213
};

Diff for: package-lock.json

+15-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"gsap": "^3.12.5",
3939
"install": "^0.13.0",
4040
"jest-environment-jsdom": "^29.7.0",
41-
"jest-fetch-mock": "^3.0.3",
4241
"jest-mock-extended": "^3.0.7",
4342
"jwt-decode": "^4.0.0",
4443
"moment": "^2.30.1",
@@ -70,6 +69,7 @@
7069
"@commitlint/cli": "^19.3.0",
7170
"@commitlint/config-conventional": "^19.2.2",
7271
"@testing-library/dom": "^10.2.0",
72+
"@testing-library/jest-dom": "^6.4.8",
7373
"@types/jest": "^29.5.12",
7474
"@types/jwt-decode": "^3.1.0",
7575
"@types/node": "^20.14.8",
@@ -98,6 +98,7 @@
9898
"husky": "^8.0.0",
9999
"identity-obj-proxy": "^3.0.0",
100100
"jest": "^29.7.0",
101+
"jest-fetch-mock": "^3.0.3",
101102
"lint-staged": "^15.2.5",
102103
"msw": "^2.3.1",
103104
"postcss": "^8.4.38",

Diff for: src/__test__/currentUser.test.ts

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

Diff for: src/__test__/notificationSlice.test.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("notificationSlice", () => {
8787
expect(state.unreadCount).toBe(1);
8888
});
8989

90-
it.skip("should handle getUserNotifications thunk", async () => {
90+
it("should handle getUserNotifications thunk", async () => {
9191
const mockNotifications: INotificationR[] = [
9292
{
9393
id: 1,
@@ -113,17 +113,13 @@ describe("notificationSlice", () => {
113113
data: { notifications: mockNotifications },
114114
});
115115

116-
(connectSocketMock as jest.Mock).mockReturnValue(socketMock);
117-
118-
await store.dispatch(getUserNotifications());
116+
const result = await store.dispatch(getUserNotifications());
117+
console.log("Thunk result:", result);
119118

120119
const state = store.getState().notifications;
121-
console.log("State after getUserNotifications:", state);
122-
// expect(state.notifications).toEqual(mockNotifications);
123-
expect(state.unreadCount).toBe(1);
124120

125-
expect(socketMock.emit).not.toHaveBeenCalled();
126-
expect(socketMock.on).not.toHaveBeenCalled();
121+
expect(state.notifications).toEqual(mockNotifications);
122+
expect(state.unreadCount).toBe(2);
127123
});
128124

129125
it("should handle readNotification thunk", async () => {

0 commit comments

Comments
 (0)