-
Notifications
You must be signed in to change notification settings - Fork 0
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
Submit Check your answers page #811
Merged
Demwunz
merged 24 commits into
main
from
WATER-4264-returns-not-required-journey-check-your-answers-page-iteration-2-3-of-3
Mar 20, 2024
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b0f9c5e
Submit Check your answers page
Demwunz 62d0835
feat(app): check your answers service
Demwunz 4f50823
fix(app): fixed broken tests
Demwunz 2acfd29
fix:(app) - updated service test
Demwunz 9bd3300
fix:(app) - added fetch licence test
Demwunz fc05b7a
fix:(app) - removed console log
Demwunz 0f53a72
Fix failing fetch-licence.service.test.js
Cruikshanks 1a3e7a2
Housekeeping in FetchLicenceService
Cruikshanks ba1112a
Clean up FetchLicenceService test
Cruikshanks 9af8930
fix:(app) - removed redundant tests
Demwunz 6c2e52b
feat(app): moved check licence expired to new service
Demwunz 33ff4c0
fix(app): simplified check licence
Demwunz 4fbdec2
Update app/services/return-requirements/check-licence-ended.service.js
Demwunz 78d7aba
Update app/services/return-requirements/check-licence-ended.service.js
Demwunz c0906cd
Update app/services/return-requirements/check-licence-ended.service.js
Demwunz c43048f
Update app/services/return-requirements/check-licence-ended.service.js
Demwunz 53db271
Update app/services/return-requirements/check-licence-ended.service.js
Demwunz 9ae6d57
Update app/services/return-requirements/check-licence-ended.service.js
Demwunz 46e4b8c
Update app/services/return-requirements/submit-check-your-answers.ser…
Demwunz c73673a
Update app/services/return-requirements/check-your-answers.service.js
Demwunz 85b45b9
Merge branch 'main' into WATER-4264-returns-not-required-journey-chec…
Demwunz bf77e18
fix(app): cleanup logic after changes
Demwunz 195a614
Merge branch 'main' into WATER-4264-returns-not-required-journey-chec…
Demwunz 98b6e2a
fix(app): restored licenceId for redirect
Demwunz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/presenters/return-requirements/check-your-answers.presenter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats data for the `/return-requirements/{sessionId}/check-your-answers` page | ||
* @module CheckYourAnswersPresenter | ||
*/ | ||
|
||
function go (session) { | ||
const data = { | ||
id: session.id, | ||
licenceRef: session.data.licence.licenceRef | ||
} | ||
|
||
return data | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
57 changes: 57 additions & 0 deletions
57
app/services/return-requirements/check-licence-ended.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict' | ||
|
||
/** | ||
* Checks if a licence is 'ended' (expired, lapsed or revoked) | ||
* @module CheckLicenceEndedService | ||
*/ | ||
|
||
const LicenceModel = require('../../models/licence.model.js') | ||
|
||
/** | ||
* Checks if a licence is 'ended' (expired, lapsed or revoked) | ||
* | ||
* A licence ended if it has expired, lapsed or revoked on or before the current date. Because we need to check this | ||
* in a number of places we have the `LicenceModel` instance method `$ends()` to do this for us. | ||
* | ||
* But for that to work you have to fetch the licence and the 3 dates from the licence record. This service combines | ||
* fetching the licence and the dates then returning the result of `$ends()` to whatever service calls it. | ||
* | ||
* @param {string} id - The UUID for the licence to fetch | ||
* | ||
* @returns {Promise<boolean>} true if the licence has ended else false | ||
*/ | ||
async function go (id) { | ||
const licence = await _fetchLicence(id) | ||
const licenceEnded = _licenceEnded(licence) | ||
return licenceEnded | ||
} | ||
|
||
async function _fetchLicence (id) { | ||
return LicenceModel.query() | ||
.findById(id) | ||
.select([ | ||
'expiredDate', | ||
'id', | ||
'lapsedDate', | ||
'licenceRef', | ||
'revokedDate', | ||
'startDate' | ||
]) | ||
} | ||
|
||
function _licenceEnded (licence) { | ||
const ends = licence.$ends() | ||
|
||
if (!ends) { | ||
return false | ||
} | ||
|
||
const today = new Date() | ||
today.setHours(0, 0, 0, 0) | ||
|
||
return ends.date <= today | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
32 changes: 32 additions & 0 deletions
32
app/services/return-requirements/check-your-answers.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data for `/return-requirements/{sessionId}/check-your-answers` page | ||
* @module CheckYourAnswersService | ||
*/ | ||
|
||
const CheckYourAnswersPresenter = require('../../presenters/return-requirements/check-your-answers.presenter.js') | ||
const SessionModel = require('../../models/session.model.js') | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data for `/return-requirements/{sessionId}/check-your-answers` page | ||
* | ||
* @param {string} sessionId - The UUID for return requirement setup session record | ||
* | ||
* @returns {Promise<Object>} page data needed by the view template | ||
*/ | ||
async function go (sessionId) { | ||
const session = await SessionModel.query().findById(sessionId) | ||
const formattedData = CheckYourAnswersPresenter.go(session) | ||
|
||
return { | ||
activeNavBar: 'search', | ||
licenceRef: session.data.licence.licenceRef, | ||
pageTitle: `Check the return requirements for ${session.data.licence.licenceHolder}`, | ||
...formattedData | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
46 changes: 46 additions & 0 deletions
46
app/services/return-requirements/submit-check-your-answers.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict' | ||
|
||
/** | ||
* Manages converting the session data to return requirement records when check your answers is confirmed | ||
* @module SubmitCheckYoursAnswersService | ||
*/ | ||
|
||
const CheckLicenceEndedService = require('./check-licence-ended.service.js') | ||
const ExpandedError = require('../../errors/expanded.error.js') | ||
const SessionModel = require('../../models/session.model.js') | ||
|
||
/** | ||
* Manages converting the session data to return requirement records when check your answers is confirmed | ||
* | ||
* > This service is work in progress. Some of the functionality described is yet to be implemented | ||
* | ||
* After fetching the session instance for the returns requirements journey in progress it validates that what the user | ||
* has setup can be persisted for the licence. | ||
* | ||
* If valid it converts the session data to return requirements records then deletes the session record. | ||
* | ||
* @param {string} sessionId - The UUID for return requirement setup session record | ||
* | ||
* @returns {string} The licence ID | ||
*/ | ||
async function go (sessionId) { | ||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
await _validateLicence(session.data.licence.id) | ||
|
||
return session.data.licence.id | ||
} | ||
|
||
async function _validateLicence (licenceId) { | ||
const licenceEnded = await CheckLicenceEndedService.go(licenceId) | ||
|
||
if (!licenceEnded) { | ||
return | ||
} | ||
|
||
throw new ExpandedError('Invalid licence for return requirements', { licenceId, licenceEnded }) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,104 @@ | ||
{% extends 'layout.njk' %} | ||
{% from "govuk/components/button/macro.njk" import govukButton %} | ||
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %} | ||
|
||
{% set baseURL = "/system/return-requirements/" + id %} | ||
|
||
{% block content %} | ||
{# Main heading #} | ||
<div class="govuk-body"> | ||
<h1 class="govuk-heading-xl govuk-!-margin-bottom-3">{{ pageTitle }}</h1> | ||
<h1 class="govuk-heading-xl govuk-!-margin-bottom-3"> | ||
<span class="govuk-caption-l">Licence {{ licenceRef }}</span> | ||
{{ pageTitle }} | ||
</h1> | ||
</div> | ||
|
||
<form method="post"> | ||
<div class="govuk-!-margin-bottom-9"> | ||
<hr class="govuk-section-break govuk-!-margin-bottom-2 govuk-section-break--visible"> | ||
{{ govukSummaryList({ | ||
classes: 'govuk-!-margin-bottom-2', | ||
rows: [ | ||
{ | ||
classes: 'govuk-summary-list govuk-summary-list__row--no-border', | ||
key: { | ||
text: "Start date" | ||
}, | ||
value: { | ||
text: "start_date_from_session" | ||
}, | ||
actions: { | ||
items: [ | ||
{ | ||
href: baseURL + "/start-date", | ||
text: "Change", | ||
visuallyHiddenText: "the start date for the return requirement" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
classes: 'govuk-summary-list govuk-summary-list__row--no-border', | ||
key: { | ||
text: "Reason" | ||
}, | ||
value: { | ||
text: "reason_from_session" | ||
}, | ||
actions: { | ||
items: [ | ||
{ | ||
href: baseURL + "/reason", | ||
text: "Change", | ||
visuallyHiddenText: "the reason for the return requirement" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}) }} | ||
<hr class="govuk-section-break govuk-!-margin-bottom-2 govuk-section-break--visible"> | ||
</div> | ||
|
||
<div class="govuk-!-margin-bottom-9"> | ||
<h2 class="govuk-heading-l govuk-!-margin-bottom-4" >Notes</h2> | ||
<hr class="govuk-section-break govuk-!-margin-bottom-2 govuk-section-break--visible"> | ||
{{ govukSummaryList({ | ||
classes: 'govuk-!-margin-bottom-2', | ||
rows: [ | ||
{ | ||
classes: 'govuk-summary-list govuk-summary-list__row--no-border', | ||
key: { | ||
text: "No notes added" | ||
}, | ||
value: { | ||
text: "" | ||
}, | ||
actions: { | ||
items: [ | ||
{ | ||
href: "#", | ||
text: "Change", | ||
visuallyHiddenText: "the note" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}) }} | ||
<hr class="govuk-section-break govuk-!-margin-bottom-2 govuk-section-break--visible"> | ||
</div> | ||
<div class="govuk-body"> | ||
{{ govukButton({ text: "Approve returns requirements" }) }} | ||
{{ govukButton({ | ||
text: "Approve returns requirements", | ||
classes: "govuk-!-margin-right-6" | ||
}) }} | ||
|
||
{{ govukButton({ | ||
text: "Cancel return requirements", | ||
classes: "govuk-button--secondary", | ||
href: "" | ||
}) }} | ||
</div> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/presenters/return-requirements/check-your-answers.presenter.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict' | ||
|
||
// Test framework dependencies | ||
const Lab = require('@hapi/lab') | ||
const Code = require('@hapi/code') | ||
|
||
const { describe, it, beforeEach } = exports.lab = Lab.script() | ||
const { expect } = Code | ||
|
||
// Thing under test | ||
const CheckYourAnswersPresenter = require('../../../app/presenters/return-requirements/check-your-answers.presenter.js') | ||
|
||
describe('Check Your Answers presenter', () => { | ||
let session | ||
|
||
beforeEach(() => { | ||
session = { | ||
id: 'f1288f6c-8503-4dc1-b114-75c408a14bd0', | ||
data: { | ||
licence: { | ||
id: 'ea53bfc6-740d-46c5-9558-fc8cabfc6c1f', | ||
licenceRef: '01/123', | ||
licenceHolder: 'Astro Boy' | ||
} | ||
} | ||
} | ||
}) | ||
|
||
describe('when provided with a populated session', () => { | ||
it('correctly presents the data', () => { | ||
const result = CheckYourAnswersPresenter.go(session) | ||
|
||
expect(result).to.equal({ | ||
id: 'f1288f6c-8503-4dc1-b114-75c408a14bd0', | ||
licenceRef: '01/123' | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid using the Optional Chaining (sometimes known as the safe navigation operator) unless we have a situation where we know a property may not be populated.
In the case of this service, the session should be correctly populated. If it isn't it's because someone has purposely tried to access the page with a valid session ID but an invalid session. So, it's own them!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cruikshanks ok, that makes sense. I'll remove it and replace with a direct reference.