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

Add the agreement exceptions text to the returns requirements check page #1076

Merged
merged 15 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
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
Loading