Skip to content

Commit

Permalink
Add failing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruikshanks committed Apr 3, 2024
1 parent 61845b3 commit 4bf16a6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/services/bill-runs/submit-send-bill-run.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const ExpandedError = require('../../../app/errors/expanded.error.js')
// Things we need to stub
const ChargingModuleSendBillRunRequest = require('../../../app/requests/charging-module/send-bill-run.request.js')
const ChargingModuleViewBillRunRequest = require('../../../app/requests/charging-module/view-bill-run.request.js')
const UnflagBilledLicencesService = require('../../../app/services/bill-runs/supplementary/unflag-billed-licences.service.js')

// Thing under test
const SubmitSendBillBunService = require('../../../app/services/bill-runs/submit-send-bill-run.service.js')
Expand All @@ -32,12 +33,14 @@ describe('Submit Send Bill Run service', () => {
let chargingModuleSendBillRunRequestStub
let chargingModuleViewBillRunRequestStub
let notifierStub
let unflagBilledLicencesServiceStub

beforeEach(async () => {
await DatabaseSupport.clean()

chargingModuleSendBillRunRequestStub = Sinon.stub(ChargingModuleSendBillRunRequest, 'send').resolves()
chargingModuleViewBillRunRequestStub = Sinon.stub(ChargingModuleViewBillRunRequest, 'send')
unflagBilledLicencesServiceStub = Sinon.stub(UnflagBilledLicencesService, 'go').resolves()

// The service depends on GlobalNotifier to have been set. This happens in app/plugins/global-notifier.plugin.js
// when the app starts up and the plugin is registered. As we're not creating an instance of Hapi server in this
Expand Down Expand Up @@ -123,6 +126,34 @@ describe('Submit Send Bill Run service', () => {
expect(logDataArg.timeTakenSs).to.exist()
expect(logDataArg.billRunId).to.exist()
})

describe("when the bill run's batch type is 'supplementary'", () => {
it('removes the SROC supplementary billing flag from those licences billed', async () => {
await SubmitSendBillBunService.go(billRun.id)

await setTimeout(delay)

expect(unflagBilledLicencesServiceStub.called).to.be.true()
})
})

describe.only("when the bill run's batch type is not 'supplementary'", () => {
let annualBillRun

beforeEach(async () => {
annualBillRun = await BillRunHelper.add({
batchType: 'annual', externalId: '76ed78bd-c104-4ad7-8842-4b660df02331', status: 'ready'
})
})

it('leaves the SROC supplementary billing flag for those licences billed', async () => {
await SubmitSendBillBunService.go(annualBillRun.id)

await setTimeout(delay)

expect(unflagBilledLicencesServiceStub.called).to.be.false()
})
})
})

describe('but the request to view the Charging Module bill run fails', () => {
Expand Down

0 comments on commit 4bf16a6

Please sign in to comment.