Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alert validation #265

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/controllers/alertsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions server/validators/alertValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
},
])
Expand Down
4 changes: 2 additions & 2 deletions server/validators/alertValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export const AlertValidator: Validator = (body: Record<string, string>) => {
})
}

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',
})
}
Expand Down