diff --git a/app/controllers/return-requirements.controller.js b/app/controllers/return-requirements.controller.js index b967188d1b..26c9cc3f91 100644 --- a/app/controllers/return-requirements.controller.js +++ b/app/controllers/return-requirements.controller.js @@ -190,7 +190,6 @@ async function startDate (request, h) { const { sessionId } = request.params const pageData = await StartDateService.go(sessionId) - return h.view('return-requirements/start-date.njk', { ...pageData }) @@ -260,6 +259,10 @@ async function submitPoints (request, h) { return h.view('return-requirements/points.njk', pageData) } + if (pageData.checkYourAnswersVisited) { + return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`) + } + return h.redirect(`/system/return-requirements/${sessionId}/abstraction-period`) } @@ -272,6 +275,10 @@ async function submitPurpose (request, h) { return h.view('return-requirements/purpose.njk', pageData) } + if (pageData.checkYourAnswersVisited) { + return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`) + } + return h.redirect(`/system/return-requirements/${sessionId}/points`) } @@ -284,6 +291,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`) } @@ -314,6 +325,10 @@ async function submitSiteDescription (request, h) { return h.view('return-requirements/site-description.njk', pageData) } + if (pageData.checkYourAnswersVisited) { + return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`) + } + return h.redirect(`/system/return-requirements/${sessionId}/frequency-collected`) } @@ -326,6 +341,10 @@ async function submitStartDate (request, h) { return h.view('return-requirements/start-date.njk', pageData) } + if (pageData.checkYourAnswersVisited) { + return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`) + } + if (pageData.journey === 'returns-required') { return h.redirect(`/system/return-requirements/${sessionId}/reason`) } diff --git a/app/services/return-requirements/check-your-answers.service.js b/app/services/return-requirements/check-your-answers.service.js index 749f557870..39fcfddcea 100644 --- a/app/services/return-requirements/check-your-answers.service.js +++ b/app/services/return-requirements/check-your-answers.service.js @@ -20,6 +20,8 @@ async function go (sessionId) { const formattedData = CheckYourAnswersPresenter.go(session) + await _checkYourAnswersVisited(session) + return { activeNavBar: 'search', licenceRef: session.data.licence.licenceRef, @@ -28,6 +30,13 @@ async function go (sessionId) { } } +async function _checkYourAnswersVisited (session) { + const currentData = session.data + + currentData.checkYourAnswersVisited = true + return session.$query().patch({ data: currentData }) +} + module.exports = { go } diff --git a/app/services/return-requirements/initiate-return-requirement-session.service.js b/app/services/return-requirements/initiate-return-requirement-session.service.js index 0bd3f99567..23b59a97e5 100644 --- a/app/services/return-requirements/initiate-return-requirement-session.service.js +++ b/app/services/return-requirements/initiate-return-requirement-session.service.js @@ -48,6 +48,7 @@ function _data (licence, journey) { const ends = licence.$ends() return { + checkYourAnswersVisited: false, licence: { id, currentVersionStartDate: _currentVersionStartDate(licenceVersions), diff --git a/app/services/return-requirements/no-returns-required.service.js b/app/services/return-requirements/no-returns-required.service.js index f8e023a89a..9135bf49fd 100644 --- a/app/services/return-requirements/no-returns-required.service.js +++ b/app/services/return-requirements/no-returns-required.service.js @@ -23,6 +23,7 @@ async function go (sessionId) { return { activeNavBar: 'search', + checkYourAnswersVisited: session.data.checkYourAnswersVisited, pageTitle: 'Why are no returns required?', ...formattedData } diff --git a/app/services/return-requirements/purpose.service.js b/app/services/return-requirements/purpose.service.js index c007cd59e6..b3d6f5535a 100644 --- a/app/services/return-requirements/purpose.service.js +++ b/app/services/return-requirements/purpose.service.js @@ -27,6 +27,7 @@ async function go (sessionId) { return { activeNavBar: 'search', + checkYourAnswersVisited: session.data.checkYourAnswersVisited, pageTitle: 'Select the purpose for the requirements for returns', ...formattedData } diff --git a/app/services/return-requirements/reason.service.js b/app/services/return-requirements/reason.service.js index 554fa04a9f..12a8e88c02 100644 --- a/app/services/return-requirements/reason.service.js +++ b/app/services/return-requirements/reason.service.js @@ -23,6 +23,7 @@ async function go (sessionId) { return { activeNavBar: 'search', + checkYourAnswersVisited: session.data.checkYourAnswersVisited, pageTitle: 'Select the reason for the return requirement', ...formattedData } diff --git a/app/services/return-requirements/setup.service.js b/app/services/return-requirements/setup.service.js index dd429b2abf..ea60312f9f 100644 --- a/app/services/return-requirements/setup.service.js +++ b/app/services/return-requirements/setup.service.js @@ -23,6 +23,7 @@ async function go (sessionId) { return { activeNavBar: 'search', + checkYourAnswersVisited: session.data.checkYourAnswersVisited, pageTitle: 'How do you want to set up the return requirement?', ...formattedData } diff --git a/app/services/return-requirements/start-date.service.js b/app/services/return-requirements/start-date.service.js index 97a59ce268..a8025fae65 100644 --- a/app/services/return-requirements/start-date.service.js +++ b/app/services/return-requirements/start-date.service.js @@ -24,6 +24,7 @@ async function go (sessionId) { return { activeNavBar: 'search', + checkYourAnswersVisited: session.data.checkYourAnswersVisited, pageTitle: 'Select the start date for the return requirement', ...formattedData } diff --git a/app/services/return-requirements/submit-no-returns-required.service.js b/app/services/return-requirements/submit-no-returns-required.service.js index c4e2660253..2b452ed158 100644 --- a/app/services/return-requirements/submit-no-returns-required.service.js +++ b/app/services/return-requirements/submit-no-returns-required.service.js @@ -31,6 +31,7 @@ async function go (sessionId, payload) { await _save(session, payload) return { + checkYourAnswersVisited: session.data.checkYourAnswersVisited, journey: session.data.journey } } @@ -39,6 +40,7 @@ async function go (sessionId, payload) { return { activeNavBar: 'search', + checkYourAnswersVisited: session.data.checkYourAnswersVisited, error: validationResult, pageTitle: 'Why are no returns required?', ...formattedData diff --git a/app/services/return-requirements/submit-purpose.service.js b/app/services/return-requirements/submit-purpose.service.js index 9f3e005c0e..c4d6399fc8 100644 --- a/app/services/return-requirements/submit-purpose.service.js +++ b/app/services/return-requirements/submit-purpose.service.js @@ -33,7 +33,9 @@ async function go (sessionId, payload) { if (!validationResult) { await _save(session, payload) - return {} + return { + checkYourAnswersVisited: session.data.checkYourAnswersVisited + } } const formattedData = SelectPurposePresenter.go(session, purposesData, payload) @@ -49,7 +51,7 @@ async function go (sessionId, payload) { async function _save (session, payload) { const currentData = session.data - currentData.purpose = payload.purpose + currentData.purposes = payload.purposes return session.$query().patch({ data: currentData }) } diff --git a/app/services/return-requirements/submit-reason.service.js b/app/services/return-requirements/submit-reason.service.js index c203b7f47b..8efefe9fbf 100644 --- a/app/services/return-requirements/submit-reason.service.js +++ b/app/services/return-requirements/submit-reason.service.js @@ -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 diff --git a/app/services/return-requirements/submit-setup.service.js b/app/services/return-requirements/submit-setup.service.js index 59fc2d7d97..626b6a1def 100644 --- a/app/services/return-requirements/submit-setup.service.js +++ b/app/services/return-requirements/submit-setup.service.js @@ -32,6 +32,7 @@ async function go (sessionId, payload) { await _save(session, payload) return { + checkYourAnswersVisited: session.data.checkYourAnswersVisited, redirect: _redirect(payload.setup) } } @@ -40,6 +41,7 @@ async function go (sessionId, payload) { return { activeNavBar: 'search', + checkYourAnswersVisited: session.data.checkYourAnswersVisited, error: validationResult, pageTitle: 'How do you want to set up the return requirement?', ...formattedData diff --git a/app/services/return-requirements/submit-start-date.service.js b/app/services/return-requirements/submit-start-date.service.js index 1aa0598d50..e8a35a1643 100644 --- a/app/services/return-requirements/submit-start-date.service.js +++ b/app/services/return-requirements/submit-start-date.service.js @@ -34,6 +34,7 @@ async function go (sessionId, payload) { await _save(session, payload) return { + checkYourAnswersVisited: session.data.checkYourAnswersVisited, journey: session.data.journey } } @@ -42,6 +43,7 @@ async function go (sessionId, payload) { return { activeNavBar: 'search', + checkYourAnswersVisited: session.data.checkYourAnswersVisited, error: validationResult, journey: session.data.journey, pageTitle: 'Select the start date for the return requirement', diff --git a/app/views/return-requirements/no-returns-required.njk b/app/views/return-requirements/no-returns-required.njk index 2d14aaf694..7593428b51 100644 --- a/app/views/return-requirements/no-returns-required.njk +++ b/app/views/return-requirements/no-returns-required.njk @@ -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 %} @@ -62,4 +66,5 @@ + {% endblock %} diff --git a/app/views/return-requirements/purpose.njk b/app/views/return-requirements/purpose.njk index 6f3a8a28d8..62e3bf6050 100644 --- a/app/views/return-requirements/purpose.njk +++ b/app/views/return-requirements/purpose.njk @@ -9,10 +9,14 @@ {% block breadcrumbs %} {# Back link #} + {% set backLink %} + /system/return-requirements/{{ id }}/{{ 'check-your-answers' if checkYourAnswersVisited else 'setup' }} + {% endset %} + {{ govukBackLink({ text: 'Back', - href: rootLink + "/setup" + href: backLink }) }} {% endblock %} diff --git a/app/views/return-requirements/reason.njk b/app/views/return-requirements/reason.njk index cda22d304f..d41461d876 100644 --- a/app/views/return-requirements/reason.njk +++ b/app/views/return-requirements/reason.njk @@ -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 %} diff --git a/app/views/return-requirements/setup.njk b/app/views/return-requirements/setup.njk index 1612cfe1e2..300dd3b9ea 100644 --- a/app/views/return-requirements/setup.njk +++ b/app/views/return-requirements/setup.njk @@ -8,10 +8,14 @@ {% block breadcrumbs %} {# Back link #} + {% set backLink %} + /system/return-requirements/{{ id }}/{{ 'check-your-answers' if checkYourAnswersVisited else 'reason' }} + {% endset %} + {{ govukBackLink({ text: 'Back', - href: rootLink + '/reason' + href: backLink }) }} {% endblock %} diff --git a/app/views/return-requirements/start-date.njk b/app/views/return-requirements/start-date.njk index 93a67bcb38..1e35bad67d 100644 --- a/app/views/return-requirements/start-date.njk +++ b/app/views/return-requirements/start-date.njk @@ -7,10 +7,18 @@ {% block breadcrumbs %} {# Back link #} + {% set backLink %} + {% if checkYourAnswersVisited %} + /system/return-requirements/{{ id }}/check-your-answers + {% else %} + /licences/{{ licenceId }}#charge + {% endif %} + {% endset %} + {{ govukBackLink({ text: 'Back', - href: '/licences/' + licenceId + '#charge' + href: backLink }) }} {% endblock %} diff --git a/test/services/return-requirements/check-your-answers.service.test.js b/test/services/return-requirements/check-your-answers.service.test.js index 7700160a2e..b10d62278a 100644 --- a/test/services/return-requirements/check-your-answers.service.test.js +++ b/test/services/return-requirements/check-your-answers.service.test.js @@ -21,6 +21,7 @@ describe('Check Your Answers service', () => { await DatabaseSupport.clean() session = await SessionHelper.add({ data: { + id: 'f1288f6c-8503-4dc1-b114-75c408a14bd0', licence: { endDate: null, licenceRef: '01/ABC', @@ -38,7 +39,10 @@ describe('Check Your Answers service', () => { it('fetches the current setup session record', async () => { const result = await CheckYourAnswersService.go(session.id) + console.log('-----sESSION----', session.data) + expect(result.id).to.equal(session.id) + expect(session.data.checkYourAnswersVisited).to.equal(true) }) it('returns page data for the view', async () => { @@ -46,6 +50,7 @@ describe('Check Your Answers service', () => { expect(result).to.equal({ activeNavBar: 'search', + id: session.id, pageTitle: 'Check the return requirements for Astro Boy', journey: 'no-returns-required', licenceRef: '01/ABC', diff --git a/test/services/return-requirements/initiate-return-requirement-session.service.test.js b/test/services/return-requirements/initiate-return-requirement-session.service.test.js index 746c32271e..b8121b68a4 100644 --- a/test/services/return-requirements/initiate-return-requirement-session.service.test.js +++ b/test/services/return-requirements/initiate-return-requirement-session.service.test.js @@ -45,6 +45,14 @@ describe('Initiate Return Requirement Session service', () => { journey = 'returns-required' }) + it('creates a new session record and checkYourAnswers page has not been visited', async () => { + const result = await InitiateReturnRequirementSessionService.go(licence.id, journey) + + const { data } = result + + expect(data.licence.checkYourAnswersVisited).to.equal(false) + }) + it('creates a new session record containing details of the licence and licence holder', async () => { const result = await InitiateReturnRequirementSessionService.go(licence.id, journey) @@ -53,6 +61,7 @@ describe('Initiate Return Requirement Session service', () => { expect(data.licence.id).to.equal(licence.id) expect(data.licence.licenceRef).to.equal(licence.licenceRef) expect(data.licence.licenceHolder).to.equal('Licence Holder Ltd') + expect(data.checkYourAnswersVisited).to.equal(false) }) it("creates a new session record containing the licence's 'current version' start date", async () => {