Skip to content

Commit c003148

Browse files
committed
feat(notifications): Add markAsRead method to the service
1 parent 61a1195 commit c003148

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/notifications/NotificationService.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ const getNotifications = async (
1717
}
1818
};
1919

20+
const markAsRead = async (notificationId: number) => {
21+
try {
22+
const response = await DiscourseService.put("notifications/mark-read", {
23+
id: notificationId,
24+
});
25+
26+
return response;
27+
} catch (e) {
28+
return null;
29+
}
30+
};
31+
2032
export default {
2133
getNotifications,
34+
markAsRead,
2235
};

src/notifications/__tests__/NotificationService.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import DiscourseService from "../../common/DiscourseService";
2+
import faker from "faker";
23
import { notifications } from "../../__fixtures__/notifications";
34
import NotificationService from "../NotificationService";
45

@@ -33,4 +34,19 @@ describe("NotificationService", () => {
3334
});
3435
});
3536
});
37+
38+
describe("markAsRead", () => {
39+
it("sends a request to the mark notifications as read", () => {
40+
const notifificationId = faker.random.number();
41+
DiscourseService.put = jest.fn().mockResolvedValueOnce(null);
42+
43+
NotificationService.markAsRead(notifificationId);
44+
45+
expect(DiscourseService.put).toHaveBeenCalledTimes(1);
46+
expect(DiscourseService.put).toHaveBeenCalledWith(
47+
"notifications/mark-read",
48+
{ id: notifificationId }
49+
);
50+
});
51+
});
3652
});

0 commit comments

Comments
 (0)