diff --git a/src/__test__/currentUser.test.ts b/src/__test__/currentUser.test.ts new file mode 100644 index 0000000..a9e3b42 --- /dev/null +++ b/src/__test__/currentUser.test.ts @@ -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: "john.doe@example.com", + 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(); + }); +}); diff --git a/src/__test__/notificationSlice.test.ts b/src/__test__/notificationSlice.test.ts index ce95b28..b0f656b 100644 --- a/src/__test__/notificationSlice.test.ts +++ b/src/__test__/notificationSlice.test.ts @@ -87,45 +87,6 @@ describe("notificationSlice", () => { expect(state.unreadCount).toBe(1); }); - it.skip("should handle getUserNotifications thunk", async () => { - const mockNotifications: INotificationR[] = [ - { - id: 1, - userId: 1, - title: "Test Notification", - message: "This is a test notification", - isRead: false, - createdAt: new Date(), - updatedAt: new Date(), - }, - { - id: 2, - userId: 1, - title: "Test Notification", - message: "This is a test notification", - isRead: false, - createdAt: new Date(), - updatedAt: new Date(), - }, - ]; - - (api.get as jest.Mock).mockResolvedValueOnce({ - data: { notifications: mockNotifications }, - }); - - (connectSocketMock as jest.Mock).mockReturnValue(socketMock); - - await store.dispatch(getUserNotifications()); - - 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(); - }); - it("should handle readNotification thunk", async () => { const notification: INotificationR = { id: 1, diff --git a/src/components/common/header/Header.tsx b/src/components/common/header/Header.tsx index 92aa527..b6d733d 100644 --- a/src/components/common/header/Header.tsx +++ b/src/components/common/header/Header.tsx @@ -200,7 +200,7 @@ const Header: React.FC = ({ searchQuery, setSearchQuery }) => { )} - {userInfo.name.split(" ")[0]} + {userInfo.name?.split(" ")[0]} {dropdownOpen && } diff --git a/src/pages/paymentPage.tsx b/src/pages/paymentPage.tsx index 3bb3dec..07ee29f 100644 --- a/src/pages/paymentPage.tsx +++ b/src/pages/paymentPage.tsx @@ -174,5 +174,24 @@ const SuccessfulPayment = () => { ); }; +const CancelledPayment = () => ( +
+
+

+ ❌ Payment Was Cancelled +

+

+ Checkout Details about your carts If you wish to adjust ! +

+

Thank you for shopping with us.

+ + + + +
+
+); export default Payment; -export { SuccessfulPayment }; +export { SuccessfulPayment, CancelledPayment }; diff --git a/src/routes/AppRoutes.tsx b/src/routes/AppRoutes.tsx index 4054464..feb3318 100644 --- a/src/routes/AppRoutes.tsx +++ b/src/routes/AppRoutes.tsx @@ -33,10 +33,13 @@ import BuyerOrders from "../pages/BuyerOrders"; import SignupVerification from "../pages/SignupVerification"; import SmoothScroll from "../utils/SmoothScroll"; import NotFound from "../pages/NotFound"; -import Payment, { SuccessfulPayment } from "../pages/paymentPage"; import UserNotifications from "../components/common/user-notifications/UserNotifcations"; import UserNotificationDetail from "../components/common/user-notifications/UserNotificationDetail"; import { LogoutProvider } from "../components/dashboard/admin/LogoutContext"; +import Payment, { + CancelledPayment, + SuccessfulPayment, +} from "../pages/paymentPage"; const AppRoutes = () => { const navigate = useNavigate(); @@ -60,62 +63,64 @@ const AppRoutes = () => { }; return ( - - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + + + }> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } + /> + + } /> + } /> + } /> + } /> + } /> + } + path="/login" + element={( + + + + )} /> - - } /> - } /> - } /> - } /> - } /> - - - - - )} - /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } - /> - } - /> - } /> - } /> - + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } + /> + } + /> + } /> + } /> + + ); };