Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into fix-notification
Browse files Browse the repository at this point in the history
  • Loading branch information
soleil00 committed Aug 1, 2024
2 parents 9fc752c + 5308eaf commit 67982ae
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 110 deletions.
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)$":
"<rootDir>/src/__test__/__mock__/fileMock.ts",
"\\.(css|less)$": "identity-obj-proxy",
"~src/(.*)": "<rootDir>/src/$1",
},
};
46 changes: 15 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"gsap": "^3.12.5",
"install": "^0.13.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"jest-mock-extended": "^3.0.7",
"jwt-decode": "^4.0.0",
"moment": "^2.30.1",
Expand Down Expand Up @@ -70,6 +69,7 @@
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@testing-library/dom": "^10.2.0",
"@testing-library/jest-dom": "^6.4.8",
"@types/jest": "^29.5.12",
"@types/jwt-decode": "^3.1.0",
"@types/node": "^20.14.8",
Expand Down Expand Up @@ -98,6 +98,7 @@
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"lint-staged": "^15.2.5",
"msw": "^2.3.1",
"postcss": "^8.4.38",
Expand Down
41 changes: 41 additions & 0 deletions src/__test__/currentUser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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",
email: "[email protected]",
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();
});
});
14 changes: 5 additions & 9 deletions src/__test__/notificationSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("notificationSlice", () => {
expect(state.unreadCount).toBe(1);
});

it.skip("should handle getUserNotifications thunk", async () => {
it("should handle getUserNotifications thunk", async () => {
const mockNotifications: INotificationR[] = [
{
id: 1,
Expand All @@ -113,17 +113,13 @@ describe("notificationSlice", () => {
data: { notifications: mockNotifications },
});

(connectSocketMock as jest.Mock).mockReturnValue(socketMock);

await store.dispatch(getUserNotifications());
const result = await store.dispatch(getUserNotifications());
console.log("Thunk result:", result);

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

expect(socketMock.emit).not.toHaveBeenCalled();
expect(socketMock.on).not.toHaveBeenCalled();
expect(state.notifications).toEqual(mockNotifications);
expect(state.unreadCount).toBe(2);
});

it("should handle readNotification thunk", async () => {
Expand Down
Loading

0 comments on commit 67982ae

Please sign in to comment.