diff --git a/src/server/validators/thesis.test.js b/src/server/validators/thesis.test.js index ed492a2..4b86f1a 100644 --- a/src/server/validators/thesis.test.js +++ b/src/server/validators/thesis.test.js @@ -9,6 +9,7 @@ describe('validateThesisData', () => { req = { body: { topic: 'Test thesis', + programId: 'test-program', supervisions: [{ percentage: 100 }], authors: [{}], researchPlan: {}, @@ -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) + }) }) diff --git a/src/server/validators/thesis.ts b/src/server/validators/thesis.ts index 94790e4..e78f01d 100644 --- a/src/server/validators/thesis.ts +++ b/src/server/validators/thesis.ts @@ -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() }