From 59ee2335947b14149d7aa44297cd375e1dcfc600 Mon Sep 17 00:00:00 2001 From: Jonathan Goulding <58443816+jonathangoulding@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:42:23 +0100 Subject: [PATCH] Add the agreement exceptions text to the returns requirements check page (#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 --- .../check/returns-requirements.presenter.js | 30 ++++++++++++ app/views/return-requirements/check.njk | 2 +- .../returns-requirements.presenter.test.js | 48 +++++++++++++++++++ .../returns-requirements.service.test.js | 1 + 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/app/presenters/return-requirements/check/returns-requirements.presenter.js b/app/presenters/return-requirements/check/returns-requirements.presenter.js index bd3985f3c9..a3058e6acb 100644 --- a/app/presenters/return-requirements/check/returns-requirements.presenter.js +++ b/app/presenters/return-requirements/check/returns-requirements.presenter.js @@ -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 @@ -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 = [] @@ -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, diff --git a/app/views/return-requirements/check.njk b/app/views/return-requirements/check.njk index a71b5eaf59..2ef5a64a6a 100644 --- a/app/views/return-requirements/check.njk +++ b/app/views/return-requirements/check.njk @@ -249,7 +249,7 @@ text: "Agreements exceptions" }, value: { - html: "requirement.agreementsExceptions" + text: requirement.agreementsExceptions }, actions: { items: [ diff --git a/test/presenters/return-requirements/check/returns-requirements.presenter.test.js b/test/presenters/return-requirements/check/returns-requirements.presenter.test.js index 94f65a777c..1d50590f15 100644 --- a/test/presenters/return-requirements/check/returns-requirements.presenter.test.js +++ b/test/presenters/return-requirements/check/returns-requirements.presenter.test.js @@ -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, @@ -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, @@ -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)', () => { diff --git a/test/services/return-requirements/check/returns-requirements.service.test.js b/test/services/return-requirements/check/returns-requirements.service.test.js index ccdc44eba2..1c5e7654e0 100644 --- a/test/services/return-requirements/check/returns-requirements.service.test.js +++ b/test/services/return-requirements/check/returns-requirements.service.test.js @@ -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,