Skip to content

Commit

Permalink
Merge branch 'service_rewrite_2023' into diaryServices-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
the-bay-kay committed Jan 23, 2024
2 parents 1fb7c95 + 3cbb5f0 commit e69138b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 11 additions & 6 deletions www/__tests__/notifScheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ describe('updateScheduledNotifs', () => {
const scheduledPromise: Promise<any> = Promise.resolve();
// create an empty array of mock notifs from cordova plugin
let mockNotifs = [];
// create the expected result
const expectedResultcheduleNotifs = [
{ key: 'November 19, 2023', val: '9:00 PM' },
{ key: 'November 17, 2023', val: '9:00 PM' },
{ key: 'November 15, 2023', val: '9:00 PM' },
{ key: 'November 14, 2023', val: '9:00 PM' },
];

// mock the cordova plugin
jest
Expand All @@ -267,13 +274,11 @@ describe('updateScheduledNotifs', () => {
await updateScheduledNotifs(reminderSchemes, isScheduling, setIsScheduling, scheduledPromise);
const scheduledNotifs = await getScheduledNotifs(isScheduling, scheduledPromise);

expect(setIsScheduling).toHaveBeenCalledWith(true);
expect(logDebug).toHaveBeenCalledWith('After cancelling, there are no scheduled notifications');
expect(logDebug).toHaveBeenCalledWith(
'After scheduling, there are 4 scheduled notifications at 21:00 first is November 19, 2023 at 9:00 PM',
);
expect(setIsScheduling).toHaveBeenCalledWith(false);
expect(scheduledNotifs).toHaveLength(4);
expect(scheduledNotifs[0].key).toEqual(expectedResultcheduleNotifs[0].key);
expect(scheduledNotifs[1].key).toEqual(expectedResultcheduleNotifs[1].key);
expect(scheduledNotifs[2].key).toEqual(expectedResultcheduleNotifs[2].key);
expect(scheduledNotifs[3].key).toEqual(expectedResultcheduleNotifs[3].key);
});

it('should resolve without scheduling if notifications are already scheduled', async () => {
Expand Down
6 changes: 6 additions & 0 deletions www/js/splash/notifScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,20 @@ export const getScheduledNotifs = function (isScheduling: boolean, scheduledProm
anywhere from 0-n of the scheduled notifs are displayed
if actively scheduling, wait for the scheduledPromise to resolve before fetching prevents such errors
*/
console.log('test log: isScheduling during getScheduledNotifs', isScheduling);
console.log('test log: scheduledPromise during getScheduledNotifs', scheduledPromise);
if (isScheduling) {
console.log(
'test log: requesting fetch while still actively scheduling, waiting on scheduledPromise',
);
logDebug('requesting fetch while still actively scheduling, waiting on scheduledPromise');
scheduledPromise.then(() => {
getNotifs().then((notifs: object[]) => {
resolve(notifs);
});
});
} else {
console.log('test log: not actively scheduling, fetching');
getNotifs().then((notifs: object[]) => {
resolve(notifs);
});
Expand Down

0 comments on commit e69138b

Please sign in to comment.