Skip to content

Commit

Permalink
Add simple setReminderPrefs test
Browse files Browse the repository at this point in the history
- Tests to see if setReminderPrefs works when called in the way that ProfileSettings.jsx calls it
  • Loading branch information
sebastianbarry committed Dec 12, 2023
1 parent 5ee4d64 commit d3750c3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions www/__tests__/notifScheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,53 @@ describe('getReminderPrefs', () => {
expect(reminder_time_of_day).toEqual(expectedResult.reminder_time_of_day);
});
});

describe('setReminderPrefs', () => {
afterEach(() => {
jest.restoreAllMocks(); // Restore mocked functions after each test
});

beforeEach(() => {
// mock the getUser function
mockGetUser.mockImplementation(() =>
Promise.resolve({
// These values are **important**...
// reminder_assignment: must match a key from the reminder scheme above,
// reminder_join_date: must match the first day of the mocked notifs below in the tests,
// reminder_time_of_day: must match the defaultTime from the chosen reminder_assignment in the reminder scheme above
reminder_assignment: 'weekly',
reminder_join_date: '2023-11-14',
reminder_time_of_day: '21:00',
}),
);
});

it('should resolve with promise that calls updateScheduledNotifs', async () => {
// setReminderPrefs arguments
const newPrefs: any = {
reminder_time_of_day: '21:00',
};
const reminderSchemes: any = exampleReminderSchemes;
let isScheduling: boolean = true;
const setIsScheduling: Function = jest.fn((val: boolean) => (isScheduling = val));
const scheduledPromise: Promise<any> = Promise.resolve();

// mock the updateUser function
mockUpdateUser.mockImplementation(() => Promise.resolve());

// call the function
setReminderPrefs(
newPrefs,
reminderSchemes,
isScheduling,
setIsScheduling,
scheduledPromise,
).then(() => {
// in the implementation in ProfileSettings.jsx,
// refresNotificationSettings();
// would be called next
});

expect(logDebug).toBeCalledWith('Added reminder prefs to client stats');
});
});

0 comments on commit d3750c3

Please sign in to comment.