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 controls & validation for Rtn req setup page #758

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9e56f9f
feat(app): WATER-4267 Added setup page
Demwunz Feb 14, 2024
dcaac33
fix(app): added missing stub to test
Demwunz Feb 15, 2024
cd8647b
Merge remote-tracking branch 'origin/main' into WATER-4267-returns-re…
Demwunz Feb 15, 2024
1316424
fix(app): address sonarcloud issue
Demwunz Feb 15, 2024
c4f44e6
fix(app): amend back link
Demwunz Feb 15, 2024
cd2bc2c
chore(app): WATER-4267 Updated jsdocs as per feedback
Demwunz Feb 16, 2024
7a8c697
Merge branch 'main' into WATER-4267-returns-required-journey-how-do-y…
Demwunz Feb 16, 2024
49e0d37
Merge remote-tracking branch 'origin/main' into WATER-4267-returns-re…
Demwunz Feb 16, 2024
4bd00e7
Merge remote-tracking branch 'origin/main' into WATER-4267-returns-re…
Demwunz Feb 19, 2024
de98aad
Merge remote-tracking branch 'origin/main' into WATER-4267-returns-re…
Demwunz Feb 20, 2024
7dfae8b
Merge remote-tracking branch 'origin/main' into WATER-4267-returns-re…
Demwunz Feb 20, 2024
69b3bb5
Merge remote-tracking branch 'origin/main' into WATER-4267-returns-re…
Demwunz Feb 23, 2024
2c2ef73
fix:(app) - add correct routing
Demwunz Feb 23, 2024
4d2572c
fix:(app) - addressed sonarcloud issue
Demwunz Feb 23, 2024
e2e7524
fix:(app) - addressed sonarcloud issue
Demwunz Feb 23, 2024
72a62e6
Merge branch 'main' into WATER-4267-returns-required-journey-how-do-y…
Demwunz Feb 26, 2024
81ff7fb
Update test/services/return-requirements/submit-setup.service.test.js
Demwunz Feb 27, 2024
bb51d41
Merge branch 'main' into WATER-4267-returns-required-journey-how-do-y…
Demwunz Feb 27, 2024
f96e1c0
Merge branch 'main' into WATER-4267-returns-required-journey-how-do-y…
Cruikshanks Feb 27, 2024
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
2 changes: 1 addition & 1 deletion app/controllers/return-requirements.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ async function submitSetup (request, h) {
return h.view('return-requirements/setup.njk', pageData)
}

return h.redirect(`/system/return-requirements/${sessionId}/purpose`)
return h.redirect(`/system/return-requirements/${sessionId}/${pageData.redirect}`)
}

async function submitSiteDescription (request, h) {
Expand Down
17 changes: 16 additions & 1 deletion app/services/return-requirements/submit-setup.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SetupValidator = require('../../validators/return-requirements/setup.valid
*
* The validation result is then combined with the output of the presenter to generate the page data needed by the view.
* If there was a validation error the controller will re-render the page so needs this information. If all is well the
* controller will redirect to the next page in the journey.
* controller will redirect to the next page in the journey depending on which radio item was chosen.
*
* @param {string} sessionId - The id of the current session
* @param {Object} payload - The submitted form data
Expand All @@ -34,10 +34,25 @@ async function go (sessionId, payload) {
activeNavBar: 'search',
error: validationResult,
pageTitle: 'How do you want to set up the return requirement?',
redirect: _redirect(payload.setup),
...formattedData
}
}

function _redirect (setup) {
let endpoint

if (setup === 'use_abstraction_data') {
endpoint = 'check-your-answers'
}

if (setup === 'set_up_manually') {
endpoint = 'purpose'
}

return endpoint
}

function _validate (payload) {
const validation = SetupValidator.go(payload)

Expand Down
2 changes: 1 addition & 1 deletion app/validators/return-requirements/setup.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Joi = require('joi')

const VALID_VALUES = [
'use_abstraction_data',
'copy_an_existing_return_requirement'
'set_up_manually'
]

/**
Expand Down
7 changes: 5 additions & 2 deletions app/views/return-requirements/setup.njk
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@
checked: false
},
{
value: "copy_an_existing_return_requirement",
text: "Copy an existing return requirement",
divider: "or"
},
{
value: "set_up_manually",
text: "Set up manually",
checked: false
}
]
Expand Down
33 changes: 31 additions & 2 deletions test/services/return-requirements/submit-setup.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ describe('Submit Setup service', () => {
expect(result).to.equal({
activeNavBar: 'search',
error: null,
licenceRef: '01/ABC',
pageTitle: 'How do you want to set up the return requirement?',
licenceRef: '01/ABC'
redirect: 'check-your-answers'
}, { skip: ['id'] })
})
})
Expand All @@ -79,8 +80,9 @@ describe('Submit Setup service', () => {

expect(result).to.equal({
activeNavBar: 'search',
licenceRef: '01/ABC',
pageTitle: 'How do you want to set up the return requirement?',
licenceRef: '01/ABC'
redirect: undefined
}, { skip: ['id', 'error'] })
})

Expand All @@ -94,4 +96,31 @@ describe('Submit Setup service', () => {
})
})
})
describe('with different setups', () => {
Demwunz marked this conversation as resolved.
Show resolved Hide resolved
describe('and setup is use_abstraction_data', () => {
beforeEach(() => {
payload = {
setup: 'use_abstraction_data'
}
})

it('redirects to the check your answers page', async () => {
const result = await SubmitSetupService.go(session.id, payload)
expect(result.redirect).to.equal('check-your-answers')
})
})

describe('and setup is set_up_manually', () => {
beforeEach(() => {
payload = {
setup: 'set_up_manually'
}
})

it('redirects to the purpose page', async () => {
const result = await SubmitSetupService.go(session.id, payload)
expect(result.redirect).to.equal('purpose')
})
})
})
})
Loading