Skip to content

Commit

Permalink
feat(app): return requirements link referral
Browse files Browse the repository at this point in the history
  • Loading branch information
Demwunz committed Apr 4, 2024
1 parent 4a89e2d commit b0f284b
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 9 deletions.
21 changes: 20 additions & 1 deletion app/controllers/return-requirements.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -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`)
}

Expand All @@ -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`)
}

Expand All @@ -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`)
}

Expand Down Expand Up @@ -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`)
}

Expand All @@ -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`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ async function go (sessionId) {

const formattedData = CheckYourAnswersPresenter.go(session)

await _checkYourAnswersVisited(session)

return {
activeNavBar: 'search',
licenceRef: session.data.licence.licenceRef,
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function _data (licence, journey) {
const ends = licence.$ends()

return {
checkYourAnswersVisited: false,
licence: {
id,
currentVersionStartDate: _currentVersionStartDate(licenceVersions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function go (sessionId) {

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
pageTitle: 'Why are no returns required?',
...formattedData
}
Expand Down
1 change: 1 addition & 0 deletions app/services/return-requirements/purpose.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions app/services/return-requirements/reason.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function go (sessionId) {

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
pageTitle: 'Select the reason for the return requirement',
...formattedData
}
Expand Down
1 change: 1 addition & 0 deletions app/services/return-requirements/setup.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions app/services/return-requirements/start-date.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async function go (sessionId, payload) {
await _save(session, payload)

return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
journey: session.data.journey
}
}
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/services/return-requirements/submit-purpose.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 })
}
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
2 changes: 2 additions & 0 deletions app/services/return-requirements/submit-setup.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function go (sessionId, payload) {
await _save(session, payload)

return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
redirect: _redirect(payload.setup)
}
}
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/services/return-requirements/submit-start-date.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async function go (sessionId, payload) {
await _save(session, payload)

return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
journey: session.data.journey
}
}
Expand All @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion app/views/return-requirements/no-returns-required.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 Expand Up @@ -62,4 +66,5 @@
</form>
</div>


{% endblock %}
6 changes: 5 additions & 1 deletion app/views/return-requirements/purpose.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
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
6 changes: 5 additions & 1 deletion app/views/return-requirements/setup.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
10 changes: 9 additions & 1 deletion app/views/return-requirements/start-date.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -38,14 +39,18 @@ 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 () => {
const result = await CheckYourAnswersService.go(session.id)

expect(result).to.equal({
activeNavBar: 'search',
id: session.id,
pageTitle: 'Check the return requirements for Astro Boy',
journey: 'no-returns-required',
licenceRef: '01/ABC',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 () => {
Expand Down

0 comments on commit b0f284b

Please sign in to comment.