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

Persist and retrieve rtn-req set up session values #814

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1e22fc5
Persist and retrieve rtn req set up session values
Demwunz Mar 13, 2024
2f817db
Merge branch 'main' into WATER-4384-persist-and-retrieve-rtn-req-set-…
Demwunz Mar 21, 2024
e44468c
Merge branch 'main' into WATER-4384-persist-and-retrieve-rtn-req-set-…
Demwunz Mar 22, 2024
ced8c2f
feat(app): added persistent data to session
Demwunz Mar 22, 2024
2d238fc
feat(app): show date from session
Demwunz Mar 22, 2024
2f09376
feat(app): make variable names consistent
Demwunz Mar 25, 2024
92629b8
feat(app): update tests
Demwunz Mar 26, 2024
d7eb2d8
Merge branch 'main' into WATER-4384-persist-and-retrieve-rtn-req-set-…
Demwunz Mar 26, 2024
72e39cf
feat(app): update check your answers test
Demwunz Mar 26, 2024
9ee1e4c
Merge branch 'main' into WATER-4384-persist-and-retrieve-rtn-req-set-…
Demwunz Mar 26, 2024
b000f38
Merge branch 'main' into WATER-4384-persist-and-retrieve-rtn-req-set-…
Demwunz Mar 27, 2024
ea7aca2
feat(app): removed unnecessary func
Demwunz Mar 27, 2024
abecef4
Update app/presenters/return-requirements/check-your-answers.presente…
Demwunz Mar 27, 2024
dab0558
Update app/presenters/return-requirements/check-your-answers.presente…
Demwunz Mar 27, 2024
b9dd135
Update app/services/return-requirements/check-your-answers.service.js
Demwunz Mar 27, 2024
8232caf
Update app/services/return-requirements/submit-no-returns-required.se…
Demwunz Mar 27, 2024
f343dbf
Update app/services/return-requirements/submit-purpose.service.js
Demwunz Mar 27, 2024
3ee51a5
Update app/services/return-requirements/submit-reason.service.js
Demwunz Mar 27, 2024
657a3b2
Update app/services/return-requirements/submit-setup.service.js
Demwunz Mar 27, 2024
9a0f94f
fix(app): simplify test
Demwunz Mar 27, 2024
9fe416a
fix(app): various test amends
Demwunz Mar 28, 2024
aa10a68
Merge branch 'main' into WATER-4384-persist-and-retrieve-rtn-req-set-…
robertparkinson Apr 2, 2024
c37836b
Merge branch 'main' into WATER-4384-persist-and-retrieve-rtn-req-set-…
Demwunz Apr 3, 2024
52d4c20
fix(app): readjusted test for legibility
Demwunz Apr 3, 2024
360806d
Update test/presenters/return-requirements/check-your-answers.present…
Demwunz Apr 3, 2024
4826f11
fix(app): restore whitespace
Demwunz Apr 3, 2024
2062d14
Merge branch 'main' into WATER-4384-persist-and-retrieve-rtn-req-set-…
Demwunz Apr 3, 2024
065a56f
fix(app): restore whitespace
Demwunz Apr 4, 2024
6b0fd44
Merge branch 'main' into WATER-4384-persist-and-retrieve-rtn-req-set-…
Demwunz Apr 4, 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
1 change: 0 additions & 1 deletion app/controllers/return-requirements.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ async function approved (request, h) {

async function checkYourAnswers (request, h) {
const { sessionId } = request.params

const pageData = await CheckYourAnswersService.go(sessionId)

return h.view('return-requirements/check-your-answers.njk', {
Expand Down
26 changes: 24 additions & 2 deletions app/presenters/return-requirements/check-your-answers.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,38 @@
* Formats data for the `/return-requirements/{sessionId}/check-your-answers` page
* @module CheckYourAnswersPresenter
*/

const { formatLongDate } = require('../base.presenter.js')
Demwunz marked this conversation as resolved.
Show resolved Hide resolved
function go (session) {
const data = {
id: session.id,
licenceRef: session.data.licence.licenceRef
journey: session.data.journey,
licenceRef: session.data.licence.licenceRef,
reason: session.data.reason,
startDate: _startDate(session.data)
}

return data
}

function _startDate (sessionData) {
const selectedOption = sessionData.startDateOptions
let date

if (selectedOption === 'licenceStartDate') {
date = new Date(sessionData.licence.currentVersionStartDate)
}

if (selectedOption === 'anotherStartDate') {
Demwunz marked this conversation as resolved.
Show resolved Hide resolved
const day = sessionData.startDateDay
const month = sessionData.startDateMonth
const year = sessionData.startDateYear

date = new Date(`${year}-${month}-${day}`)
}

return formatLongDate(date)
}

module.exports = {
go
}
20 changes: 10 additions & 10 deletions app/presenters/return-requirements/start-date.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Formats data for the `/return-requirements/{sessionId}/start-date` page
* @module StartDatedPresenter
* @module StartDatePresenter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 👍

*/

const { formatLongDate } = require('../base.presenter.js')
Expand All @@ -15,13 +15,13 @@ const { formatLongDate } = require('../base.presenter.js')
*
* @returns {Object} The data formatted for the view template
*/
function go (session, payload = {}) {
function go (session) {
const data = {
id: session.id,
licenceId: session.data.licence.id,
licenceRef: session.data.licence.licenceRef,
licenceVersionStartDate: _licenceVersionStartDate(session.data.licence.currentVersionStartDate),
..._transformPayload(payload)
..._transformSession(session.data)
}

return data
Expand All @@ -36,13 +36,13 @@ function _licenceVersionStartDate (date) {
return formattedDate
}

function _transformPayload (payload) {
// NOTE: 'start-date-options' is the payload value that tells us whether the user selected the licence version start
function _transformSession (sessionData) {
// NOTE: 'startDateOptions' is the session value that tells us whether the user selected the licence version start
// date or another date radio button.
// If it is not set then either its because the presenter has been called from `StartDateService` and it's the first
// load. Else its been called by `SubmitStartDateService` but the user hasn't selected a radio button.
// Either way, we use it to tell us whether there is anything in the payload worth transforming.
const selectedOption = payload['start-date-options']
// Either way, we use it to tell us whether there is anything in the session worth transforming.
const selectedOption = sessionData.startDateOptions

if (!selectedOption) {
return {
Expand All @@ -55,9 +55,9 @@ function _transformPayload (payload) {
}

return {
anotherStartDateDay: payload['start-date-day'],
anotherStartDateMonth: payload['start-date-month'],
anotherStartDateYear: payload['start-date-year'],
anotherStartDateDay: sessionData.startDateDay,
anotherStartDateMonth: sessionData.startDateMonth,
anotherStartDateYear: sessionData.startDateYear,
anotherStartDateSelected: selectedOption === 'anotherStartDate',
licenceStartDateSelected: selectedOption === 'licenceStartDate'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const SessionModel = require('../../models/session.model.js')
*/
async function go (sessionId) {
const session = await SessionModel.query().findById(sessionId)
const formattedData = CheckYourAnswersPresenter.go(session)

const formattedData = CheckYourAnswersPresenter.go(session)
Demwunz marked this conversation as resolved.
Show resolved Hide resolved
return {
activeNavBar: 'search',
licenceRef: session.data.licence.licenceRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ const SessionModel = require('../../models/session.model.js')
*/
async function go (sessionId, payload) {
const session = await SessionModel.query().findById(sessionId)

const validationResult = _validate(payload)

if (!validationResult) {
await _save(session, payload)
return {
Demwunz marked this conversation as resolved.
Show resolved Hide resolved
journey: session.data.journey
}
}

const formattedData = NoReturnsRequiredPresenter.go(session, payload)

return {
Expand All @@ -38,6 +44,14 @@ async function go (sessionId, payload) {
}
}

async function _save (session, payload) {
const currentData = session.data

currentData.reason = payload.reason

return session.$query().patch({ data: currentData })
}

function _validate (payload) {
const validation = NoReturnsRequiredValidator.go(payload)

Expand Down
14 changes: 14 additions & 0 deletions app/services/return-requirements/submit-purpose.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ async function go (sessionId, payload) {

const purposesData = await FetchPurposesService.go(session.data.licence.id)
const validationResult = _validate(payload)

if (!validationResult) {
await _save(session, payload)
return {}
Demwunz marked this conversation as resolved.
Show resolved Hide resolved
}

const formattedData = SelectPurposePresenter.go(session, purposesData, payload)

return {
Expand All @@ -39,6 +45,14 @@ async function go (sessionId, payload) {
}
}

async function _save (session, payload) {
const currentData = session.data

currentData.purpose = payload.purpose

return session.$query().patch({ data: currentData })
}

function _validate (payload) {
const validation = PurposeValidation.go(payload)

Expand Down
13 changes: 13 additions & 0 deletions app/services/return-requirements/submit-reason.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ async function go (sessionId, payload) {

const validationResult = _validate(payload)

if (!validationResult) {
await _save(session, payload)
return {}
Demwunz marked this conversation as resolved.
Show resolved Hide resolved
}

const formattedData = ReasonPresenter.go(session, payload)

return {
Expand All @@ -38,6 +43,14 @@ async function go (sessionId, payload) {
}
}

async function _save (session, payload) {
const currentData = session.data

currentData.reason = payload.reason

return session.$query().patch({ data: currentData })
}

function _validate (payload) {
const validation = ReasonValidator.go(payload)

Expand Down
16 changes: 15 additions & 1 deletion app/services/return-requirements/submit-setup.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ async function go (sessionId, payload) {

const validationResult = _validate(payload)

if (!validationResult) {
await _save(session, payload)
return {
Demwunz marked this conversation as resolved.
Show resolved Hide resolved
redirect: _redirect(payload.setup)
}
}

const formattedData = SetupPresenter.go(session, payload)

return {
activeNavBar: 'search',
error: validationResult,
pageTitle: 'How do you want to set up the return requirement?',
redirect: _redirect(payload.setup),
...formattedData
}
}
Expand All @@ -53,6 +59,14 @@ function _redirect (setup) {
return endpoint
}

async function _save (session, payload) {
const currentData = session.data

currentData.setup = payload.setup

return session.$query().patch({ data: currentData })
}

function _validate (payload) {
const validation = SetupValidator.go(payload)

Expand Down
22 changes: 22 additions & 0 deletions app/services/return-requirements/submit-start-date.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ async function go (sessionId, payload) {
const { endDate, startDate } = session.data.licence
const validationResult = _validate(payload, startDate, endDate)

if (!validationResult) {
await _save(session, payload)
return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just whitespace

Suggested change
await _save(session, payload)
return {
await _save(session, payload)
return {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one still doesn't look to be resolved.

journey: session.data.journey
}
}

const formattedData = StartDatePresenter.go(session, payload)

return {
Expand All @@ -41,6 +48,21 @@ async function go (sessionId, payload) {
}
}

async function _save (session, payload) {
const currentData = session.data
const selectedOption = payload['start-date-options']

currentData.startDateOptions = selectedOption

if (selectedOption === 'anotherStartDate') {
currentData.startDateDay = payload['start-date-day']
currentData.startDateMonth = payload['start-date-month']
currentData.startDateYear = payload['start-date-year']
}

return session.$query().patch({ data: currentData })
}

function _validate (payload, licenceStartDate, licenceEndDate) {
const validation = StartDateValidator.go(payload, licenceStartDate, licenceEndDate)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
const Joi = require('joi')

const VALID_VALUES = [
'abstraction_below_100_cubic_metres_per_day',
'returns_exception',
'transfer_licence'
'abstraction-below-100-cubic-metres-per-day',
'returns-exception',
'transfer-licence'
]

/**
Expand All @@ -23,7 +23,7 @@ const VALID_VALUES = [
*/
function go (data) {
const schema = Joi.object({
'no-returns-required': Joi.string()
reason: Joi.string()
.required()
.valid(...VALID_VALUES)
.messages({
Expand Down
22 changes: 11 additions & 11 deletions app/validators/return-requirements/reason.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
const Joi = require('joi')

const VALID_VALUES = [
'change_to_special_agreement',
'name_or_address_change',
'transfer_and_now_chargeable',
'extension_of_licence_validity',
'major_change',
'minor_change',
'new_licence_in_part_succession_or_licence_apportionment',
'new_licence',
'new_special_agreement',
'succession_or_transfer_of_licence',
'succession_to_remainder_licence_or_licence_apportionment'
'change-to-special-agreement',
'name-or-address-change',
'transfer-and-now-chargeable',
'extension-of-licence-validity',
'major-change',
'minor-change',
'new-licence-in-part-succession-or-licence-apportionment',
'new-licence',
'new-special-agreement',
'succession-or-transfer-of-licence',
'succession-to-remainder-licence-or-licence-apportionment'
]

/**
Expand Down
Loading
Loading