Skip to content

Commit

Permalink
test: added failed and denied test cases of redux
Browse files Browse the repository at this point in the history
  • Loading branch information
SundasNoreen committed Jun 19, 2023
1 parent 4483a73 commit 8175ba8
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/Notifications/data/redux.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ describe('Notification Redux', () => {
expect(Object.keys(notifications)).toHaveLength(2);
});

it.each([
{ statusCode: 404, status: 'failed' },
{ statusCode: 403, status: 'denied' },
])('%s to load notifications list in the redux.', async ({ statusCode, status }) => {
axiosMock.onGet(notificationsApiUrl).reply(statusCode);
await executeThunk(fetchNotificationList({ page: 1, pageSize: 10 }), store.dispatch, store.getState);

const { notifications: { notificationStatus } } = store.getState();

expect(notificationStatus).toEqual(status);
});

it('Successfully loaded notification counts in the redux.', async () => {
const { notifications: { tabsCount } } = store.getState();

Expand All @@ -85,13 +97,37 @@ describe('Notification Redux', () => {
expect(tabsCount.authoring).toEqual(5);
});

it.each([
{ statusCode: 404, status: 'failed' },
{ statusCode: 403, status: 'denied' },
])('%s to load notification counts in the redux.', async ({ statusCode, status }) => {
axiosMock.onGet(notificationCountsApiUrl).reply(statusCode);
await executeThunk(fetchAppsNotificationCount(), store.dispatch, store.getState);

const { notifications: { notificationStatus } } = store.getState();

expect(notificationStatus).toEqual(status);
});

it('Successfully marked all notifications as seen for selected app.', async () => {
axiosMock.onPut(markedAllNotificationsAsSeenApiUrl).reply(200);
await executeThunk(markNotificationsAsSeen('discussions'), store.dispatch, store.getState);

expect(store.getState().notifications.notificationStatus).toEqual('successful');
});

it.each([
{ statusCode: 404, status: 'failed' },
{ statusCode: 403, status: 'denied' },
])('%s to mark all notifications as seen for selected app.', async ({ statusCode, status }) => {
axiosMock.onPut(markedAllNotificationsAsSeenApiUrl).reply(statusCode);
await executeThunk(markNotificationsAsSeen('discussions'), store.dispatch, store.getState);

const { notifications: { notificationStatus } } = store.getState();

expect(notificationStatus).toEqual(status);
});

it('Successfully marked all notifications as read for selected app in the redux.', async () => {
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(200);
await executeThunk(markAllNotificationsAsRead('discussions'), store.dispatch, store.getState);
Expand All @@ -103,6 +139,18 @@ describe('Notification Redux', () => {
expect(firstNotification.lastRead).not.toBeNull();
});

it.each([
{ statusCode: 404, status: 'failed' },
{ statusCode: 403, status: 'denied' },
])('%s to mark all notifications as read for selected app in the redux.', async ({ statusCode, status }) => {
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(statusCode);
await executeThunk(markAllNotificationsAsRead('discussions'), store.dispatch, store.getState);

const { notifications: { notificationStatus } } = store.getState();

expect(notificationStatus).toEqual(status);
});

it('Successfully marked notification as read in the redux.', async () => {
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(200);
await executeThunk(markNotificationsAsRead(1), store.dispatch, store.getState);
Expand All @@ -113,4 +161,16 @@ describe('Notification Redux', () => {
expect(notificationStatus).toEqual('successful');
expect(firstNotification.lastRead).not.toBeNull();
});

it.each([
{ statusCode: 404, status: 'failed' },
{ statusCode: 403, status: 'denied' },
])('%s to marked notification as read in the redux.', async ({ statusCode, status }) => {
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(statusCode);
await executeThunk(markNotificationsAsRead(1), store.dispatch, store.getState);

const { notifications: { notificationStatus } } = store.getState();

expect(notificationStatus).toEqual(status);
});
});

0 comments on commit 8175ba8

Please sign in to comment.