Skip to content

Commit b647a4c

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

File tree

5 files changed

+122
-96
lines changed

5 files changed

+122
-96
lines changed

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

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

90-
it.skip("should handle getUserNotifications thunk", async () => {
91-
const mockNotifications: INotificationR[] = [
92-
{
93-
id: 1,
94-
userId: 1,
95-
title: "Test Notification",
96-
message: "This is a test notification",
97-
isRead: false,
98-
createdAt: new Date(),
99-
updatedAt: new Date(),
100-
},
101-
{
102-
id: 2,
103-
userId: 1,
104-
title: "Test Notification",
105-
message: "This is a test notification",
106-
isRead: false,
107-
createdAt: new Date(),
108-
updatedAt: new Date(),
109-
},
110-
];
111-
112-
(api.get as jest.Mock).mockResolvedValueOnce({
113-
data: { notifications: mockNotifications },
114-
});
115-
116-
(connectSocketMock as jest.Mock).mockReturnValue(socketMock);
117-
118-
await store.dispatch(getUserNotifications());
119-
120-
const state = store.getState().notifications;
121-
console.log("State after getUserNotifications:", state);
122-
// expect(state.notifications).toEqual(mockNotifications);
123-
expect(state.unreadCount).toBe(1);
124-
125-
expect(socketMock.emit).not.toHaveBeenCalled();
126-
expect(socketMock.on).not.toHaveBeenCalled();
127-
});
128-
12990
it("should handle readNotification thunk", async () => {
13091
const notification: INotificationR = {
13192
id: 1,

Diff for: src/components/common/header/Header.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const Header: React.FC<ISerachProps> = ({ searchQuery, setSearchQuery }) => {
200200
)}
201201
<Stack className="flex flex-col">
202202
<span className="hidden lg:block select-none font-semibold text-[12px]">
203-
{userInfo.name.split(" ")[0]}
203+
{userInfo.name?.split(" ")[0]}
204204
</span>
205205
</Stack>
206206
{dropdownOpen && <ProfileDropdown userInfo={userInfo} />}

Diff for: src/pages/paymentPage.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,24 @@ const SuccessfulPayment = () => {
174174
);
175175
};
176176

177+
const CancelledPayment = () => (
178+
<section className="flex items-center justify-center py-32 bg-gray-100 md:m-0 px-4 ">
179+
<div className="bg-white p-6 rounded shadow-md text-center">
180+
<h1 className="text-2xl font-medium text-red-500">
181+
❌ Payment Was Cancelled
182+
</h1>
183+
<p className="mt-4">
184+
Checkout Details about your carts If you wish to adjust !
185+
</p>
186+
<p className="mt-2">Thank you for shopping with us.</p>
187+
188+
<Link to="/carts">
189+
<button className="mt-4 inline-block px-4 py-2 text-white bg-red-500 rounded transition-colors duration-300 cursor-pointer hover:bg-green-600">
190+
Checkout your Carts
191+
</button>
192+
</Link>
193+
</div>
194+
</section>
195+
);
177196
export default Payment;
178-
export { SuccessfulPayment };
197+
export { SuccessfulPayment, CancelledPayment };

Diff for: src/routes/AppRoutes.tsx

+60-55
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ import BuyerOrders from "../pages/BuyerOrders";
3333
import SignupVerification from "../pages/SignupVerification";
3434
import SmoothScroll from "../utils/SmoothScroll";
3535
import NotFound from "../pages/NotFound";
36-
import Payment, { SuccessfulPayment } from "../pages/paymentPage";
3736
import UserNotifications from "../components/common/user-notifications/UserNotifcations";
3837
import UserNotificationDetail from "../components/common/user-notifications/UserNotificationDetail";
3938
import { LogoutProvider } from "../components/dashboard/admin/LogoutContext";
39+
import Payment, {
40+
CancelledPayment,
41+
SuccessfulPayment,
42+
} from "../pages/paymentPage";
4043

4144
const AppRoutes = () => {
4245
const navigate = useNavigate();
@@ -60,62 +63,64 @@ const AppRoutes = () => {
6063
};
6164
return (
6265
<SmoothScroll>
63-
<Routes>
64-
<Route path="/" element={<RootLayout />}>
65-
<Route index element={<Homepage />} />
66-
<Route path="products" element={<ProductPage />} />
67-
<Route path="products/:id" element={<ProductDetails />} />
68-
<Route path="/carts" element={<CartManagement />} />
69-
<Route path="/wishes" element={<BuyerWishesList />} />
70-
<Route path="/orders" element={<BuyerOrders />} />
71-
<Route path="/payment" element={<Payment />} />
72-
<Route path="/payment/success" element={<SuccessfulPayment />} />
73-
<Route path="/payment/canceled" element={<Payment />} />
74-
<Route path="/notifications" element={<UserNotifications />} />
66+
<LogoutProvider>
67+
<Routes>
68+
<Route path="/" element={<RootLayout />}>
69+
<Route index element={<Homepage />} />
70+
<Route path="products" element={<ProductPage />} />
71+
<Route path="products/:id" element={<ProductDetails />} />
72+
<Route path="/carts" element={<CartManagement />} />
73+
<Route path="/wishes" element={<BuyerWishesList />} />
74+
<Route path="/orders" element={<BuyerOrders />} />
75+
<Route path="/payment" element={<Payment />} />
76+
<Route path="/payment/success" element={<SuccessfulPayment />} />
77+
<Route path="/payment/canceled" element={<Payment />} />
78+
<Route path="/notifications" element={<UserNotifications />} />
79+
<Route
80+
path="/notifications/:id"
81+
element={<UserNotificationDetail />}
82+
/>
83+
</Route>
84+
<Route path="chat" element={<ChatPage />} />
85+
<Route path="/password-reset-link" element={<GetLinkPage />} />
86+
<Route path="/reset-password" element={<ResetPassword />} />
87+
<Route path="/register" element={<RegisterUser />} />
88+
<Route path="/verify-user" element={<SignupVerification />} />
89+
7590
<Route
76-
path="/notifications/:id"
77-
element={<UserNotificationDetail />}
91+
path="/login"
92+
element={(
93+
<AlreadyLogged>
94+
<Login />
95+
</AlreadyLogged>
96+
)}
7897
/>
79-
</Route>
80-
<Route path="chat" element={<ChatPage />} />
81-
<Route path="/password-reset-link" element={<GetLinkPage />} />
82-
<Route path="/reset-password" element={<ResetPassword />} />
83-
<Route path="/register" element={<RegisterUser />} />
84-
<Route path="/verify-user" element={<SignupVerification />} />
85-
86-
<Route
87-
path="/login"
88-
element={(
89-
<AlreadyLogged>
90-
<Login />
91-
</AlreadyLogged>
92-
)}
93-
/>
94-
<Route path="2fa-verify" element={<OtpVerificationForm />} />
95-
<Route path="/dashboard" element={<SellerDashboard />} />
96-
<Route path="/dashboard/addproduct" element={<AddProduct />} />
97-
<Route path="/update-password" element={<UpdatePasswordPage />} />
98-
<Route path="/profile" element={<UsersProfile />} />
99-
<Route path="/profile/update" element={<UpdateUserProfile />} />
100-
<Route path="/dashboard/products" element={<Products />} />
101-
<Route path="/dashboard/products/:id" element={<AddProduct />} />
102-
<Route path="/dashboard/orders" element={<SellerOrder />} />
103-
<Route path="/admin/dashboard" element={<Dashboard />} />
104-
<Route path="/admin/users" element={<UserManagement />} />
105-
<Route path="/admin/settings" element={<Settings />} />
106-
<Route path="/admin/analytics" element={<Analytics />} />
107-
<Route path="/admin/Products" element={<Products />} />
108-
<Route
109-
path="/dashboard/notifications"
110-
element={<SellerNotifications />}
111-
/>
112-
<Route
113-
path="/dashboard/notifications/:id"
114-
element={<NotificationDetail />}
115-
/>
116-
<Route path="/dashboard/wishes" element={<Wishes />} />
117-
<Route path="/*" element={<NotFound />} />
118-
</Routes>
98+
<Route path="2fa-verify" element={<OtpVerificationForm />} />
99+
<Route path="/dashboard" element={<SellerDashboard />} />
100+
<Route path="/dashboard/addproduct" element={<AddProduct />} />
101+
<Route path="/update-password" element={<UpdatePasswordPage />} />
102+
<Route path="/profile" element={<UsersProfile />} />
103+
<Route path="/profile/update" element={<UpdateUserProfile />} />
104+
<Route path="/dashboard/products" element={<Products />} />
105+
<Route path="/dashboard/products/:id" element={<AddProduct />} />
106+
<Route path="/dashboard/orders" element={<SellerOrder />} />
107+
<Route path="/admin/dashboard" element={<Dashboard />} />
108+
<Route path="/admin/users" element={<UserManagement />} />
109+
<Route path="/admin/settings" element={<Settings />} />
110+
<Route path="/admin/analytics" element={<Analytics />} />
111+
<Route path="/admin/Products" element={<Products />} />
112+
<Route
113+
path="/dashboard/notifications"
114+
element={<SellerNotifications />}
115+
/>
116+
<Route
117+
path="/dashboard/notifications/:id"
118+
element={<NotificationDetail />}
119+
/>
120+
<Route path="/dashboard/wishes" element={<Wishes />} />
121+
<Route path="/*" element={<NotFound />} />
122+
</Routes>
123+
</LogoutProvider>
119124
</SmoothScroll>
120125
);
121126
};

0 commit comments

Comments
 (0)