Skip to content

Commit 8b50d93

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

File tree

8 files changed

+143
-75
lines changed

8 files changed

+143
-75
lines changed

Diff for: package-lock.json

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

Diff for: package.json

+1-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",
@@ -98,6 +97,7 @@
9897
"husky": "^8.0.0",
9998
"identity-obj-proxy": "^3.0.0",
10099
"jest": "^29.7.0",
100+
"jest-fetch-mock": "^3.0.3",
101101
"lint-staged": "^15.2.5",
102102
"msw": "^2.3.1",
103103
"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 () => {

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/redux/reducers/notificationSlice.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ const notificationSlice = createSlice({
121121
.addCase(
122122
getUserNotifications.fulfilled,
123123
(state, action: PayloadAction<INotificationR[]>) => {
124-
// state.notifications = action.payload;
125-
// state.unreadCount = action.payload.filter(
126-
// (notification) => !notification.isRead,
127-
// ).length;
124+
state.notifications = action.payload;
125+
state.unreadCount = action.payload.filter(
126+
(notification) => !notification.isRead,
127+
).length;
128128
},
129129
)
130130
.addCase(handleCurrentUser.fulfilled, (state, action) => {

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)