forked from learningequality/kolibri
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix order in which notification updates are commited to state
Commit updates to state sorted by timestamp. Fixes learningequality#11302 where "Completed" update was commited before "Started" update.
- Loading branch information
Showing
2 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
kolibri/plugins/coach/assets/src/modules/classSummary/__test__/actions.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { NotificationObjects } from '../../../constants/notificationsConstants'; | ||
import { updateWithNotifications } from '../actions'; | ||
|
||
const { QUIZ } = NotificationObjects; | ||
|
||
describe('classSummary/actions', () => { | ||
describe('updateWithNotifications', () => { | ||
it('commits quiz notifications updates in a correct order (sorted by their datetime)', () => { | ||
const state = { | ||
learnerMap: { 'user-id': {} }, | ||
examMap: { 'quiz-id': {} }, | ||
contentNodeMap: {}, | ||
lessonMap: {}, | ||
}; | ||
const commit = jest.fn(); | ||
const dispatch = jest.fn(); | ||
|
||
const quizNotifications = [ | ||
{ | ||
id: 1, | ||
user_id: 'user-id', | ||
object: QUIZ, | ||
event: 'Completed', | ||
timestamp: '2023-10-05T13:35:00+02:00', | ||
quiz_num_correct: 1, | ||
quiz_num_answered: 2, | ||
quiz_id: 'quiz-id', | ||
}, | ||
{ | ||
id: 2, | ||
user_id: 'user-id', | ||
object: QUIZ, | ||
event: 'Started', | ||
timestamp: '2023-10-05T13:30:00+02:00', | ||
quiz_num_correct: 2, | ||
quiz_num_answered: 3, | ||
quiz_id: 'quiz-id', | ||
}, | ||
]; | ||
|
||
updateWithNotifications({ state, commit, dispatch }, quizNotifications); | ||
|
||
expect(commit).toHaveBeenCalledTimes(1); | ||
expect(commit.mock.calls[0][0]).toBe('APPLY_NOTIFICATION_UPDATES'); | ||
expect(commit.mock.calls[0][1].examLearnerStatusMapUpdates).toEqual([ | ||
{ | ||
learner_id: 'user-id', | ||
status: 'Started', | ||
last_activity: new Date('2023-10-05T11:30:00.000Z'), | ||
num_correct: 2, | ||
num_answered: 3, | ||
exam_id: 'quiz-id', | ||
}, | ||
{ | ||
learner_id: 'user-id', | ||
status: 'Completed', | ||
last_activity: new Date('2023-10-05T11:35:00.000Z'), | ||
num_correct: 1, | ||
num_answered: 2, | ||
exam_id: 'quiz-id', | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters