Skip to content

Commit

Permalink
Add the agreement exceptions text to the returns requirements check p…
Browse files Browse the repository at this point in the history
…age (#1076)

* Add the agreement exceptions text to the returns requirements check page

Due to the estimated complexity of adding fetch services for purposes, points and other display items. We have broken down the complex display items into their own branches of work.

https://eaflood.atlassian.net/browse/WATER-4386

This branch will add agreement exceptions to the return requirement summary card. This will be a comma seperated list in the oxford comma style.

Previous work done here - #1019

Co-authored-by: Alan Cruikshanks <[email protected]>
  • Loading branch information
jonathangoulding and Cruikshanks authored Jun 7, 2024
1 parent af57bbf commit 59ee233
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
const { formatAbstractionDate } = require('../../base.presenter.js')
const { generateAbstractionPointDetail } = require('../../../lib/general.lib.js')

const agreementsExceptionsText = {
none: 'None',
'gravity-fill': 'Gravity fill',
'transfer-re-abstraction-scheme': 'Transfer re-abstraction scheme',
'two-part-tariff': 'Two-part tariff',
'56-returns-exception': '56 returns exception'
}

/**
* Formats return requirements data for the `/return-requirements/{sessionId}/check` page
* @module ReturnRequirementsPresenter
Expand Down Expand Up @@ -39,6 +47,27 @@ function _abstractionPeriod (abstractionPeriod) {
return `From ${startDate} to ${endDate}`
}

function _agreementsExceptions (agreementsExceptions) {
if (agreementsExceptions[0] === agreementsExceptionsText.none) {
return 'None'
}

const formattedExceptions = agreementsExceptions.map((exception) => {
return agreementsExceptionsText[exception]
})

if (formattedExceptions.length === 1) {
return formattedExceptions[0]
}

if (formattedExceptions.length === 2) {
return formattedExceptions.join(' and ')
}

return formattedExceptions.slice(0, formattedExceptions.length - 1)
.join(', ') + ', and ' + formattedExceptions[formattedExceptions.length - 1]
}

function _requirements (requirements, purposes, points) {
const completedRequirements = []

Expand Down Expand Up @@ -67,6 +96,7 @@ function _mapPurposes (requirementPurposes, purposes) {
function _mapRequirement (requirement, index, purposes, points) {
return {
abstractionPeriod: _abstractionPeriod(requirement.abstractionPeriod),
agreementsExceptions: _agreementsExceptions(requirement.agreementsExceptions),
frequencyCollected: requirement.frequencyCollected,
frequencyReported: requirement.frequencyReported,
index,
Expand Down
2 changes: 1 addition & 1 deletion app/views/return-requirements/check.njk
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
text: "Agreements exceptions"
},
value: {
html: "requirement.agreementsExceptions"
text: requirement.agreementsExceptions
},
actions: {
items: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('Return Requirements presenter', () => {
returnsRequired: false,
requirements: [{
abstractionPeriod: 'From 1 June to 1 March',
agreementsExceptions: 'Gravity fill',
frequencyCollected: 'daily',
frequencyReported: 'daily',
index: 0,
Expand All @@ -93,6 +94,7 @@ describe('Return Requirements presenter', () => {

expect(result.requirements).to.equal([{
abstractionPeriod: 'From 1 June to 1 March',
agreementsExceptions: 'Gravity fill',
frequencyCollected: 'daily',
frequencyReported: 'daily',
index: 0,
Expand Down Expand Up @@ -141,6 +143,52 @@ describe('Return Requirements presenter', () => {
})
})
})

describe('and the agreement exceptions', () => {
describe('is "none"', () => {
beforeEach(() => {
requirements = [{ ...requirement, agreementsExceptions: ['none'] }]
})

it('should return "None"', () => {
const result = ReturnRequirementsPresenter.go(requirements, purposes, points, journey)

expect(result.requirements[0].agreementsExceptions).to.equal('None')
})
})

describe('has one exception', () => {
it('should return the exception as "Gravity fill"', () => {
const result = ReturnRequirementsPresenter.go(requirements, purposes, points, journey)

expect(result.requirements[0].agreementsExceptions).to.equal('Gravity fill')
})
})

describe('has two exceptions', () => {
beforeEach(() => {
requirements = [{ ...requirement, agreementsExceptions: ['gravity-fill', 'transfer-re-abstraction-scheme'] }]
})

it('should return the exceptions as "Gravity fill and Transfer re-abstraction scheme"', () => {
const result = ReturnRequirementsPresenter.go(requirements, purposes, points, journey)

expect(result.requirements[0].agreementsExceptions).to.equal('Gravity fill and Transfer re-abstraction scheme')
})
})

describe('has more than two exceptions', () => {
beforeEach(() => {
requirements = [{ ...requirement, agreementsExceptions: ['gravity-fill', 'transfer-re-abstraction-scheme', 'two-part-tariff', '56-returns-exception'] }]
})

it('should return the exceptions as "Gravity fill, Transfer re-abstraction scheme, Two-part tariff, and 56 returns exception"', () => {
const result = ReturnRequirementsPresenter.go(requirements, purposes, points, journey)

expect(result.requirements[0].agreementsExceptions).to.equal('Gravity fill, Transfer re-abstraction scheme, Two-part tariff, and 56 returns exception')
})
})
})
})

describe('when the requirement is "incomplete" (agreements exceptions is not populated)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('Return Requirements service', () => {
expect(result).to.equal({
requirements: [{
abstractionPeriod: 'From 1 June to 1 March',
agreementsExceptions: 'Gravity fill',
frequencyCollected: 'daily',
frequencyReported: 'daily',
index: 0,
Expand Down

0 comments on commit 59ee233

Please sign in to comment.