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

Select the points for the requirements for returns page #833

Merged
merged 56 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
7248451
Select the points for the requirements for returns page
rvsiyad Mar 18, 2024
e34b8c1
Merge branch 'main' into return-requirements-select-points
rvsiyad Mar 18, 2024
9c7e7e1
Added the points return requirements view
rvsiyad Mar 18, 2024
475c6a7
Changed points method to use SelectPointsService
rvsiyad Mar 18, 2024
73af0c5
Added the Points service
rvsiyad Mar 18, 2024
00cb02c
WIP
rvsiyad Mar 18, 2024
845561a
Merge branch 'return-requirements-select-points' of https://github.co…
rvsiyad Mar 18, 2024
12460d5
Added SubmitPoints service to submitPoints() method
rvsiyad Mar 19, 2024
e3eb1a3
Added Points presenter
rvsiyad Mar 19, 2024
2b3cd8e
Added FetchPoints service
rvsiyad Mar 19, 2024
27e7d19
Added SubmitPoints service
rvsiyad Mar 19, 2024
ce58e60
Added Points validator
rvsiyad Mar 19, 2024
d69aaa3
Merge branch 'main' into return-requirements-select-points
rvsiyad Mar 19, 2024
323d9f5
Added stubbing of SelectPoints service test within Return Requirement…
rvsiyad Mar 19, 2024
7936817
Remove .only()
rvsiyad Mar 19, 2024
b09b7bc
Added Points Presenter test
rvsiyad Mar 19, 2024
1447343
Merge branch 'return-requirements-select-points' of https://github.co…
rvsiyad Mar 19, 2024
8c8735a
Altered FetchPoints service to extract point details before being pas…
rvsiyad Mar 20, 2024
d5bc6d0
Altered Points presenter to handle changed pointsData
rvsiyad Mar 20, 2024
ae4510a
Added extra test cases for Points presenter
rvsiyad Mar 20, 2024
29c2046
Remove .only()
rvsiyad Mar 20, 2024
301f9b4
Changed point route description to new title
rvsiyad Mar 20, 2024
6791831
Remove unused select for 'displayName'
rvsiyad Mar 20, 2024
f9ba54d
Added test for FetchPoints service
rvsiyad Mar 20, 2024
8a8b594
Added test for Point service
rvsiyad Mar 20, 2024
7d67a54
Added test for SubmitPoints service
rvsiyad Mar 20, 2024
9cc54c5
Added test for Point validator
rvsiyad Mar 20, 2024
d2b0b67
Merge branch 'main' into return-requirements-select-points
rvsiyad Mar 20, 2024
616dfeb
SonarCloud changes over duplicated code
rvsiyad Mar 20, 2024
c6b127b
Merge branch 'return-requirements-select-points' of https://github.co…
rvsiyad Mar 20, 2024
2cfb308
Added JSDocs to Points presenter
rvsiyad Mar 21, 2024
e8b25df
Changed comment error in Purpose presenter
rvsiyad Mar 21, 2024
14148b1
Changed route descriptions in ReturnRequirement routes
rvsiyad Mar 21, 2024
90c08de
Added JSDocs to FetchPoints service
rvsiyad Mar 21, 2024
c0af0b7
Added JSDocs to SubmitPoints service
rvsiyad Mar 21, 2024
689a7a8
Added JSDocs to Point validator
rvsiyad Mar 21, 2024
d515b20
Added missing .js for file import
rvsiyad Mar 21, 2024
ea298ea
Merge branch 'main' into return-requirements-select-points
rvsiyad Mar 21, 2024
12cadfb
Merge branch 'main' into return-requirements-select-points
rvsiyad Mar 22, 2024
59b2746
Conventions: Change import from SelectPurpose to PurposeService
rvsiyad Mar 22, 2024
d4d8be7
Removed unnecessary checks for data and fixed typo in comments
rvsiyad Mar 22, 2024
8ec4764
Typo in comments
rvsiyad Mar 22, 2024
956ff12
Typo - id to UUID
rvsiyad Mar 22, 2024
fb9290c
Typo - id to UUID
rvsiyad Mar 22, 2024
7991853
Changed import from Point to Points and wrapped comments
rvsiyad Mar 22, 2024
7cb9be3
Added NOTE explaining use of array check
rvsiyad Mar 22, 2024
164ec09
Fixed indentations and spacing
rvsiyad Mar 22, 2024
d900a02
Changed file import from SelectPoints to PointsService
rvsiyad Mar 22, 2024
591114d
Changed file import from SelectPoints to PointsPresenter
rvsiyad Mar 22, 2024
19eabba
Added extra detail and more describe blocks for readability
rvsiyad Mar 22, 2024
b1814a5
Created separate function to hold FetchPointsService data for stubbing
rvsiyad Mar 22, 2024
fa34ced
Changed import and file name to PointsValidator
rvsiyad Mar 22, 2024
b3c3851
Merge branch 'main' into return-requirements-select-points
rvsiyad Mar 22, 2024
136f32b
Change import from PointsValidation to PointsValidator
rvsiyad Mar 25, 2024
fe252d6
Merge branch 'main' into return-requirements-select-points
rvsiyad Mar 25, 2024
3886d00
Merge branch 'main' into return-requirements-select-points
rvsiyad Mar 25, 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
4 changes: 2 additions & 2 deletions app/controllers/return-requirements.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const CheckYourAnswersService = require('../services/return-requirements/check-your-answers.service.js')
const NoReturnsRequiredService = require('../services/return-requirements/no-returns-required.service.js')
const SelectPointsService = require('../services/return-requirements/points.service.js')
const PointsService = require('../services/return-requirements/points.service.js')
const SelectPurposeService = require('../services/return-requirements/purpose.service.js')
const SelectReasonService = require('../services/return-requirements/reason.service.js')
const SessionModel = require('../models/session.model.js')
Expand Down Expand Up @@ -128,7 +128,7 @@ async function noReturnsRequired (request, h) {
async function points (request, h) {
const { sessionId } = request.params

const pageData = await SelectPointsService.go(sessionId)
const pageData = await PointsService.go(sessionId)

return h.view('return-requirements/points.njk', {
...pageData
Expand Down
16 changes: 6 additions & 10 deletions app/presenters/return-requirements/points.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,21 @@ function _licencePoints (pointsData, payload) {
// for the return requirement.
// If it is not set then it is because the presenter has been called from 'PointsService' and it's the first
// load. Else it has been called by the 'SubmitPointsService' and the user has not checked a point from the list.
// Either way, we use it to tell us wether there is anything in the payload worth transforming.
// Either way, we use it to tell us whether there is anything in the payload worth transforming.
const points = payload.points

if (points) {
return points
}

if (!pointsData || pointsData === undefined) {
return {
abstractionPoints: null
}
}

const abstractionPoints = []

if (!pointsData) {
return abstractionPoints
}

pointsData.forEach((pointDetail) => {
if (pointDetail) {
abstractionPoints.push(_generateAbstractionContent(pointDetail))
}
abstractionPoints.push(_generateAbstractionContent(pointDetail))
})

return abstractionPoints
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/return-requirements/purpose.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function _licencePurposes (purposesData, payload) {
// for the return requirement.
// If it is not set then it is because the presenter has been called from 'PurposeService' and it's the first
// load. Else it has been called by the 'SubmitPurposeService' and the user has not checked a purpose from the list.
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved
// Either way, we use it to tell us wether there is anything in the payload worth transforming.
// Either way, we use it to tell us whether there is anything in the payload worth transforming.
const purposes = payload.purposes

if (!purposes) {
Expand Down
2 changes: 1 addition & 1 deletion app/services/return-requirements/fetch-points.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const LicenceModel = require('../../models/licence.model.js')
/**
* Fetches points details needed for `/return-requirements/{sessionId}/points` page
*
* @param {string} licenceId The UUID for the licence to fetch
* @param {string} licenceId - The UUID for the licence to fetch
*
* @returns {Promise<Object>} The points details for the matching licenceId
*/
Expand Down
2 changes: 1 addition & 1 deletion app/services/return-requirements/points.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const SessionModel = require('../../models/session.model.js')
* Supports generating the data needed for the points page in the return requirements setup journey. It fetches the
* current session record and combines it with the checkboxes and other information needed for the form.
*
* @param {string} sessionId - The id of the current session
* @param {string} sessionId - The UUID of the current session
*
* @returns {Promise<Object>} The view data for the points page
*/
Expand Down
12 changes: 6 additions & 6 deletions app/services/return-requirements/submit-points.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

const FetchPointsService = require('../../services/return-requirements/fetch-points.service.js')
const PointValidation = require('../../validators/return-requirements/point.validator.js')
const PointsValidation = require('../../validators/return-requirements/points.validator.js')
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved
const SelectPointsPresenter = require('../../presenters/return-requirements/points.presenter.js')
const SessionModel = require('../../models/session.model.js')

Expand All @@ -15,11 +15,11 @@ const SessionModel = require('../../models/session.model.js')
*
* It first retrieves the session instance for the returns requirements journey in progress.
*
* The user input is then validated and the 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.
* The user input is then validated and the 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.
*
* @param {string} sessionId - The id of the current session
* @param {string} sessionId - The UUID of the current session
* @param {Object} payload - The submitted form data
*
* @returns {Promise<Object>} The page data for the start date page
Expand All @@ -40,7 +40,7 @@ async function go (sessionId, payload) {
}

function _validate (payload) {
const validation = PointValidation.go(payload)
const validation = PointsValidation.go(payload)

if (!validation.error) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ const Joi = require('joi')
/**
* Validates data submitted for the `/return-requirements/{sessionId}/points` page
*
* When setting up a requirement users must specify a points for the return requirement.
* Users must select one or more points linked to the licence. If these requirements are not met
* the validation will return an error.
* When setting up a requirement users must specify points for the return requirement. Users must select one or more
* points linked to the licence. If these requirements are not met the validation will return an error.
*
* @param {Object} payload - The payload from the request to be validated
*
* @returns {Object} The result from calling Joi's schema.validate(). If any errors are found the
* `error:` property will also exist detailing what the issue is.
* @returns {Object} The result from calling Joi's schema.validate(). If any errors are found the `error:` property will
* also exist detailing what the issue is.
*/
function go (payload) {
// NOTE: When a single point is checked by a user, it returns as a string. When multiple points are checked, the
// 'payload' is returned as an array. To make Joi validation straightforward, if the 'payload.points' is a string, it is
// turned into an array and validated as such.
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved
let points = payload.points

if (!Array.isArray(points)) {
Expand Down
13 changes: 5 additions & 8 deletions app/views/return-requirements/points.njk
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@
<span class="govuk-caption-l"> Licence {{ licenceRef }} </span>
<h1 class="govuk-heading-xl govuk-!-margin-bottom-3">{{ pageTitle }}</h1>

rvsiyad marked this conversation as resolved.
Show resolved Hide resolved

<div class="govuk-hint"> Select all that apply </div>
</div>

<div>
<form method="post">
<div>
<form method="post">
{% set checkBoxItems = [] %}
{% for point in licencePoints %}

Expand All @@ -51,7 +50,7 @@
checked: false
} %}

{% set checkBoxItems = (checkBoxItems.push(checkBoxItem), checkBoxItems) %}
{% set checkBoxItems = (checkBoxItems.push(checkBoxItem), checkBoxItems) %}

{% endfor %}
{{ govukCheckboxes({
Expand All @@ -61,8 +60,6 @@
}) }}

{{ govukButton({ text: "Continue" }) }}
</form>
</div>


</form>
</div>
{% endblock %}
5 changes: 3 additions & 2 deletions test/controllers/return-requirements.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { expect } = Code
// Things we need to stub
const CheckYourAnswersService = require('../../app/services/return-requirements/check-your-answers.service.js')
const NoReturnsRequiredService = require('../../app/services/return-requirements/no-returns-required.service.js')
const SelectPointsService = require('../../app/services/return-requirements/points.service.js')
const PointsService = require('../../app/services/return-requirements/points.service.js')
const SelectPurposeService = require('../../app/services/return-requirements/purpose.service.js')
const SelectReasonService = require('../../app/services/return-requirements/reason.service.js')
const SetupService = require('../../app/services/return-requirements/setup.service.js')
Expand Down Expand Up @@ -153,10 +153,11 @@ describe('Return requirements controller', () => {

describe('GET /return-requirements/{sessionId}/points', () => {
beforeEach(async () => {
Sinon.stub(SelectPointsService, 'go').resolves({
Sinon.stub(PointsService, 'go').resolves({
id: '8702b98f-ae51-475d-8fcc-e049af8b8d38', pageTitle: 'Select the points for the requirements for returns'
})
})
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved

describe('when the request succeeds', () => {
it('returns the page successfully', async () => {
const response = await server.inject(_options('points'))
Expand Down
6 changes: 3 additions & 3 deletions test/presenters/return-requirements/points.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { describe, it, beforeEach } = exports.lab = Lab.script()
const { expect } = Code

// Thing under test
const SelectPointsPresenter = require('../../../app/presenters/return-requirements/points.presenter.js')
const PointsPresenter = require('../../../app/presenters/return-requirements/points.presenter.js')

describe('Select Points presenter', () => {
let session
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Select Points presenter', () => {
describe('when provided with a populated session', () => {
describe('and no payload', () => {
it('correctly presents the data', () => {
const result = SelectPointsPresenter.go(session, pointsData)
const result = PointsPresenter.go(session, pointsData)

expect(result).to.equal({
id: '61e07498-f309-4829-96a9-72084a54996d',
Expand All @@ -88,7 +88,7 @@ describe('Select Points presenter', () => {
}

it('correctly presents the data', () => {
const result = SelectPointsPresenter.go(session, pointsData, payload)
const result = PointsPresenter.go(session, pointsData, payload)

expect(result).to.equal({
id: '61e07498-f309-4829-96a9-72084a54996d',
Expand Down
38 changes: 20 additions & 18 deletions test/services/return-requirements/fetch-points.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const RegionHelper = require('../../support/helpers/region.helper.js')
// Thing under test
const FetchPointsService = require('../../../app/services/return-requirements/fetch-points.service.js')

describe('Fetch points service', () => {
describe('Return requirements Fetch Points service', () => {
let licence
let region

Expand Down Expand Up @@ -61,23 +61,25 @@ describe('Fetch points service', () => {
})
})

it('returns result', async () => {
const result = await FetchPointsService.go(licence.id)
describe('when called', () => {
it('returns result', async () => {
const result = await FetchPointsService.go(licence.id)

expect(result).to.equal([{
NGR1_EAST: '69212',
NGR2_EAST: 'null',
NGR3_EAST: 'null',
NGR4_EAST: 'null',
LOCAL_NAME: 'RIVER MEDWAY AT YALDING INTAKE',
NGR1_NORTH: '50394',
NGR1_SHEET: 'TQ',
NGR2_NORTH: 'null',
NGR2_SHEET: 'null',
NGR3_NORTH: 'null',
NGR3_SHEET: 'null',
NGR4_NORTH: 'null',
NGR4_SHEET: 'null'
}])
expect(result).to.equal([{
NGR1_EAST: '69212',
NGR2_EAST: 'null',
NGR3_EAST: 'null',
NGR4_EAST: 'null',
LOCAL_NAME: 'RIVER MEDWAY AT YALDING INTAKE',
NGR1_NORTH: '50394',
NGR1_SHEET: 'TQ',
NGR2_NORTH: 'null',
NGR2_SHEET: 'null',
NGR3_NORTH: 'null',
NGR3_SHEET: 'null',
NGR4_NORTH: 'null',
NGR4_SHEET: 'null'
}])
})
})
})
103 changes: 38 additions & 65 deletions test/services/return-requirements/submit-points.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SessionHelper = require('../../support/helpers/session.helper.js')

// Things we need to stub
const FetchPointsService = require('../../../app/services/return-requirements/fetch-points.service.js')
const PointsValidation = require('../../../app/validators/return-requirements/point.validator.js')
const PointsValidation = require('../../../app/validators/return-requirements/points.validator.js')
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved

// Thing under test
const SubmitPointsService = require('../../../app/services/return-requirements/submit-points.service.js')
Expand Down Expand Up @@ -54,38 +54,7 @@ describe('Submit Points service', () => {
]
}

Sinon.stub(FetchPointsService, 'go').resolves([
{
NGR1_EAST: '69212',
NGR2_EAST: 'null',
NGR3_EAST: 'null',
NGR4_EAST: 'null',
LOCAL_NAME: 'RIVER MEDWAY AT YALDING INTAKE',
NGR1_NORTH: '50394',
NGR1_SHEET: 'TQ',
NGR2_NORTH: 'null',
NGR2_SHEET: 'null',
NGR3_NORTH: 'null',
NGR3_SHEET: 'null',
NGR4_NORTH: 'null',
NGR4_SHEET: 'null'
},
{
NGR1_EAST: '68083',
NGR2_EAST: 'null',
NGR3_EAST: 'null',
NGR4_EAST: 'null',
LOCAL_NAME: 'BEWL WATER RESERVOIR',
NGR1_NORTH: '33604',
NGR1_SHEET: 'TQ',
NGR2_NORTH: 'null',
NGR2_SHEET: 'null',
NGR3_NORTH: 'null',
NGR3_SHEET: 'null',
NGR4_NORTH: 'null',
NGR4_SHEET: 'null'
}
])
Sinon.stub(FetchPointsService, 'go').resolves(_testFetchPointsService())

Sinon.stub(PointsValidation, 'go').resolves(null)
})
Expand Down Expand Up @@ -118,38 +87,7 @@ describe('Submit Points service', () => {
beforeEach(() => {
payload = {}

Sinon.stub(FetchPointsService, 'go').resolves([
{
NGR1_EAST: '69212',
NGR2_EAST: 'null',
NGR3_EAST: 'null',
NGR4_EAST: 'null',
LOCAL_NAME: 'RIVER MEDWAY AT YALDING INTAKE',
NGR1_NORTH: '50394',
NGR1_SHEET: 'TQ',
NGR2_NORTH: 'null',
NGR2_SHEET: 'null',
NGR3_NORTH: 'null',
NGR3_SHEET: 'null',
NGR4_NORTH: 'null',
NGR4_SHEET: 'null'
},
{
NGR1_EAST: '68083',
NGR2_EAST: 'null',
NGR3_EAST: 'null',
NGR4_EAST: 'null',
LOCAL_NAME: 'BEWL WATER RESERVOIR',
NGR1_NORTH: '33604',
NGR1_SHEET: 'TQ',
NGR2_NORTH: 'null',
NGR2_SHEET: 'null',
NGR3_NORTH: 'null',
NGR3_SHEET: 'null',
NGR4_NORTH: 'null',
NGR4_SHEET: 'null'
}
])
Sinon.stub(FetchPointsService, 'go').resolves(_testFetchPointsService())
})

it('fetches the current setup session record', async () => {
Expand Down Expand Up @@ -183,3 +121,38 @@ describe('Submit Points service', () => {
})
})
})

function _testFetchPointsService () {
return [
{
NGR1_EAST: '69212',
NGR2_EAST: 'null',
NGR3_EAST: 'null',
NGR4_EAST: 'null',
LOCAL_NAME: 'RIVER MEDWAY AT YALDING INTAKE',
NGR1_NORTH: '50394',
NGR1_SHEET: 'TQ',
NGR2_NORTH: 'null',
NGR2_SHEET: 'null',
NGR3_NORTH: 'null',
NGR3_SHEET: 'null',
NGR4_NORTH: 'null',
NGR4_SHEET: 'null'
},
{
NGR1_EAST: '68083',
NGR2_EAST: 'null',
NGR3_EAST: 'null',
NGR4_EAST: 'null',
LOCAL_NAME: 'BEWL WATER RESERVOIR',
NGR1_NORTH: '33604',
NGR1_SHEET: 'TQ',
NGR2_NORTH: 'null',
NGR2_SHEET: 'null',
NGR3_NORTH: 'null',
NGR3_SHEET: 'null',
NGR4_NORTH: 'null',
NGR4_SHEET: 'null'
}
]
}
Loading
Loading