Skip to content

Commit

Permalink
Persist a new return version for 'no returns required' (#1213)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4619

Having completed the return requirements setup journey (no-returns-required), we need to persist a return version (start date, reason and notes) to the database. There will be no return requirements in this scenario.

When "Approve" is clicked in the `/check` page the data in the session needs to be persisted to the `water.return_versions` table.
  • Loading branch information
Jozzey authored Jul 31, 2024
1 parent 2f631c3 commit 35816f6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})

0 comments on commit 35816f6

Please sign in to comment.