Skip to content

Commit 68db9b1

Browse files
authored
Use existing helpers in view bill page (#1756)
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!
1 parent 0921721 commit 68db9b1

File tree

2 files changed

+11
-136
lines changed

2 files changed

+11
-136
lines changed

app/presenters/bills/view-bill.presenter.js

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
* @module ViewBillPresenter
66
*/
77

8-
const { formatLongDate, formatMoney, titleCase } = require('../base.presenter.js')
8+
const {
9+
formatBillRunType,
10+
formatChargeScheme,
11+
formatFinancialYear,
12+
formatLongDate,
13+
formatMoney,
14+
titleCase
15+
} = require('../base.presenter.js')
916

1017
/**
1118
* Formats bill and billing account data ready for presenting in the single licence bill and multi licence bill pages
@@ -29,17 +36,17 @@ function go(bill, billingAccount) {
2936
billRunId: billRun.id,
3037
billRunNumber: billRun.billRunNumber,
3138
billRunStatus: billRun.status,
32-
billRunType: _billRunType(billRun),
39+
billRunType: formatBillRunType(billRun.batchType, billRun.scheme, billRun.summer),
3340
billTotal: _billTotal(bill.netAmount, bill.credit),
34-
chargeScheme: _scheme(billRun),
41+
chargeScheme: formatChargeScheme(billRun.scheme),
3542
contactName: billingAccount.$contactName(),
3643
credit: bill.credit,
3744
creditsTotal: _creditsTotal(bill, billRun),
3845
dateCreated: formatLongDate(bill.createdAt),
3946
debitsTotal: _debitsTotal(bill, billRun),
4047
deminimis: bill.deminimis,
4148
displayCreditDebitTotals: _displayCreditDebitTotals(billRun),
42-
financialYear: _financialYear(bill),
49+
financialYear: formatFinancialYear(bill.financialYearEnding),
4350
flaggedForReissue: bill.flaggedForRebilling,
4451
pageTitle: `Bill for ${accountName}`,
4552
region: titleCase(billRun.region.displayName),
@@ -49,24 +56,6 @@ function go(bill, billingAccount) {
4956
return formattedBill
5057
}
5158

52-
function _billRunType(billRun) {
53-
const { batchType, summer, scheme } = billRun
54-
55-
if (batchType !== 'two_part_tariff') {
56-
return titleCase(batchType)
57-
}
58-
59-
if (scheme === 'sroc') {
60-
return 'Two-part tariff'
61-
}
62-
63-
if (summer) {
64-
return 'Two-part tariff summer'
65-
}
66-
67-
return 'Two-part tariff winter and all year'
68-
}
69-
7059
function _creditsTotal(bill, billRun) {
7160
const { creditNoteValue, netAmount } = bill
7261
const { source } = billRun
@@ -103,20 +92,6 @@ function _displayCreditDebitTotals(billRun) {
10392
return batchType === 'supplementary'
10493
}
10594

106-
function _financialYear(bill) {
107-
const { financialYearEnding } = bill
108-
109-
return `${financialYearEnding - 1} to ${financialYearEnding}`
110-
}
111-
112-
function _scheme(billRun) {
113-
if (billRun.scheme === 'sroc') {
114-
return 'Current'
115-
}
116-
117-
return 'Old'
118-
}
119-
12095
function _billTotal(valueInPence, credit) {
12196
const valueAsMoney = formatMoney(valueInPence)
12297

test/presenters/bills/view-bill.presenter.test.js

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -54,68 +54,6 @@ describe('View Bill presenter', () => {
5454
})
5555
})
5656

57-
describe('the "billRunType" property', () => {
58-
describe('when the bill run is annual', () => {
59-
it('returns Annual', () => {
60-
const result = ViewBillPresenter.go(bill, billingAccount)
61-
62-
expect(result.billRunType).to.equal('Annual')
63-
})
64-
})
65-
66-
describe('when the bill run is supplementary', () => {
67-
beforeEach(() => {
68-
bill.billRun.batchType = 'supplementary'
69-
})
70-
71-
it('returns Supplementary', () => {
72-
const result = ViewBillPresenter.go(bill, billingAccount)
73-
74-
expect(result.billRunType).to.equal('Supplementary')
75-
})
76-
})
77-
78-
describe('when the bill run is two_part_tariff', () => {
79-
beforeEach(() => {
80-
bill.billRun.batchType = 'two_part_tariff'
81-
})
82-
83-
describe('and the scheme is sroc', () => {
84-
it('returns Supplementary', () => {
85-
const result = ViewBillPresenter.go(bill, billingAccount)
86-
87-
expect(result.billRunType).to.equal('Two-part tariff')
88-
})
89-
})
90-
91-
describe('and the scheme is alcs', () => {
92-
beforeEach(() => {
93-
bill.billRun.scheme = 'alcs'
94-
})
95-
96-
describe('and it is not summer only', () => {
97-
it('returns Supplementary', () => {
98-
const result = ViewBillPresenter.go(bill, billingAccount)
99-
100-
expect(result.billRunType).to.equal('Two-part tariff winter and all year')
101-
})
102-
})
103-
104-
describe('and it is for summer only', () => {
105-
beforeEach(() => {
106-
bill.billRun.summer = true
107-
})
108-
109-
it('returns Supplementary', () => {
110-
const result = ViewBillPresenter.go(bill, billingAccount)
111-
112-
expect(result.billRunType).to.equal('Two-part tariff summer')
113-
})
114-
})
115-
})
116-
})
117-
})
118-
11957
describe('the "billTotal" property', () => {
12058
describe('when the bill is a debit', () => {
12159
it('returns just the bill total formatted as money', () => {
@@ -138,28 +76,6 @@ describe('View Bill presenter', () => {
13876
})
13977
})
14078

141-
describe('the "chargeScheme" property', () => {
142-
describe('when the bill run is sroc', () => {
143-
it('returns Current', () => {
144-
const result = ViewBillPresenter.go(bill, billingAccount)
145-
146-
expect(result.chargeScheme).to.equal('Current')
147-
})
148-
})
149-
150-
describe('when the bill run is alcs', () => {
151-
beforeEach(() => {
152-
bill.billRun.scheme = 'alcs'
153-
})
154-
155-
it('returns Old', () => {
156-
const result = ViewBillPresenter.go(bill, billingAccount)
157-
158-
expect(result.chargeScheme).to.equal('Old')
159-
})
160-
})
161-
})
162-
16379
describe('the "creditsTotal" property', () => {
16480
describe('when the bill run was created in WRLS', () => {
16581
it('returns the "creditNoteValue" of the bill (£0.00)', () => {
@@ -277,22 +193,6 @@ describe('View Bill presenter', () => {
277193
})
278194
})
279195
})
280-
281-
describe('the "financialYear" property', () => {
282-
it('returns the bill run start and end financial year', () => {
283-
const result = ViewBillPresenter.go(bill, billingAccount)
284-
285-
expect(result.financialYear).to.equal('2022 to 2023')
286-
})
287-
})
288-
289-
describe('the "region" property', () => {
290-
it("returns the bill run's region display name in title case", () => {
291-
const result = ViewBillPresenter.go(bill, billingAccount)
292-
293-
expect(result.region).to.equal('South West')
294-
})
295-
})
296196
})
297197
})
298198

0 commit comments

Comments
 (0)