Skip to content

Commit

Permalink
Use existing helpers in view bill page (#1756)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4201

> Part of the work to support two-part tariff bill runs

Spotted whilst adding support for two_part_supplementary bill runs. Our view bill page displays the bill run type. When we generated a two-part tariff supplementary bill run, we saw that the type was displayed incorrectly in the view. When we checked we found it was like PR's #1562 and #1747, where a view was not taking advantage of the available helpers.

This change updates the view bill presenter to take advantage of them, which also resolves our bill run type issue!
  • Loading branch information
Cruikshanks authored Feb 28, 2025
1 parent 0921721 commit 68db9b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 136 deletions.
47 changes: 11 additions & 36 deletions app/presenters/bills/view-bill.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
* @module ViewBillPresenter
*/

const { formatLongDate, formatMoney, titleCase } = require('../base.presenter.js')
const {
formatBillRunType,
formatChargeScheme,
formatFinancialYear,
formatLongDate,
formatMoney,
titleCase
} = require('../base.presenter.js')

/**
* Formats bill and billing account data ready for presenting in the single licence bill and multi licence bill pages
Expand All @@ -29,17 +36,17 @@ function go(bill, billingAccount) {
billRunId: billRun.id,
billRunNumber: billRun.billRunNumber,
billRunStatus: billRun.status,
billRunType: _billRunType(billRun),
billRunType: formatBillRunType(billRun.batchType, billRun.scheme, billRun.summer),
billTotal: _billTotal(bill.netAmount, bill.credit),
chargeScheme: _scheme(billRun),
chargeScheme: formatChargeScheme(billRun.scheme),
contactName: billingAccount.$contactName(),
credit: bill.credit,
creditsTotal: _creditsTotal(bill, billRun),
dateCreated: formatLongDate(bill.createdAt),
debitsTotal: _debitsTotal(bill, billRun),
deminimis: bill.deminimis,
displayCreditDebitTotals: _displayCreditDebitTotals(billRun),
financialYear: _financialYear(bill),
financialYear: formatFinancialYear(bill.financialYearEnding),
flaggedForReissue: bill.flaggedForRebilling,
pageTitle: `Bill for ${accountName}`,
region: titleCase(billRun.region.displayName),
Expand All @@ -49,24 +56,6 @@ function go(bill, billingAccount) {
return formattedBill
}

function _billRunType(billRun) {
const { batchType, summer, scheme } = billRun

if (batchType !== 'two_part_tariff') {
return titleCase(batchType)
}

if (scheme === 'sroc') {
return 'Two-part tariff'
}

if (summer) {
return 'Two-part tariff summer'
}

return 'Two-part tariff winter and all year'
}

function _creditsTotal(bill, billRun) {
const { creditNoteValue, netAmount } = bill
const { source } = billRun
Expand Down Expand Up @@ -103,20 +92,6 @@ function _displayCreditDebitTotals(billRun) {
return batchType === 'supplementary'
}

function _financialYear(bill) {
const { financialYearEnding } = bill

return `${financialYearEnding - 1} to ${financialYearEnding}`
}

function _scheme(billRun) {
if (billRun.scheme === 'sroc') {
return 'Current'
}

return 'Old'
}

function _billTotal(valueInPence, credit) {
const valueAsMoney = formatMoney(valueInPence)

Expand Down
100 changes: 0 additions & 100 deletions test/presenters/bills/view-bill.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,68 +54,6 @@ describe('View Bill presenter', () => {
})
})

describe('the "billRunType" property', () => {
describe('when the bill run is annual', () => {
it('returns Annual', () => {
const result = ViewBillPresenter.go(bill, billingAccount)

expect(result.billRunType).to.equal('Annual')
})
})

describe('when the bill run is supplementary', () => {
beforeEach(() => {
bill.billRun.batchType = 'supplementary'
})

it('returns Supplementary', () => {
const result = ViewBillPresenter.go(bill, billingAccount)

expect(result.billRunType).to.equal('Supplementary')
})
})

describe('when the bill run is two_part_tariff', () => {
beforeEach(() => {
bill.billRun.batchType = 'two_part_tariff'
})

describe('and the scheme is sroc', () => {
it('returns Supplementary', () => {
const result = ViewBillPresenter.go(bill, billingAccount)

expect(result.billRunType).to.equal('Two-part tariff')
})
})

describe('and the scheme is alcs', () => {
beforeEach(() => {
bill.billRun.scheme = 'alcs'
})

describe('and it is not summer only', () => {
it('returns Supplementary', () => {
const result = ViewBillPresenter.go(bill, billingAccount)

expect(result.billRunType).to.equal('Two-part tariff winter and all year')
})
})

describe('and it is for summer only', () => {
beforeEach(() => {
bill.billRun.summer = true
})

it('returns Supplementary', () => {
const result = ViewBillPresenter.go(bill, billingAccount)

expect(result.billRunType).to.equal('Two-part tariff summer')
})
})
})
})
})

describe('the "billTotal" property', () => {
describe('when the bill is a debit', () => {
it('returns just the bill total formatted as money', () => {
Expand All @@ -138,28 +76,6 @@ describe('View Bill presenter', () => {
})
})

describe('the "chargeScheme" property', () => {
describe('when the bill run is sroc', () => {
it('returns Current', () => {
const result = ViewBillPresenter.go(bill, billingAccount)

expect(result.chargeScheme).to.equal('Current')
})
})

describe('when the bill run is alcs', () => {
beforeEach(() => {
bill.billRun.scheme = 'alcs'
})

it('returns Old', () => {
const result = ViewBillPresenter.go(bill, billingAccount)

expect(result.chargeScheme).to.equal('Old')
})
})
})

describe('the "creditsTotal" property', () => {
describe('when the bill run was created in WRLS', () => {
it('returns the "creditNoteValue" of the bill (£0.00)', () => {
Expand Down Expand Up @@ -277,22 +193,6 @@ describe('View Bill presenter', () => {
})
})
})

describe('the "financialYear" property', () => {
it('returns the bill run start and end financial year', () => {
const result = ViewBillPresenter.go(bill, billingAccount)

expect(result.financialYear).to.equal('2022 to 2023')
})
})

describe('the "region" property', () => {
it("returns the bill run's region display name in title case", () => {
const result = ViewBillPresenter.go(bill, billingAccount)

expect(result.region).to.equal('South West')
})
})
})
})

Expand Down

0 comments on commit 68db9b1

Please sign in to comment.