-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into fix-notification
- Loading branch information
Showing
8 changed files
with
143 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters