Skip to content

Commit 96673d5

Browse files
committed
feat: mark as done on unsubscribe
Signed-off-by: Adam Setch <[email protected]>
1 parent 41f4ac9 commit 96673d5

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/hooks/useNotifications.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ describe('hooks/useNotifications.ts', () => {
426426
describe('unsubscribeNotification', () => {
427427
const id = 'notification-123';
428428

429-
it('should unsubscribe from a notification with success', async () => {
429+
it('should unsubscribe from a notification with success - markAsDoneOnUnsubscribe = false', async () => {
430430
// The unsubscribe endpoint call.
431431
nock('https://api.github.com/')
432432
.put(`/notifications/threads/${id}/subscription`)
@@ -453,6 +453,39 @@ describe('hooks/useNotifications.ts', () => {
453453
expect(result.current.notifications.length).toBe(0);
454454
});
455455

456+
it('should unsubscribe from a notification with success - markAsDoneOnUnsubscribe = true', async () => {
457+
// The unsubscribe endpoint call.
458+
nock('https://api.github.com/')
459+
.put(`/notifications/threads/${id}/subscription`)
460+
.reply(200);
461+
462+
// The mark done endpoint call.
463+
nock('https://api.github.com/')
464+
.delete(`/notifications/threads/${id}`)
465+
.reply(200);
466+
467+
const { result } = renderHook(() => useNotifications());
468+
469+
act(() => {
470+
result.current.unsubscribeNotification(
471+
{
472+
...mockState,
473+
settings: {
474+
...mockState.settings,
475+
markAsDoneOnUnsubscribe: true,
476+
},
477+
},
478+
mockSingleNotification,
479+
);
480+
});
481+
482+
await waitFor(() => {
483+
expect(result.current.status).toBe('success');
484+
});
485+
486+
expect(result.current.notifications.length).toBe(0);
487+
});
488+
456489
it('should unsubscribe from a notification with failure', async () => {
457490
// The unsubscribe endpoint call.
458491
nock('https://api.github.com/')

0 commit comments

Comments
 (0)