Skip to content

Commit

Permalink
Update the view return version presenter
Browse files Browse the repository at this point in the history
Didn't spot at the time it was doing it's won implementation of `formatAbstractionPeriod()`. So, we update it to use the common one in `base.presenter.js`.

We also didn't spot it was using the legacy pattern, of sometimes prefixing dates with `From ...`. Again, using the common method in the base presenter helps us stick to a common pattern.
  • Loading branch information
Cruikshanks committed Jan 23, 2025
1 parent 2fb67f0 commit 154fdb9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
15 changes: 8 additions & 7 deletions app/presenters/return-versions/view.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module ViewPresenter
*/

const { formatAbstractionDate } = require('../base.presenter.js')
const { formatAbstractionPeriod } = require('../base.presenter.js')
const { formatLongDate } = require('../base.presenter.js')
const { isQuarterlyReturnSubmissions } = require('../../lib/dates.lib.js')
const { returnRequirementReasons, returnRequirementFrequencies } = require('../../lib/static-lookups.lib.js')
Expand Down Expand Up @@ -39,13 +39,14 @@ function go(returnVersion) {
}

function _abstractionPeriod(requirement) {
const { abstractionPeriodStartDay, abstractionPeriodStartMonth, abstractionPeriodEndDay, abstractionPeriodEndMonth } =
requirement

const startDate = formatAbstractionDate(abstractionPeriodStartDay, abstractionPeriodStartMonth)
const endDate = formatAbstractionDate(abstractionPeriodEndDay, abstractionPeriodEndMonth)
const abstractionPeriod = formatAbstractionPeriod(
requirement.abstractionPeriodStartDay,
requirement.abstractionPeriodStartMonth,
requirement.abstractionPeriodEndDay,
requirement.abstractionPeriodEndMonth
)

return `From ${startDate} to ${endDate}`
return abstractionPeriod ?? ''
}

function _agreementsExceptions(returnRequirement) {
Expand Down
29 changes: 23 additions & 6 deletions test/presenters/return-versions/view.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ReturnVersionModel = require('../../../app/models/return-version.model.js'
// Thing under test
const ViewPresenter = require('../../../app/presenters/return-versions/view.presenter.js')

describe('Return Versions - View presenter', () => {
describe.only('Return Versions - View presenter', () => {
let returnVersion

beforeEach(() => {
Expand All @@ -39,7 +39,7 @@ describe('Return Versions - View presenter', () => {
reason: 'New licence',
requirements: [
{
abstractionPeriod: 'From 1 April to 31 October',
abstractionPeriod: '1 April to 31 October',
agreementsExceptions: 'None',
frequencyCollected: 'monthly',
frequencyReported: 'monthly',
Expand Down Expand Up @@ -205,12 +205,29 @@ describe('Return Versions - View presenter', () => {

describe('the "requirements" property', () => {
describe('the requirements "abstractionPeriod" property', () => {
it('formats the abstraction period for display', () => {
const result = ViewPresenter.go(returnVersion)
describe('when the abstraction period has been set', () => {
it('formats the abstraction period for display', () => {
const result = ViewPresenter.go(returnVersion)

const { abstractionPeriod } = result.requirements[0]

expect(abstractionPeriod).to.equal('1 April to 31 October')
})
})

const { abstractionPeriod } = result.requirements[0]
describe('when the abstraction period has not been set', () => {
beforeEach(() => {
returnVersion.returnRequirements[0].abstractionPeriodEndDay = null
returnVersion.returnRequirements[0].abstractionPeriodEndMonth = null
returnVersion.returnRequirements[0].abstractionPeriodStartDay = null
returnVersion.returnRequirements[0].abstractionPeriodStartMonth = null
})

it('returns an empty string', () => {
const result = ViewPresenter.go(returnVersion)

expect(abstractionPeriod).to.equal('From 1 April to 31 October')
expect(result.requirements[0].abstractionPeriod).to.equal('')
})
})
})

Expand Down

0 comments on commit 154fdb9

Please sign in to comment.