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

Add default for multiple upload on return version journey #1465

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -13,16 +13,16 @@
* @returns {object} - The data formatted for the view template
*/
function go (session) {
const { id: sessionId, licence: { id: licenceId, licenceRef }, additionalSubmissionOptions } = session
const data = {
additionalSubmissionOptions: additionalSubmissionOptions ?? [],
const { id: sessionId, licence: { id: licenceId, licenceRef }, multipleUpload, noAdditionalOptions } = session

return {
multipleUpload,
noAdditionalOptions,
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
backLink: `/system/return-versions/setup/${sessionId}/check`,
licenceId,
licenceRef,
sessionId
}

return data
}

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/return-versions/setup/check/check.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const { returnRequirementReasons } = require('../../../../lib/static-lookups.lib
* @returns {object} The data formatted for the view template
*/
function go (session) {
const { additionalSubmissionOptions, id: sessionId, journey, licence, note, reason } = session
const { multipleUpload, id: sessionId, journey, licence, note, reason } = session

const returnsRequired = journey === 'returns-required'

return {
additionalSubmissionOptions: additionalSubmissionOptions ?? [],
multipleUpload,
licenceRef: licence.licenceRef,
note: _note(note),
pageTitle: `Check the requirements for returns for ${licence.licenceHolder}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function _generateReturnVersion (nextVersionNumber, sessionData, userId) {
createdBy: userId,
endDate,
licenceId: sessionData.licence.id,
multipleUpload: _multipleUpload(sessionData?.additionalSubmissionOptions),
multipleUpload: sessionData.multipleUpload,
notes: sessionData?.note?.content,
reason: sessionData.reason,
startDate,
Expand All @@ -80,10 +80,6 @@ async function _nextVersionNumber (licenceId) {
return 1
}

function _multipleUpload (additionalSubmissionOptions) {
return additionalSubmissionOptions ? additionalSubmissionOptions.includes('multiple-upload') : false
}

module.exports = {
go
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function _createSession (data) {
}

function _data (licence, journey) {
const { id, licenceRef, licenceVersions, returnVersions, startDate } = licence
const { id, licenceRef, licenceVersions, returnVersions, startDate, waterUndertaker } = licence
const ends = licence.$ends()

return {
Expand All @@ -57,8 +57,10 @@ function _data (licence, journey) {
licenceRef,
licenceHolder: licence.$licenceHolder(),
returnVersions,
startDate
startDate,
waterUndertaker
},
multipleUpload: waterUndertaker,
journey,
requirements: [{}]
}
Expand All @@ -73,7 +75,8 @@ async function _fetchLicence (licenceId) {
'lapsedDate',
'licenceRef',
'revokedDate',
'startDate'
'startDate',
'waterUndertaker'
])
.withGraphFetched('licenceVersions')
.modifyGraph('licenceVersions', (builder) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ function _notification (session, payload) {
}

async function _save (session, payload) {
session.additionalSubmissionOptions = payload.additionalSubmissionOptions
session.multipleUpload = payload.additionalSubmissionOptions.includes('multiple-upload')

session.noAdditionalOptions = payload.additionalSubmissionOptions.includes('none')

return session.$update()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
{
value: "multiple-upload",
text: "Multiple upload",
checked: additionalSubmissionOptions.includes("multiple-upload")
checked: multipleUpload
},
{
divider: "or"
},
{
value: "none",
text: "None",
checked: additionalSubmissionOptions.includes("none"),
checked: noAdditionalOptions,
behaviour: "exclusive"
}
]
Expand Down
2 changes: 1 addition & 1 deletion app/views/return-versions/setup/check.njk
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
classes: "govuk-body "
},
value: {
text: 'Yes' if additionalSubmissionOptions.includes('multiple-upload') else "No"
text: 'Yes' if multipleUpload else "No"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ describe('Return Versions Setup - Additional Submission Options presenter', () =
expect(result).to.be.equal({
backLink: `/system/return-versions/setup/${session.id}/check`,
licenceId: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
additionalSubmissionOptions: [],
multipleUpload: undefined,
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
noAdditionalOptions: undefined,
licenceRef: '01/ABC',
sessionId: session.id
})
Expand All @@ -54,24 +55,70 @@ describe('Return Versions Setup - Additional Submission Options presenter', () =
})
})

describe('the "additionalSubmissionOptions" property', () => {
describe('when the user has previously submitted additional submission options', () => {
describe('the "multipleUpload" property', () => {
describe('when a user has selected "multipleUpload" for additional options', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to have dropped the word 'previously' from these tests. It was there to try and highlight where a user has previously visited this page and submitted an option, then we expect the presenter to replay it.

Happy to change it to something else if it's not making that clear. But I think just dropping it makes it unclear we are talking about selections a user previously made, instead of ones they have just made.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated to reflect the previous state setting and the default being set.

beforeEach(() => {
session.additionalSubmissionOptions = ['multiple-upload']
session.multipleUpload = true
})

it('returns the options', () => {
it('returns true', () => {
const result = AdditionalSubmissionOptionsPresenter.go(session)

expect(result.additionalSubmissionOptions).to.include('multiple-upload')
expect(result.multipleUpload).to.be.true()
})
})

describe('when the user has not previously chosen options', () => {
it('returns empty options', () => {
describe('when a user has not selected "multipleUpload" for additional options', () => {
beforeEach(() => {
session.multipleUpload = false
})

it('returns false', () => {
const result = AdditionalSubmissionOptionsPresenter.go(session)

expect(result.multipleUpload).to.be.false()
})
})

describe('when it has not been set', () => {
it('returns false', () => {
const result = AdditionalSubmissionOptionsPresenter.go(session)

expect(result.multipleUpload).to.be.undefined()
})
})
})

describe('the "noAdditionalOptions" property', () => {
describe('when a user has selected "none" for additional options', () => {
beforeEach(() => {
session.noAdditionalOptions = true
})

it('returns true', () => {
const result = AdditionalSubmissionOptionsPresenter.go(session)

expect(result.noAdditionalOptions).to.be.true()
})
})

describe('when a user not has selected "none" for additional options', () => {
beforeEach(() => {
session.noAdditionalOptions = false
})

it('returns false', () => {
const result = AdditionalSubmissionOptionsPresenter.go(session)

expect(result.noAdditionalOptions).to.be.false()
})
})

describe('when it has not been set', () => {
it('returns false', () => {
const result = AdditionalSubmissionOptionsPresenter.go(session)

expect(result.additionalSubmissionOptions).to.be.empty()
expect(result.multipleUpload).to.be.undefined()
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('Return Versions Setup - Check presenter', () => {
licenceHolder: 'Turbo Kid',
startDate: '2022-04-01T00:00:00.000Z'
},
multipleUpload: false,
returnVersionStartDate: '2023-01-01',
startDateOptions: 'licenceStartDate',
reason: 'major-change'
Expand All @@ -37,8 +38,8 @@ describe('Return Versions Setup - Check presenter', () => {
const result = CheckPresenter.go(session)

expect(result).to.equal({
additionalSubmissionOptions: [],
licenceRef: '01/ABC',
multipleUpload: false,
note: {
actions: [
{
Expand All @@ -57,24 +58,24 @@ describe('Return Versions Setup - Check presenter', () => {
})
})

describe('the "additionalSubmissionOptions" property', () => {
describe('when the user has checked additionalSubmissionOptions', () => {
describe('the "multipleUpload" property', () => {
describe('when there is a multipleUpload', () => {
beforeEach(() => {
session.additionalSubmissionOptions = ['multiple-upload']
session.multipleUpload = true
})

it('returns a checked option', () => {
it('returns the value', () => {
const result = CheckPresenter.go(session)

expect(result.additionalSubmissionOptions).to.include('multiple-upload')
expect(result.multipleUpload).to.be.true()
})
})

describe('when the user has not checked an option', () => {
it('returns no options', () => {
describe('when there is not a multipleUpload', () => {
it('returns the value', () => {
const result = CheckPresenter.go(session)

expect(result.additionalSubmissionOptions).to.be.empty()
expect(result.multipleUpload).to.be.false()
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('Return Versions Setup - Additional Submission Options service', () =>
licenceHolder: 'Turbo Kid',
startDate: '2022-04-01T00:00:00.000Z'
},
multipleUpload: false,
noAdditionalOptions: undefined,
journey: 'returns-required',
requirements: [{}],
startDateOptions: 'licenceStartDate',
Expand All @@ -47,8 +49,9 @@ describe('Return Versions Setup - Additional Submission Options service', () =>
const result = await AdditionalSubmissionOptionsService.go(session.id)

expect(result).to.equal({
multipleUpload: false,
noAdditionalOptions: undefined,
activeNavBar: 'search',
additionalSubmissionOptions: [],
backLink: `/system/return-versions/setup/${session.id}/check`,
licenceId: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
licenceRef: '01/ABC',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Return Versions Setup - Check service', () => {
licenceHolder: 'Turbo Kid',
startDate: '2022-04-01T00:00:00.000Z'
},
multipleUpload: false,
returnVersionStartDate: '2023-01-01',
journey: 'returns-required',
requirements: [{}],
Expand Down Expand Up @@ -60,8 +61,8 @@ describe('Return Versions Setup - Check service', () => {

expect(result).to.equal({
activeNavBar: 'search',
additionalSubmissionOptions: [],
licenceRef: '01/ABC',
multipleUpload: false,
note: {
actions: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ describe('Return Versions Setup - Generate Return Version service', () => {
beforeEach(async () => {
licenceId = generateUUID()
sessionData = {
method: 'use-existing-requirements',
reason: 'minor-change',
checkPageVisited: true,
journey: 'returns-required',
licence: {
id: licenceId,
Expand All @@ -61,9 +60,11 @@ describe('Return Versions Setup - Generate Return Version service', () => {
],
currentVersionStartDate: '2023-02-13T00:00:00.000Z'
},
returnVersionStartDate: '2023-02-13',
method: 'use-existing-requirements',
multipleUpload: false,
reason: 'minor-change',
requirements: ['return requirements data'],
checkPageVisited: true,
returnVersionStartDate: '2023-02-13',
startDateOptions: 'licenceStartDate'
}

Expand Down Expand Up @@ -99,12 +100,7 @@ describe('Return Versions Setup - Generate Return Version service', () => {
beforeEach(async () => {
licenceId = generateUUID()
sessionData = {
note: {
content: 'This is a test note',
userEmail: '[email protected]'
},
method: 'set-up-manually',
reason: 'change-to-special-agreement',
checkPageVisited: true,
journey: 'returns-required',
licence: {
id: licenceId,
Expand All @@ -114,13 +110,16 @@ describe('Return Versions Setup - Generate Return Version service', () => {
licenceHolder: 'Another licence holder',
returnVersions: []
},
method: 'set-up-manually',
multipleUpload: true,
note: {
content: 'This is a test note',
userEmail: '[email protected]'
},
reason: 'change-to-special-agreement',
requirements: ['return requirements data'],
returnVersionStartDate: '2023-02-13',
checkPageVisited: true,
startDateOptions: 'anotherStartDate',
additionalSubmissionOptions: [
'multiple-upload'
]
startDateOptions: 'anotherStartDate'
}
})

Expand Down Expand Up @@ -151,7 +150,7 @@ describe('Return Versions Setup - Generate Return Version service', () => {
beforeEach(async () => {
licenceId = generateUUID()
sessionData = {
reason: 'returns-exception',
checkPageVisited: true,
journey: 'no-returns-required',
licence: {
id: licenceId,
Expand All @@ -162,9 +161,10 @@ describe('Return Versions Setup - Generate Return Version service', () => {
returnVersions: [],
currentVersionStartDate: '2023-02-13T00:00:00.000Z'
},
returnVersionStartDate: '2023-02-13',
multipleUpload: false,
reason: 'returns-exception',
requirements: [{}],
checkPageVisited: true,
returnVersionStartDate: '2023-02-13',
startDateOptions: 'licenceStartDate'
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ describe('Return Versions Setup - Initiate Session service', () => {
licenceRef,
licenceHolder: 'Licence Holder Ltd',
returnVersions: [],
startDate: new Date('2022-01-01')
startDate: new Date('2022-01-01'),
waterUndertaker: false
},
multipleUpload: false,
journey: 'returns-required',
requirements: [{}]
}, { skip: ['id'] })
Expand Down
Loading
Loading