diff --git a/app/services/return-requirements/generate-return-version.service.js b/app/services/return-requirements/generate-return-version.service.js index 55c82da5b3..97e4bf495d 100644 --- a/app/services/return-requirements/generate-return-version.service.js +++ b/app/services/return-requirements/generate-return-version.service.js @@ -21,7 +21,7 @@ const ReturnVersionModel = require('../../models/return-version.model.js') */ async function go (sessionData, userId) { const returnVersion = await _generateReturnVersion(sessionData, userId) - const returnRequirements = await GenerateReturnVersionRequirementsService.go(sessionData.licence.id, sessionData.requirements) + const returnRequirements = await _generateReturnRequirements(sessionData) return { returnRequirements, @@ -39,6 +39,20 @@ function _calculateStartDate (sessionData) { return sessionData.licence.currentVersionStartDate } +async function _generateReturnRequirements (sessionData) { + // When no returns are required a return version is created without any return requirements + if (sessionData.journey === 'no-returns-required') { + return [] + } + + const returnRequirements = await GenerateReturnVersionRequirementsService.go( + sessionData.licence.id, + sessionData.requirements + ) + + return returnRequirements +} + async function _generateReturnVersion (sessionData, userId) { return { createdBy: userId, diff --git a/test/services/return-requirements/generate-return-version.service.test.js b/test/services/return-requirements/generate-return-version.service.test.js index 626abcafe6..186a3544f3 100644 --- a/test/services/return-requirements/generate-return-version.service.test.js +++ b/test/services/return-requirements/generate-return-version.service.test.js @@ -136,4 +136,42 @@ describe('Generate Return Version service', () => { expect(result.returnVersion.version).to.equal(1) }) }) + + describe('when called with session data from the "no-returns-required" journey', () => { + beforeEach(async () => { + licenceId = generateUUID() + + sessionData = { + reason: 'returns-exception', + journey: 'no-returns-required', + licence: { + id: licenceId, + endDate: null, + startDate: '2023-02-13T00:00:00.000Z', + licenceRef: '99/99/9999', + licenceHolder: 'A licence holder', + returnVersions: [], + currentVersionStartDate: '2023-02-13T00:00:00.000Z' + }, + requirements: [{}], + checkPageVisited: true, + startDateOptions: 'licenceStartDate' + } + }) + + it('generates the data required to populate a record in the "return_version" table', async () => { + const result = await GenerateReturnVersionService.go(sessionData, userId) + + expect(result.returnRequirements).to.equal([]) + expect(result.returnVersion.createdBy).to.equal(userId) + expect(result.returnVersion.endDate).to.be.null() + expect(result.returnVersion.licenceId).to.equal(licenceId) + 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(sessionData.licence.currentVersionStartDate) + expect(result.returnVersion.status).to.equal('current') + expect(result.returnVersion.version).to.equal(1) + }) + }) })