diff --git a/app/services/return-versions/setup/submit-start-date.service.js b/app/services/return-versions/setup/submit-start-date.service.js index f40bae32c7..7b6d8bd10e 100644 --- a/app/services/return-versions/setup/submit-start-date.service.js +++ b/app/services/return-versions/setup/submit-start-date.service.js @@ -65,11 +65,9 @@ async function _save (session, payload) { session.startDateDay = payload['start-date-day'] session.startDateMonth = payload['start-date-month'] session.startDateYear = payload['start-date-year'] - // Reminder! Because of the unique qualities of Javascript, Year and Day are literal values, month is an index! So, - // January is actually 0, February is 1 etc. This is why we deduct 1 from the month. - session.returnVersionStartDate = new Date(`${payload['start-date-year']}-${payload['start-date-month'] - 1}-${payload['start-date-day']}`).toISOString().split('T')[0] + session.returnVersionStartDate = new Date(`${payload['start-date-year']}-${payload['start-date-month']}-${payload['start-date-day']}`) } else { - session.returnVersionStartDate = new Date(session.licence.currentVersionStartDate).toISOString().split('T')[0] + session.returnVersionStartDate = new Date(session.licence.currentVersionStartDate) } return session.$update() diff --git a/test/services/return-versions/setup/check/generate-return-version.service.test.js b/test/services/return-versions/setup/check/generate-return-version.service.test.js index b5c0571312..7270bb0a07 100644 --- a/test/services/return-versions/setup/check/generate-return-version.service.test.js +++ b/test/services/return-versions/setup/check/generate-return-version.service.test.js @@ -61,7 +61,7 @@ describe('Return Versions Setup - Generate Return Version service', () => { ], currentVersionStartDate: '2023-02-13T00:00:00.000Z' }, - returnVersionStartDate: '2023-02-13', + returnVersionStartDate: '2023-02-13T00:00:00.000Z', requirements: ['return requirements data'], checkPageVisited: true, startDateOptions: 'licenceStartDate' @@ -81,7 +81,7 @@ describe('Return Versions Setup - Generate Return Version service', () => { expect(result.returnVersion.multipleUpload).to.be.false() expect(result.returnVersion.notes).to.be.undefined() expect(result.returnVersion.reason).to.equal(sessionData.reason) - expect(result.returnVersion.startDate).to.equal(new Date('2023-02-13 ')) + expect(result.returnVersion.startDate).to.equal(new Date('2023-02-13')) expect(result.returnVersion.status).to.equal('current') // Version number is 103 because this is the next version number after the previous version expect(result.returnVersion.version).to.equal(103) @@ -134,7 +134,7 @@ describe('Return Versions Setup - Generate Return Version service', () => { expect(result.returnVersion.multipleUpload).to.be.true() expect(result.returnVersion.notes).to.equal(sessionData.note.content) expect(result.returnVersion.reason).to.equal(sessionData.reason) - expect(result.returnVersion.startDate).to.equal(new Date('2023-02-13 ')) + expect(result.returnVersion.startDate).to.equal(new Date('2023-02-13')) expect(result.returnVersion.status).to.equal('current') // Version number is 1 because no previous return versions exist expect(result.returnVersion.version).to.equal(1) @@ -179,7 +179,7 @@ describe('Return Versions Setup - Generate Return Version service', () => { expect(result.returnVersion.multipleUpload).to.be.false() expect(result.returnVersion.notes).to.be.undefined() expect(result.returnVersion.reason).to.equal(sessionData.reason) - expect(result.returnVersion.startDate).to.equal(new Date('2023-02-13 ')) + expect(result.returnVersion.startDate).to.equal(new Date('2023-02-13')) expect(result.returnVersion.status).to.equal('current') expect(result.returnVersion.version).to.equal(1) }) diff --git a/test/services/return-versions/setup/submit-start-date.service.test.js b/test/services/return-versions/setup/submit-start-date.service.test.js index f36d1d66d9..58ad233bd8 100644 --- a/test/services/return-versions/setup/submit-start-date.service.test.js +++ b/test/services/return-versions/setup/submit-start-date.service.test.js @@ -64,6 +64,7 @@ describe('Return Versions Setup - Submit Start Date service', () => { const refreshedSession = await session.$query() expect(refreshedSession.startDateOptions).to.equal('licenceStartDate') + expect(new Date(refreshedSession.returnVersionStartDate)).to.equal(new Date('2023-01-01')) }) describe('and the page has been not been visited', () => { @@ -118,7 +119,7 @@ describe('Return Versions Setup - Submit Start Date service', () => { expect(refreshedSession.startDateDay).to.equal('26') expect(refreshedSession.startDateMonth).to.equal('11') expect(refreshedSession.startDateYear).to.equal('2023') - expect(refreshedSession.returnVersionStartDate).to.equal('2023-10-26') + expect(new Date(refreshedSession.returnVersionStartDate)).to.equal(new Date('2023-11-26')) }) it('returns the correct details the controller needs to redirect the journey', async () => {