Skip to content

Commit

Permalink
express-current-user test updated date mock
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelDau committed May 9, 2024
1 parent c37cc24 commit ad39599
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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)
Expand All @@ -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()
})
})
})

0 comments on commit ad39599

Please sign in to comment.