From e44e07839d0dbfe78bb64cca00901f7561f11d4b Mon Sep 17 00:00:00 2001 From: David Middleton Date: Wed, 30 Aug 2023 13:56:03 +0100 Subject: [PATCH] Fix alert validation --- server/controllers/alertsController.ts | 2 +- server/validators/alertValidator.test.ts | 4 ++-- server/validators/alertValidator.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/controllers/alertsController.ts b/server/controllers/alertsController.ts index 8bb8d318b..1e0e09c4c 100644 --- a/server/controllers/alertsController.ts +++ b/server/controllers/alertsController.ts @@ -94,7 +94,7 @@ export default class AlertsController { return res.render('pages/alerts/addAlert', { today: formatDate(now.toISOString(), 'short'), - todayMinus8: formatDate(subDays(now, 8).toISOString(), 'short'), + todayMinus8: formatDate(subDays(now, 7).toISOString(), 'short'), prisonerDisplayName, prisonerNumber, formValues, diff --git a/server/validators/alertValidator.test.ts b/server/validators/alertValidator.test.ts index d572797e3..426c80cef 100644 --- a/server/validators/alertValidator.test.ts +++ b/server/validators/alertValidator.test.ts @@ -68,7 +68,7 @@ describe('Validation middleware', () => { ]) }) - it('should fail validation with date more than 8 days in the past', async () => { + it('should fail validation with date more than 7 days in the past', async () => { const alertForm = { alertType: 'X', alertCode: 'X', @@ -80,7 +80,7 @@ describe('Validation middleware', () => { expect(result).toEqual([ { - text: 'Enter a date that is not more than 8 days in the past in the format DD/MM/YYYY - for example, 27/03/2020', + text: 'Enter a date that is not more than 7 days in the past in the format DD/MM/YYYY - for example, 27/03/2020', href: '#alertDate', }, ]) diff --git a/server/validators/alertValidator.ts b/server/validators/alertValidator.ts index f7a0169e8..de715ed08 100644 --- a/server/validators/alertValidator.ts +++ b/server/validators/alertValidator.ts @@ -64,9 +64,9 @@ export const AlertValidator: Validator = (body: Record) => { }) } - if (alertDate && differenceInDays(new Date(), parseDate(alertDate)) > 8) { + if (alertDate && differenceInDays(new Date(), parseDate(alertDate)) > 7) { errors.push({ - text: 'Enter a date that is not more than 8 days in the past in the format DD/MM/YYYY - for example, 27/03/2020', + text: 'Enter a date that is not more than 7 days in the past in the format DD/MM/YYYY - for example, 27/03/2020', href: '#alertDate', }) }