From ad3959946be0ff16f2232c099b32670e59d1aad6 Mon Sep 17 00:00:00 2001 From: Rachel Dauns Date: Thu, 9 May 2024 10:21:32 -0400 Subject: [PATCH] express-current-user test updated date mock --- .../__tests__/express_current_user.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/app/obojobo-express/__tests__/express_current_user.test.js b/packages/app/obojobo-express/__tests__/express_current_user.test.js index 0f1fcca2c..30caf390f 100644 --- a/packages/app/obojobo-express/__tests__/express_current_user.test.js +++ b/packages/app/obojobo-express/__tests__/express_current_user.test.js @@ -234,6 +234,8 @@ describe('current user middleware', () => { req.currentUserId = mockUser.id req.currentUser = mockUser req.currentUser.lastLogin = mockUser.lastLogin + jest.useFakeTimers('modern') + jest.setSystemTime(new Date(2024, 3, 1)) //mock the date so that runtime does not affect the date/time const mockNotifications = [ { id: 1, title: 'Notification 1', text: 'Message 1' }, @@ -263,6 +265,8 @@ describe('current user middleware', () => { ) expect(req.currentUser.lastLogin).toStrictEqual(today) expect(viewerNotificationState.setLastLogin).toHaveBeenCalledWith(8, today) + + jest.useRealTimers() }) }) test('getNotifications returns empty when there are no notifications', async () => { @@ -274,6 +278,8 @@ describe('current user middleware', () => { req.currentUserId = mockUser.id req.currentUser = mockUser req.currentUser.lastLogin = mockUser.lastLogin + jest.useFakeTimers('modern') + jest.setSystemTime(new Date(2024, 3, 1)) //mock the date so that runtime does not affect the date/time viewerState.get.mockResolvedValueOnce(req.currentUserId) viewerNotificationState.getRecentNotifications.mockResolvedValueOnce(null) @@ -286,6 +292,8 @@ describe('current user middleware', () => { expect(res.cookie).not.toHaveBeenCalled() expect(req.currentUser.lastLogin).toStrictEqual(today) expect(viewerNotificationState.setLastLogin).toHaveBeenCalledWith(8, today) + + jest.useRealTimers() }) }) })