Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect status showing on licence set up page #1363

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const ReturnVersionModel = require('../../models/return-version.model.js')
* @returns {Promise<object>} The new return version and requirement data for a licence
*/
async function go (sessionData, userId) {
const returnVersionsExist = sessionData.licence.returnVersions.length > 0
const nextVersionNumber = await _nextVersionNumber(sessionData.licence.id)

const returnVersion = await _generateReturnVersion(returnVersionsExist, sessionData, userId)
const returnVersion = await _generateReturnVersion(nextVersionNumber, sessionData, userId)
const returnRequirements = await _generateReturnRequirements(sessionData)

return {
Expand Down Expand Up @@ -56,12 +56,11 @@ async function _generateReturnRequirements (sessionData) {
return returnRequirements
}

async function _generateReturnVersion (returnVersionsExist, sessionData, userId) {
async function _generateReturnVersion (nextVersionNumber, sessionData, userId) {
const startDate = _calculateStartDate(sessionData)
let endDate = null

// If the journey is for 'no-returns-required' `returnVersionsExist` will always be false
if (returnVersionsExist || sessionData.journey === 'no-returns-required') {
if (nextVersionNumber > 1) {
endDate = await ProcessExistingReturnVersionsService.go(sessionData.licence.id, startDate)
}

Expand All @@ -74,7 +73,7 @@ async function _generateReturnVersion (returnVersionsExist, sessionData, userId)
reason: sessionData.reason,
startDate,
status: 'current',
version: await _nextVersionNumber(sessionData.licence.id)
version: nextVersionNumber
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('Generate Return Version service', () => {

expect(result.returnRequirements).to.equal([])
expect(result.returnVersion.createdBy).to.equal(userId)
expect(result.returnVersion.endDate).to.equal('2024-04-01T00:00:00.000Z')
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()
Expand All @@ -185,11 +185,5 @@ describe('Generate Return Version service', () => {
expect(result.returnVersion.status).to.equal('current')
expect(result.returnVersion.version).to.equal(1)
})

it('processes the existing return versions', async () => {
await GenerateReturnVersionService.go(sessionData, userId)

expect(ProcessExistingReturnVersionsService.go.called).to.be.true()
})
})
})
Loading