Skip to content

Commit

Permalink
Do not send reminders for skipped weeks
Browse files Browse the repository at this point in the history
  • Loading branch information
JHWelch committed Mar 19, 2024
1 parent cd96061 commit 04e186f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions server/__tests__/controllers/cronController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FirebaseMock } from '../support/firebaseMock'
import { transaction } from '../../__mocks__/firebase/firestore'
import { TMDB_POSTER_URL } from '../../src/data/tmdb/constants'
import Config from '../../src/config/config'
import { getDocs } from 'firebase/firestore'

const { res, mockClear } = getMockRes()

Expand Down Expand Up @@ -138,4 +139,38 @@ describe('reminders', () => {
})
})
})

describe('there is no event tomorrow', () => {
beforeEach(() => {
FirebaseMock.mockGetWeek()
})

it('should return 200', async () => {
await new CronController(config, firestore).reminders(getMockReq(), res)

expect(res.status).toHaveBeenCalledWith(200)
expect(res.send).toHaveBeenCalledWith('ok')
expect(getDocs).not.toHaveBeenCalled()
})
})

describe('the event is skipped', () => {
beforeEach(() => {
FirebaseMock.mockGetWeek({
id: 'week-id1',
theme: 'theme1',
date: new Date('2021-01-01'),
slug: null,
isSkipped: true,
})
})

it('should return 200', async () => {
await new CronController(config, firestore).reminders(getMockReq(), res)

expect(res.status).toHaveBeenCalledWith(200)
expect(res.send).toHaveBeenCalledWith('ok')
expect(getDocs).not.toHaveBeenCalled()
})
})
})
2 changes: 1 addition & 1 deletion server/src/controllers/cronController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CronController {
reminders = async (_req: Request, res: Response): Promise<void> => {
const week = await this.firestore.getWeek(tomorrow())

if (!week) {
if (!week || week.isSkipped) {
res.status(200).send('ok')

return
Expand Down

0 comments on commit 04e186f

Please sign in to comment.