Skip to content

Commit 911cea6

Browse files
Merge pull request #350 from openedx/sundas/INF-878
test: added redux, selector and api cases
2 parents cfda72b + a52ddfd commit 911cea6

10 files changed

Lines changed: 550 additions & 39 deletions

File tree

package-lock.json

Lines changed: 46 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@
6262
"@fortawesome/free-solid-svg-icons": "6.3.0",
6363
"@fortawesome/react-fontawesome": "^0.2.0",
6464
"@reduxjs/toolkit": "1.9.5",
65+
"axios-mock-adapter": "1.21.4",
6566
"babel-polyfill": "6.26.0",
6667
"classnames": "2.3.2",
6768
"lodash": "4.17.21",
6869
"react-redux": "7.2.9",
6970
"react-responsive": "8.2.0",
71+
"react-router-dom": "5.3.4",
7072
"react-transition-group": "4.4.5",
71-
"timeago.js": "4.0.2",
72-
"react-router-dom": "5.3.4"
73+
"rosie": "2.1.0",
74+
"timeago.js": "4.0.2"
7375
},
7476
"peerDependencies": {
7577
"@edx/frontend-platform": "^4.0.0",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './notifications.factory';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Factory } from 'rosie';
2+
3+
Factory.define('notificationsCount')
4+
.attr('count', 45)
5+
.attr('countByAppName', {
6+
reminders: 10,
7+
discussions: 20,
8+
grades: 10,
9+
authoring: 5,
10+
})
11+
.attr('showNotificationTray', true);
12+
13+
Factory.define('notification')
14+
.sequence('id')
15+
.attr('type', 'post')
16+
.sequence('content', ['id'], (idx, notificationId) => `<p><b>User ${idx}</b> posts <b>Hello and welcome to SC0x
17+
${notificationId}!</b></p>`)
18+
.attr('course_name', 'Supply Chain Analytics')
19+
.sequence('content_url', (idx) => `https://example.com/${idx}`)
20+
.attr('last_read', null)
21+
.attr('last_seen', null)
22+
.sequence('created_at', ['createdDate'], (idx, date) => date);

src/Notifications/data/api.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
import { camelCaseObject } from '@edx/frontend-platform';
2-
import notificationsList from './notifications.json';
1+
import { getConfig, snakeCaseObject } from '@edx/frontend-platform';
2+
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
3+
4+
export const getNotificationsCountApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/count/`;
5+
export const getNotificationsApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/`;
6+
export const markNotificationsSeenApiUrl = (appName) => `${getConfig().LMS_BASE_URL}/api/notifications/mark-notifications-unseen/${appName}/`;
7+
export const markNotificationAsReadApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/read/`;
38

49
export async function getNotifications(appName, page, pageSize) {
5-
const { data } = notificationsList;
10+
const params = snakeCaseObject({ page, pageSize });
11+
const { data } = await getAuthenticatedHttpClient().get(getNotificationsApiUrl(), { params });
12+
613
const startIndex = (page - 1) * pageSize;
714
const endIndex = startIndex + pageSize;
815

916
const notifications = data.slice(startIndex, endIndex);
10-
return { notifications: camelCaseObject(notifications), numPages: 2, currentPage: page };
17+
return { notifications, numPages: 2, currentPage: page };
1118
}
1219

1320
export async function getNotificationCounts() {
14-
const data = {
15-
count: 45,
16-
count_by_app_name: {
17-
reminders: 10,
18-
discussions: 20,
19-
grades: 10,
20-
authoring: 5,
21-
},
22-
show_notification_tray: false,
23-
};
24-
return camelCaseObject(data);
21+
const { data } = await getAuthenticatedHttpClient().get(getNotificationsCountApiUrl());
22+
23+
return data;
2524
}
2625

27-
export async function markNotificationSeen() {
28-
const data = [];
29-
return camelCaseObject(data);
26+
export async function markNotificationSeen(appName) {
27+
const { data } = await getAuthenticatedHttpClient().put(`${markNotificationsSeenApiUrl(appName)}`);
28+
29+
return data;
3030
}
3131

32-
export async function markAllNotificationRead() {
33-
const { data } = camelCaseObject(notificationsList);
32+
export async function markAllNotificationRead(appName) {
33+
const params = snakeCaseObject({ appName });
34+
const { data } = await getAuthenticatedHttpClient().put(markNotificationAsReadApiUrl(), { params });
35+
3436
return data;
3537
}
3638

3739
export async function markNotificationRead(notificationId) {
38-
const { data } = camelCaseObject(notificationsList);
40+
const params = snakeCaseObject({ notificationId });
41+
const { data } = await getAuthenticatedHttpClient().put(markNotificationAsReadApiUrl(), { params });
42+
3943
return { data, id: notificationId };
4044
}

0 commit comments

Comments
 (0)