Skip to content

Commit

Permalink
Require programId in validation, require startDate < endDate
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksTeresh committed May 16, 2024
1 parent b4e4b1c commit 2498076
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/server/validators/thesis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('validateThesisData', () => {
req = {
body: {
topic: 'Test thesis',
programId: 'test-program',
supervisions: [{ percentage: 100 }],
authors: [{}],
researchPlan: {},
Expand Down Expand Up @@ -165,4 +166,29 @@ describe('validateThesisData', () => {
)
expect(next).toHaveBeenCalledTimes(0)
})

it('should return an error if targetDate is before startDate', () => {
req.body = {
...req.body,
startDate: '2021-12-31',
targetDate: '2021-01-01',
}

expect(() => validateThesisData(req, res, next)).toThrow(
'Start date must be before target date'
)
expect(next).toHaveBeenCalledTimes(0)
})

it('should return an error if programId is missing', () => {
req.body = {
...req.body,
programId: undefined
}

expect(() => validateThesisData(req, res, next)).toThrow(
'Program is required'
)
expect(next).toHaveBeenCalledTimes(0)
})
})
8 changes: 8 additions & 0 deletions src/server/validators/thesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,13 @@ export const validateThesisData = (
throw new Error('Target date is required')
}

if (thesisData.startDate > thesisData.targetDate) {
throw new Error('Start date must be before target date')
}

if (!thesisData.programId) {
throw new Error('Program is required')
}

next()
}

0 comments on commit 2498076

Please sign in to comment.