Skip to content

Commit

Permalink
refactor: changed api url
Browse files Browse the repository at this point in the history
  • Loading branch information
SundasNoreen committed Jun 19, 2023
1 parent 8175ba8 commit a52ddfd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/Notifications/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
export const getNotificationsCountApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/count/`;
export const getNotificationsApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/`;
export const markNotificationsSeenApiUrl = (appName) => `${getConfig().LMS_BASE_URL}/api/notifications/mark-notifications-unseen/${appName}/`;
export const markAllNotificationsAsReadpiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/read/`;
export const markNotificationAsReadApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/read/`;

export async function getNotifications(appName, page, pageSize) {
const params = snakeCaseObject({ page, pageSize });
Expand All @@ -31,14 +31,14 @@ export async function markNotificationSeen(appName) {

export async function markAllNotificationRead(appName) {
const params = snakeCaseObject({ appName });
const { data } = await getAuthenticatedHttpClient().put(markAllNotificationsAsReadpiUrl(), { params });
const { data } = await getAuthenticatedHttpClient().put(markNotificationAsReadApiUrl(), { params });

return data;
}

export async function markNotificationRead(notificationId) {
const params = snakeCaseObject({ notificationId });
const { data } = await getAuthenticatedHttpClient().put(markAllNotificationsAsReadpiUrl(), { params });
const { data } = await getAuthenticatedHttpClient().put(markNotificationAsReadApiUrl(), { params });

return { data, id: notificationId };
}
4 changes: 2 additions & 2 deletions src/Notifications/data/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { initializeMockApp } from '@edx/frontend-platform/testing';

import {
getNotificationsApiUrl, getNotificationsCountApiUrl, markAllNotificationsAsReadpiUrl, markNotificationsSeenApiUrl,
getNotificationsApiUrl, getNotificationsCountApiUrl, markNotificationAsReadApiUrl, markNotificationsSeenApiUrl,
getNotificationCounts, getNotifications, markNotificationSeen, markAllNotificationRead, markNotificationRead,
} from './api';

Expand All @@ -14,7 +14,7 @@ import './__factories__';
const notificationCountsApiUrl = getNotificationsCountApiUrl();
const notificationsApiUrl = getNotificationsApiUrl();
const markedAllNotificationsAsSeenApiUrl = markNotificationsSeenApiUrl('discussions');
const markedAllNotificationsAsReadApiUrl = markAllNotificationsAsReadpiUrl();
const markedAllNotificationsAsReadApiUrl = markNotificationAsReadApiUrl();

let axiosMock = null;

Expand Down
16 changes: 2 additions & 14 deletions src/Notifications/data/redux.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initializeMockApp } from '@edx/frontend-platform/testing';
import { initializeStore } from '../../store';
import executeThunk from '../../test-utils';
import {
getNotificationsApiUrl, getNotificationsCountApiUrl, markAllNotificationsAsReadpiUrl, markNotificationsSeenApiUrl,
getNotificationsApiUrl, getNotificationsCountApiUrl, markNotificationAsReadApiUrl, markNotificationsSeenApiUrl,
} from './api';
import {
fetchAppsNotificationCount, fetchNotificationList, markNotificationsAsRead, markAllNotificationsAsRead,
Expand All @@ -18,7 +18,7 @@ import './__factories__';

const notificationCountsApiUrl = getNotificationsCountApiUrl();
const notificationsApiUrl = getNotificationsApiUrl();
const markedAllNotificationsAsReadApiUrl = markAllNotificationsAsReadpiUrl();
const markedAllNotificationsAsReadApiUrl = markNotificationAsReadApiUrl();
const markedAllNotificationsAsSeenApiUrl = markNotificationsSeenApiUrl('discussions');

let axiosMock;
Expand Down Expand Up @@ -139,18 +139,6 @@ 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 Down

0 comments on commit a52ddfd

Please sign in to comment.