Skip to content

Commit

Permalink
Update tests to cover failing scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruikshanks committed Dec 23, 2024
1 parent 93ffb8e commit 55cb13a
Showing 1 changed file with 89 additions and 9 deletions.
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: false,
supportedSourceName: null,
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 55cb13a

Please sign in to comment.