From 4cb1ea5113889d8f744992007a783560eca7b092 Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Wed, 19 Apr 2023 11:53:19 +0100 Subject: [PATCH] Fix 'draft' tests One of our failing tests highlighted we had been a bit to eager when deleting the status WHERE condition. Though we've not seen much evidence of its use, charge versions do have a status of 'draft'. So, just in case we add that WHERE condition back in and update the tests appropriately. --- .../fetch-charge-versions.service.js | 1 + .../fetch-charge-versions.service.test.js | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/services/supplementary-billing/fetch-charge-versions.service.js b/app/services/supplementary-billing/fetch-charge-versions.service.js index d55fe8748f..99fac7aad1 100644 --- a/app/services/supplementary-billing/fetch-charge-versions.service.js +++ b/app/services/supplementary-billing/fetch-charge-versions.service.js @@ -42,6 +42,7 @@ async function _fetch (regionId, billingPeriod) { .where('regionId', regionId) .where('chargeVersions.startDate', '>=', billingPeriod.startDate) .where('chargeVersions.startDate', '<=', billingPeriod.endDate) + .whereNot('chargeVersions.status', 'draft') .whereNotExists( ChargeVersionWorkflow.query() .select(1) diff --git a/test/services/supplementary-billing/fetch-charge-versions.service.test.js b/test/services/supplementary-billing/fetch-charge-versions.service.test.js index 7cbd2138e4..ec938492e3 100644 --- a/test/services/supplementary-billing/fetch-charge-versions.service.test.js +++ b/test/services/supplementary-billing/fetch-charge-versions.service.test.js @@ -164,22 +164,18 @@ describe('Fetch Charge Versions service', () => { }) }) - describe("because all the applicable charge versions do not have a 'current' status", () => { + describe("because all the applicable charge versions have a 'draft' status", () => { beforeEach(async () => { billingPeriod = { startDate: new Date('2022-04-01'), endDate: new Date('2023-03-31') } - const srocSupersededChargeVersion = await ChargeVersionHelper.add( - { status: 'superseded' }, - { regionId, isWaterUndertaker: true, includeInSrocSupplementaryBilling: true } - ) const srocDraftChargeVersion = await ChargeVersionHelper.add( { status: 'draft' }, { regionId, isWaterUndertaker: true, includeInSrocSupplementaryBilling: true } ) - testRecords = [srocSupersededChargeVersion, srocDraftChargeVersion] + testRecords = [srocDraftChargeVersion] }) it('returns no applicable charge versions', async () => {