From db839c02baf4981c3c12d9716cd0bb6d180f34d0 Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Wed, 7 Dec 2022 16:02:54 +0000 Subject: [PATCH] Implement chage to query We aso needed to tweak the helper to allow us to support this scenario. --- .../supplementary-billing/fetch-licences.service.js | 2 ++ .../supplementary-billing/fetch-licences.service.test.js | 5 +++-- test/support/helpers/charge-version.helper.js | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/services/supplementary-billing/fetch-licences.service.js b/app/services/supplementary-billing/fetch-licences.service.js index 5bf50a58b2..0896944e1f 100644 --- a/app/services/supplementary-billing/fetch-licences.service.js +++ b/app/services/supplementary-billing/fetch-licences.service.js @@ -26,8 +26,10 @@ class FetchLicencesService { static async _fetch (region) { const result = await LicenceModel.query() + .innerJoinRelated('chargeVersions') .where('region_id', region.regionId) .where('include_in_supplementary_billing', 'yes') + .where('chargeVersions.scheme', 'sroc') return result } diff --git a/test/services/supplementary-billing/fetch-licences.service.test.js b/test/services/supplementary-billing/fetch-licences.service.test.js index 8b8bfb4111..193af9df95 100644 --- a/test/services/supplementary-billing/fetch-licences.service.test.js +++ b/test/services/supplementary-billing/fetch-licences.service.test.js @@ -8,6 +8,7 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers +const ChargeVersionHelper = require('../../support/helpers/charge-version.helper.js') const DatabaseHelper = require('../../support/helpers/database.helper.js') const LicenceHelper = require('../../support/helpers/licence.helper.js') @@ -30,10 +31,10 @@ describe('Fetch Licences service', () => { describe('and that have an SROC charge version', () => { beforeEach(async () => { - // testRecords = await LicenceHelper.add({ include_in_supplementary_billing: 'yes' }) + await ChargeVersionHelper.add({}, testRecords[0]) }) - it('returns results', async () => { + it.only('returns results', async () => { const result = await FetchLicencesService.go(region) expect(result.length).to.equal(1) diff --git a/test/support/helpers/charge-version.helper.js b/test/support/helpers/charge-version.helper.js index 0ae64ebd21..9df8cb4b9d 100644 --- a/test/support/helpers/charge-version.helper.js +++ b/test/support/helpers/charge-version.helper.js @@ -28,7 +28,11 @@ class ChargeVersionHelper { * @returns {string} The ID of the newly created record */ static async add (data = {}, licence = {}) { - const licenceId = await this._addLicence(licence) + let licenceId = licence?.licenceId + if (!licenceId) { + licenceId = await this._addLicence(licence) + } + const insertData = this.defaults({ ...data, licence_id: licenceId }) const result = await db.table('water.charge_versions')