Skip to content

Commit

Permalink
Fix miscalculated preview 2PT charge in review (#1583)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4849

When previewing the two-part tariff charge calculation for some licences, the business spotted that the value returned was more than expected.

They have deduced it is because the preview is incorrectly flagging the licence as having a 'public water supply' and, therefore, adds the additional £141 charge to the calculation.

This change corrects what data we send to the [Charging Module API](https://github.com/DEFRA/sroc-charging-module-api) to ensure we present the correct preview charge to users.
  • Loading branch information
Cruikshanks authored Dec 23, 2024
1 parent bb8eaa6 commit 28d2b50
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/services/bill-runs/review/preview.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function _transaction(reviewChargeReference) {
supportedSourceName: chargeReference.supportedSourceName,
// If `twoPartTariff` is `true` then `section127Agreement` must also be `true`
twoPartTariff: section127Agreement,
waterCompanyCharge: chargeReference.waterCompanyCharge !== null,
waterCompanyCharge: !!chargeReference.waterCompanyCharge,
waterUndertaker: reviewChargeVersion.reviewLicence.licence.waterUndertaker,
winterOnly
}
Expand Down
98 changes: 89 additions & 9 deletions test/services/bill-runs/review/preview.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const FetchReviewChargeReferenceService = require('../../../../app/services/bill
const PreviewService = require('../../../../app/services/bill-runs/review/preview.service.js')

describe('Bill Runs Review - Preview service', () => {
let calculateChargeRequestStub
let reviewChargeReference
let yarStub

Expand All @@ -42,7 +43,7 @@ describe('Bill Runs Review - Preview service', () => {

describe('and the request to the Charging Module API succeeds', () => {
beforeEach(async () => {
Sinon.stub(CalculateChargeRequest, 'send').resolves({
calculateChargeRequestStub = Sinon.stub(CalculateChargeRequest, 'send').resolves({
succeeded: true,
response: {
info: {
Expand All @@ -66,14 +67,95 @@ describe('Bill Runs Review - Preview service', () => {
})
})

it('adds a flash message stating the example charge returned by the Charging Module API', async () => {
await PreviewService.go(reviewChargeReference.id, yarStub)
describe('for a charge reference with no additional charges (null)', () => {
it('makes the correct request to the Charging Module API', async () => {
await PreviewService.go(reviewChargeReference.id, yarStub)

const generatedTransaction = calculateChargeRequestStub.args[0][0]

expect(generatedTransaction).to.equal({
abatementFactor: 1,
actualVolume: 9.092,
adjustmentFactor: 1,
aggregateProportion: 0.333333333,
authorisedDays: 0,
authorisedVolume: 9.092,
billableDays: 0,
chargeCategoryCode: '4.6.5',
compensationCharge: false,
credit: false,
loss: 'high',
periodStart: '01-APR-2023',
periodEnd: '31-MAR-2024',
ruleset: 'sroc',
section127Agreement: true,
section130Agreement: false,
supportedSource: false,
supportedSourceName: null,
twoPartTariff: true,
waterCompanyCharge: false,
waterUndertaker: false,
winterOnly: false
})
})

const [flashType, bannerMessage] = yarStub.flash.args[0]
it('adds a flash message stating the example charge returned by the Charging Module API', async () => {
await PreviewService.go(reviewChargeReference.id, yarStub)

expect(yarStub.flash.called).to.be.true()
expect(flashType).to.equal('charge')
expect(bannerMessage).to.equal('Based on this information the example charge is £20.00')
const [flashType, bannerMessage] = yarStub.flash.args[0]

expect(yarStub.flash.called).to.be.true()
expect(flashType).to.equal('charge')
expect(bannerMessage).to.equal('Based on this information the example charge is £20.00')
})
})

describe('for a charge reference with additional charges ({})', () => {
beforeEach(async () => {
reviewChargeReference.chargeReference.supportedSourceName = 'Support me please'
reviewChargeReference.chargeReference.waterCompanyCharge = false
})

it('makes the correct request to the Charging Module API', async () => {
await PreviewService.go(reviewChargeReference.id, yarStub)

const generatedTransaction = calculateChargeRequestStub.args[0][0]

expect(generatedTransaction).to.equal({
abatementFactor: 1,
actualVolume: 9.092,
adjustmentFactor: 1,
aggregateProportion: 0.333333333,
authorisedDays: 0,
authorisedVolume: 9.092,
billableDays: 0,
chargeCategoryCode: '4.6.5',
compensationCharge: false,
credit: false,
loss: 'high',
periodStart: '01-APR-2023',
periodEnd: '31-MAR-2024',
ruleset: 'sroc',
section127Agreement: true,
section130Agreement: false,
supportedSource: true,
supportedSourceName: 'Support me please',
twoPartTariff: true,
waterCompanyCharge: false,
waterUndertaker: false,
winterOnly: false
})
})

it('adds a flash message stating the example charge returned by the Charging Module API', async () => {
await PreviewService.go(reviewChargeReference.id, yarStub)

const [flashType, bannerMessage] = yarStub.flash.args[0]

expect(yarStub.flash.called).to.be.true()
expect(flashType).to.equal('charge')
expect(bannerMessage).to.equal('Based on this information the example charge is £20.00')
})
})
})

Expand Down Expand Up @@ -106,8 +188,6 @@ describe('Bill Runs Review - Preview service', () => {
})

describe('for a review charge reference with a total allocation that is 0', () => {
let calculateChargeRequestStub

beforeEach(() => {
Sinon.stub(FetchReviewChargeReferenceService, 'go').resolves(reviewChargeReference)

Expand Down

0 comments on commit 28d2b50

Please sign in to comment.