Skip to content

Commit

Permalink
Merge branch 'main' into WATER-4306-select-additional-submission-opti…
Browse files Browse the repository at this point in the history
…ons-page-layout-and-controls
  • Loading branch information
Demwunz authored May 16, 2024
2 parents 258e1cd + 7bf5dae commit 747d4a1
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/controllers/return-requirements.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async function submitReason (request, h) {
async function submitRemove (request, h) {
const { requirementIndex, sessionId } = request.params

await SubmitRemoveService.go(sessionId, requirementIndex)
await SubmitRemoveService.go(sessionId, requirementIndex, request.yar)

return h.redirect(`/system/return-requirements/${sessionId}/check`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function _persistAmendedAdjustmentFactor (reviewChargeReferenceId, payload
}

function _validate (payload) {
const maxDecimalsForAggregateValue = 2
const maxDecimalsForAggregateValue = 15
const maxDecimalsForChargeAdjustmentValue = 15

const aggregateValidation = AdjustmentFactorValidator.go(
Expand Down
11 changes: 10 additions & 1 deletion app/services/return-requirements/submit-remove.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ const SessionModel = require('../../models/session.model.js')
* is deleted from the session in the database.
*
* @param {string} sessionId - The UUID for the return requirement setup session record
* @param {number} requirementIndex - The index of the requirement being removed
* @param {Object} yar - The Hapi `request.yar` session manager passed on by the controller
*
* @returns {Promise} the promise returned is not intended to resolve to any particular value
*/
async function go (sessionId, requirementIndex) {
async function go (sessionId, requirementIndex, yar) {
const session = await SessionModel.query().findById(sessionId)

const notification = {
title: 'Removed',
text: 'Requirement removed'
}

yar.flash('notification', notification)

return _removeRequirementFromSession(session, requirementIndex)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function _customValidation (quantity, helpers, maxNumberOfDecimals, validationTy
}

return helpers.message({
custom: `The ${validationType} must contain no more than ${maxNumberOfDecimals} decimal places`
custom: `The ${validationType} factor must not have more than ${maxNumberOfDecimals} decimal places`
})
}

Expand All @@ -60,7 +60,7 @@ function _validate (quantity, maxNumberOfDecimals, validationType) {
'number.base': `The ${validationType} factor must be a number`,
'number.unsafe': `The ${validationType} factor must be a number`,
'number.min': `The ${validationType} factor must be greater than 0`,
'number.max': `The ${validationType} factor must be less than 1`,
'number.max': `The ${validationType} factor must be equal to or less than 1`,
'any.required': `Enter a ${validationType} factor`
})
})
Expand Down
2 changes: 1 addition & 1 deletion app/views/licences/tabs/contact-details.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h2 class="govuk-heading-l">Contact Details</h2>
<h2 class="govuk-heading-l">Contact details</h2>

{% if customerId %}
<p><a href='/customer/{{ customerId }}/#contacts'>Go to customer contacts</a></p>
Expand Down
9 changes: 7 additions & 2 deletions app/views/return-requirements/check.njk
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@
{# Set an easier to use index #}
{% set rowIndex = loop.index0 %}
<div>
<h3>{{requirement.siteDescription}}</h3>
<p>Remove {{rowIndex}} </p>
<h3 class="govuk-body">{{requirement.siteDescription}}</h3>
{{ govukButton({
text: "Remove requirement",
classes: "govuk-button--warning",
preventDoubleClick: true,
href: "/system/return-requirements/" + sessionId + "/remove/" + rowIndex
}) }}
</div>
{% endfor %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/return-requirements/points.njk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
titleText: "There is a problem",
errorList: [
{
text: "Select any points for the return requirement",
text: error.text,
href: "#points"
}
]
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/licences.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe('Licences controller', () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Contact Details')
expect(response.payload).to.contain('Contact details')
// Table row titles
expect(response.payload).to.contain('Name')
expect(response.payload).to.contain('Communication type')
Expand All @@ -242,7 +242,7 @@ describe('Licences controller', () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Contact Details')
expect(response.payload).to.contain('Contact details')
expect(response.payload).to.contain('No contacts found.')
})
})
Expand Down
17 changes: 16 additions & 1 deletion test/services/return-requirements/submit-remove.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Test framework dependencies
const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const Sinon = require('sinon')

const { describe, it, beforeEach } = exports.lab = Lab.script()
const { expect } = Code
Expand All @@ -18,6 +19,7 @@ describe('Return Requirements - Submit Remove service', () => {
const requirementIndex = 0

let session
let yarStub

beforeEach(async () => {
await DatabaseSupport.clean()
Expand Down Expand Up @@ -60,15 +62,28 @@ describe('Return Requirements - Submit Remove service', () => {
reason: 'major-change'
}
})

yarStub = {
flash: Sinon.stub()
}
})

describe('when a user submits the return requirements to be removed', () => {
it('deletes the selected requirement from the session data', async () => {
await SubmitRemoveService.go(session.id, requirementIndex)
await SubmitRemoveService.go(session.id, requirementIndex, yarStub)

const refreshedSession = await session.$query()

expect(refreshedSession.requirements[requirementIndex]).not.to.exist()
})

it("sets the notification message to 'Requirements removed'", async () => {
await SubmitRemoveService.go(session.id, requirementIndex, yarStub)

const [flashType, notification] = yarStub.flash.args[0]

expect(flashType).to.equal('notification')
expect(notification).to.equal({ title: 'Removed', text: 'Requirement removed' })
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const { expect } = Code
const AdjustmentFactorValidator = require('../../../../app/validators/bill-runs/two-part-tariff/adjustment-factor.validator.js')

describe('Adjustment Factor validator', () => {
const maxNumberOfDecimals = 15

let payload
let maxNumberOfDecimals
let validationType

describe('when a valid payload is provided', () => {
Expand All @@ -22,7 +23,6 @@ describe('Adjustment Factor validator', () => {
amendedAggregateFactor: 0.5
}

maxNumberOfDecimals = 2
validationType = 'aggregate'
})

Expand All @@ -39,12 +39,15 @@ describe('Adjustment Factor validator', () => {
amendedChargeAdjustment: 0.5
}

maxNumberOfDecimals = 15
validationType = 'charge'
})

it('confirms the payload is valid', () => {
const result = AdjustmentFactorValidator.go(payload.amendedChargeAdjustment, maxNumberOfDecimals, validationType)
const result = AdjustmentFactorValidator.go(
payload.amendedChargeAdjustment,
maxNumberOfDecimals,
validationType
)

expect(result.error).not.to.exist()
})
Expand All @@ -56,7 +59,6 @@ describe('Adjustment Factor validator', () => {
beforeEach(() => {
payload = undefined

maxNumberOfDecimals = 2
validationType = 'aggregate'
})

Expand All @@ -74,7 +76,6 @@ describe('Adjustment Factor validator', () => {
amendedAggregateFactor: 'Hello World'
}

maxNumberOfDecimals = 2
validationType = 'aggregate'
})

Expand All @@ -89,18 +90,19 @@ describe('Adjustment Factor validator', () => {
describe('because the user entered too many decimal places', () => {
beforeEach(() => {
payload = {
amendedAggregateFactor: 0.555
amendedAggregateFactor: 0.1234567890123456
}

maxNumberOfDecimals = 2
validationType = 'aggregate'
})

it("fails the validation with the message 'The aggregate must contain no more than 2 decimal places'", () => {
it("fails the validation with the message 'The aggregate factor must not have more than 15 decimal places'", () => {
const result = AdjustmentFactorValidator.go(payload.amendedAggregateFactor, maxNumberOfDecimals, validationType)

expect(result.error).to.exist()
expect(result.error.details[0].message).to.equal('The aggregate must contain no more than 2 decimal places')
expect(result.error.details[0].message).to.equal(
'The aggregate factor must not have more than 15 decimal places'
)
})
})

Expand All @@ -110,15 +112,14 @@ describe('Adjustment Factor validator', () => {
amendedAggregateFactor: 1.1
}

maxNumberOfDecimals = 2
validationType = 'aggregate'
})

it("fails the validation with the message 'The aggregate factor must be less than 1'", () => {
it("fails the validation with the message 'The aggregate factor must be equal to or less than 1'", () => {
const result = AdjustmentFactorValidator.go(payload.amendedAggregateFactor, maxNumberOfDecimals, validationType)

expect(result.error).to.exist()
expect(result.error.details[0].message).to.equal('The aggregate factor must be less than 1')
expect(result.error.details[0].message).to.equal('The aggregate factor must be equal to or less than 1')
})
})

Expand All @@ -128,7 +129,6 @@ describe('Adjustment Factor validator', () => {
amendedAggregateFactor: -1
}

maxNumberOfDecimals = 2
validationType = 'aggregate'
})

Expand All @@ -146,7 +146,6 @@ describe('Adjustment Factor validator', () => {
beforeEach(() => {
payload = undefined

maxNumberOfDecimals = 15
validationType = 'charge'
})

Expand All @@ -164,7 +163,6 @@ describe('Adjustment Factor validator', () => {
amendedChargeFactor: 'Hello World'
}

maxNumberOfDecimals = 15
validationType = 'charge'
})

Expand All @@ -182,15 +180,14 @@ describe('Adjustment Factor validator', () => {
amendedChargeFactor: 0.5555555555555555
}

maxNumberOfDecimals = 15
validationType = 'charge'
})

it("fails the validation with the message 'The charge must contain no more than 2 decimal places'", () => {
it("fails the validation with the message 'The charge factor must not have more than 15 decimal places'", () => {
const result = AdjustmentFactorValidator.go(payload.amendedChargeFactor, maxNumberOfDecimals, validationType)

expect(result.error).to.exist()
expect(result.error.details[0].message).to.equal('The charge must contain no more than 15 decimal places')
expect(result.error.details[0].message).to.equal('The charge factor must not have more than 15 decimal places')
})
})

Expand All @@ -200,15 +197,14 @@ describe('Adjustment Factor validator', () => {
amendedChargeFactor: 1.1
}

maxNumberOfDecimals = 15
validationType = 'charge'
})

it("fails the validation with the message 'The charge factor must be less than 1'", () => {
it("fails the validation with the message 'The charge factor must be equal to or less than 1'", () => {
const result = AdjustmentFactorValidator.go(payload.amendedChargeFactor, maxNumberOfDecimals, validationType)

expect(result.error).to.exist()
expect(result.error.details[0].message).to.equal('The charge factor must be less than 1')
expect(result.error.details[0].message).to.equal('The charge factor must be equal to or less than 1')
})
})

Expand All @@ -218,7 +214,6 @@ describe('Adjustment Factor validator', () => {
amendedChargeFactor: -1
}

maxNumberOfDecimals = 15
validationType = 'charge'
})

Expand Down

0 comments on commit 747d4a1

Please sign in to comment.