Skip to content

Commit

Permalink
fix(app): add redirect to check-your-answers
Browse files Browse the repository at this point in the history
  • Loading branch information
Demwunz committed Apr 23, 2024
1 parent e39d741 commit bf9258a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/controllers/return-requirements.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ async function submitReason (request, h) {
return h.view('return-requirements/reason.njk', pageData)
}

if (pageData.checkYourAnswersVisited) {
return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

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

Expand Down
5 changes: 4 additions & 1 deletion app/services/return-requirements/submit-reason.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

return {}
return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited
}
}

const formattedData = ReasonPresenter.go(session, payload)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
pageTitle: 'Select the reason for the return requirement',
...formattedData
Expand Down
6 changes: 5 additions & 1 deletion app/views/return-requirements/reason.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

{% block breadcrumbs %}
{# Back link #}
{% set backLink %}
/system/return-requirements/{{ id }}/{{ 'check-your-answers' if checkYourAnswersVisited else 'start-date' }}
{% endset %}

{{
govukBackLink({
text: 'Back',
href: '/system/return-requirements/' + id + '/start-date'
href: backLink
})
}}
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Submit Reason service', () => {

session = await SessionHelper.add({
data: {
checkYourAnswersVisited: false,
licence: {
id: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
currentVersionStartDate: '2023-01-01T00:00:00.000Z',
Expand Down Expand Up @@ -58,6 +59,7 @@ describe('Submit Reason service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
pageTitle: 'Select the reason for the return requirement',
licenceRef: '01/ABC'
}, { skip: ['id', 'error'] })
Expand All @@ -81,6 +83,7 @@ describe('Submit Reason service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
pageTitle: 'Select the reason for the return requirement',
licenceRef: '01/ABC'
}, { skip: ['id', 'error'] })
Expand Down

0 comments on commit bf9258a

Please sign in to comment.