diff --git a/test/models/water/billing-batch.model.test.js b/test/models/water/billing-batch.model.test.js index aa056dab63..b715534b86 100644 --- a/test/models/water/billing-batch.model.test.js +++ b/test/models/water/billing-batch.model.test.js @@ -76,7 +76,7 @@ describe('Billing Batch model', () => { testBillingInvoices = [] for (let i = 0; i < 2; i++) { - const billingInvoice = await BillingInvoiceHelper.add({ financialYearEnding: 2023 }, { billingBatchId }) + const billingInvoice = await BillingInvoiceHelper.add({ financialYearEnding: 2023, billingBatchId }) testBillingInvoices.push(billingInvoice) } }) diff --git a/test/models/water/billing-invoice-licence.model.test.js b/test/models/water/billing-invoice-licence.model.test.js index 689bcdc544..2a51875670 100644 --- a/test/models/water/billing-invoice-licence.model.test.js +++ b/test/models/water/billing-invoice-licence.model.test.js @@ -46,7 +46,7 @@ describe('Billing Invoice Licence model', () => { testBillingInvoice = await BillingInvoiceHelper.add() const { billingInvoiceId } = testBillingInvoice - testRecord = await BillingInvoiceLicenceHelper.add({}, {}, { billingInvoiceId }) + testRecord = await BillingInvoiceLicenceHelper.add({ billingInvoiceId }) }) it('can successfully run a related query', async () => { @@ -112,7 +112,7 @@ describe('Billing Invoice Licence model', () => { testLicence = await LicenceHelper.add() const { licenceId } = testLicence - testRecord = await BillingInvoiceLicenceHelper.add({}, { licenceId }) + testRecord = await BillingInvoiceLicenceHelper.add({ licenceId }) }) it('can successfully run a related query', async () => { diff --git a/test/models/water/billing-invoice.model.test.js b/test/models/water/billing-invoice.model.test.js index 2a705caa51..70b0a786e9 100644 --- a/test/models/water/billing-invoice.model.test.js +++ b/test/models/water/billing-invoice.model.test.js @@ -44,7 +44,7 @@ describe('Billing Invoice model', () => { beforeEach(async () => { testBillingBatch = await BillingBatchHelper.add() - testRecord = await BillingInvoiceHelper.add({}, { billingBatchId: testBillingBatch.billingBatchId }) + testRecord = await BillingInvoiceHelper.add({ billingBatchId: testBillingBatch.billingBatchId }) }) it('can successfully run a related query', async () => { @@ -76,7 +76,7 @@ describe('Billing Invoice model', () => { testBillingInvoiceLicences = [] for (let i = 0; i < 2; i++) { - const billingInvoiceLicence = await BillingInvoiceLicenceHelper.add({}, {}, { billingInvoiceId }) + const billingInvoiceLicence = await BillingInvoiceLicenceHelper.add({ billingInvoiceId }) testBillingInvoiceLicences.push(billingInvoiceLicence) } }) diff --git a/test/models/water/charge-version.model.test.js b/test/models/water/charge-version.model.test.js index 0f287f996c..8cac1f8ad5 100644 --- a/test/models/water/charge-version.model.test.js +++ b/test/models/water/charge-version.model.test.js @@ -46,7 +46,7 @@ describe('ChargeVersion model', () => { testLicence = await LicenceHelper.add() const { licenceId } = testLicence - testRecord = await ChargeVersionHelper.add({}, { licenceId }) + testRecord = await ChargeVersionHelper.add({ licenceId }) }) it('can successfully run a related query', async () => { diff --git a/test/models/water/licence.model.test.js b/test/models/water/licence.model.test.js index 7a8c404e2a..42bf0e6c88 100644 --- a/test/models/water/licence.model.test.js +++ b/test/models/water/licence.model.test.js @@ -49,7 +49,7 @@ describe('Licence model', () => { testChargeVersions = [] for (let i = 0; i < 2; i++) { - const chargeVersion = await ChargeVersionHelper.add({ licenceRef }, { licenceId }) + const chargeVersion = await ChargeVersionHelper.add({ licenceRef, licenceId }) testChargeVersions.push(chargeVersion) } }) @@ -114,7 +114,7 @@ describe('Licence model', () => { testBillingInvoiceLicences = [] for (let i = 0; i < 2; i++) { - const billingInvoiceLicence = await BillingInvoiceLicenceHelper.add({ licenceRef }, { licenceId }) + const billingInvoiceLicence = await BillingInvoiceLicenceHelper.add({ licenceRef, licenceId }) testBillingInvoiceLicences.push(billingInvoiceLicence) } }) 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 ec938492e3..97c96e6df3 100644 --- a/test/services/supplementary-billing/fetch-charge-versions.service.test.js +++ b/test/services/supplementary-billing/fetch-charge-versions.service.test.js @@ -58,20 +58,17 @@ describe('Fetch Charge Versions service', () => { // This creates a 'current' SROC charge version const srocChargeVersion = await ChargeVersionHelper.add( - { changeReasonId: changeReason.changeReasonId }, - { licenceId } + { changeReasonId: changeReason.changeReasonId, licenceId } ) // This creates a 'superseded' SROC charge version const srocSupersededChargeVersion = await ChargeVersionHelper.add( - { changeReasonId: changeReason.changeReasonId, status: 'superseded' }, - { licenceId } + { changeReasonId: changeReason.changeReasonId, status: 'superseded', licenceId } ) // This creates an ALCS (presroc) charge version const alcsChargeVersion = await ChargeVersionHelper.add( - { scheme: 'alcs' }, - { licenceId } + { scheme: 'alcs', licenceId } ) testRecords = [srocChargeVersion, srocSupersededChargeVersion, alcsChargeVersion] @@ -171,10 +168,13 @@ describe('Fetch Charge Versions service', () => { endDate: new Date('2023-03-31') } - const srocDraftChargeVersion = await ChargeVersionHelper.add( - { status: 'draft' }, - { regionId, isWaterUndertaker: true, includeInSrocSupplementaryBilling: true } - ) + const { licenceId } = await LicenceHelper.add({ + regionId, + isWaterUndertaker: true, + includeInSrocSupplementaryBilling: true + }) + + const srocDraftChargeVersion = await ChargeVersionHelper.add({ status: 'draft', licenceId }) testRecords = [srocDraftChargeVersion] }) @@ -192,11 +192,13 @@ describe('Fetch Charge Versions service', () => { endDate: new Date('2023-03-31') } + const { licenceId } = await LicenceHelper.add({ + regionId, + includeInSupplementaryBilling: true + }) + // This creates an ALCS (presroc) charge version linked to a licence marked for supplementary billing - const alcsChargeVersion = await ChargeVersionHelper.add( - { scheme: 'alcs' }, - { includeInSupplementaryBilling: 'yes' } - ) + const alcsChargeVersion = await ChargeVersionHelper.add({ scheme: 'alcs', licenceId }) testRecords = [alcsChargeVersion] }) @@ -214,11 +216,13 @@ describe('Fetch Charge Versions service', () => { endDate: new Date('2023-03-31') } + const { licenceId } = await LicenceHelper.add({ + regionId, + includeInSrocSupplementaryBilling: true + }) + // This creates a charge version with no `invoiceAccountId` - const nullInvoiceAccountIdChargeVersion = await ChargeVersionHelper.add( - { invoiceAccountId: null }, - { regionId, includeInSrocSupplementaryBilling: true } - ) + const nullInvoiceAccountIdChargeVersion = await ChargeVersionHelper.add({ invoiceAccountId: null, licenceId }) testRecords = [nullInvoiceAccountIdChargeVersion] }) @@ -237,11 +241,15 @@ describe('Fetch Charge Versions service', () => { endDate: new Date('2023-03-31') } + const { licenceId } = await LicenceHelper.add({ + regionId, + includeInSrocSupplementaryBilling: true + }) + // This creates an SROC charge version with a start date before the billing period. This would have been // picked up by a previous bill run const alcsChargeVersion = await ChargeVersionHelper.add( - { startDate: new Date(2022, 2, 31) }, // 2022-03-01 - Months are zero indexed :-) - { includeInSrocSupplementaryBilling: true } + { startDate: new Date(2022, 2, 31), licenceId } // 2022-03-01 - Months are zero indexed :-) ) testRecords = [alcsChargeVersion] }) @@ -260,11 +268,15 @@ describe('Fetch Charge Versions service', () => { endDate: new Date('2023-03-31') } + const { licenceId } = await LicenceHelper.add({ + regionId, + includeInSrocSupplementaryBilling: true + }) + // This creates an SROC charge version with a start date after the billing period. This will be picked in // next years bill runs const alcsChargeVersion = await ChargeVersionHelper.add( - { startDate: new Date(2023, 3, 1) }, // 2023-04-01 - Months are zero indexed :-) - { includeInSrocSupplementaryBilling: true } + { startDate: new Date(2023, 3, 1), licenceId } // 2023-04-01 - Months are zero indexed :-) ) testRecords = [alcsChargeVersion] }) @@ -284,14 +296,13 @@ describe('Fetch Charge Versions service', () => { endDate: new Date('2023-03-31') } + const { licenceId } = await LicenceHelper.add({ + regionId: 'e117b501-e3c1-4337-ad35-21c60ed9ad73', + includeInSrocSupplementaryBilling: true + }) + // This creates an SROC charge version linked to a licence with an different region than selected - const otherRegionChargeVersion = await ChargeVersionHelper.add( - {}, - { - includeInSrocSupplementaryBilling: true, - regionId: 'e117b501-e3c1-4337-ad35-21c60ed9ad73' - } - ) + const otherRegionChargeVersion = await ChargeVersionHelper.add({ licenceId }) testRecords = [otherRegionChargeVersion] }) @@ -309,14 +320,13 @@ describe('Fetch Charge Versions service', () => { endDate: new Date('2023-03-31') } - const chargeVersion = await ChargeVersionHelper.add( - {}, - { - includeInSrocSupplementaryBilling: true, - regionId - } - ) - await ChargeVersionWorkflowHelper.add({ licenceId: chargeVersion.licenceId }) + const { licenceId } = await LicenceHelper.add({ + regionId, + includeInSrocSupplementaryBilling: true + }) + + const chargeVersion = await ChargeVersionHelper.add({ licenceId }) + await ChargeVersionWorkflowHelper.add({ licenceId }) testRecords = [chargeVersion] }) diff --git a/test/services/supplementary-billing/fetch-previous-billing-transactions.service.test.js b/test/services/supplementary-billing/fetch-previous-billing-transactions.service.test.js index bdfcb7e720..3cec0fe87e 100644 --- a/test/services/supplementary-billing/fetch-previous-billing-transactions.service.test.js +++ b/test/services/supplementary-billing/fetch-previous-billing-transactions.service.test.js @@ -172,12 +172,8 @@ describe('Fetch Previous Billing Transactions service', () => { async function _createBillingBatchInvoiceAndLicence (invoiceAccountId, licenceId) { const { billingBatchId } = await BillingBatchHelper.add({ status: 'sent' }) - const { billingInvoiceId } = await BillingInvoiceHelper.add({ invoiceAccountId }, { billingBatchId }) - const { billingInvoiceLicenceId } = await BillingInvoiceLicenceHelper.add( - {}, - { licenceId }, - { billingInvoiceId } - ) + const { billingInvoiceId } = await BillingInvoiceHelper.add({ invoiceAccountId, billingBatchId }) + const { billingInvoiceLicenceId } = await BillingInvoiceLicenceHelper.add({ billingInvoiceId, licenceId }) return billingInvoiceLicenceId } diff --git a/test/services/supplementary-billing/process-billing-batch.service.test.js b/test/services/supplementary-billing/process-billing-batch.service.test.js index 9fe95882fb..2d06ed50ac 100644 --- a/test/services/supplementary-billing/process-billing-batch.service.test.js +++ b/test/services/supplementary-billing/process-billing-batch.service.test.js @@ -105,9 +105,7 @@ describe('Process billing batch service', () => { { changeReasonId: changeReason.changeReasonId, invoiceAccountId: invoiceAccount.invoiceAccountId, - startDate: new Date(2022, 7, 1, 9) - }, - { + startDate: new Date(2022, 7, 1, 9), licenceId: licence.licenceId } ) @@ -171,10 +169,11 @@ describe('Process billing batch service', () => { describe('because generating the calculated transactions fails', () => { beforeEach(async () => { - const { chargeVersionId } = await ChargeVersionHelper.add( - { changeReasonId: changeReason.changeReasonId, invoiceAccountId: invoiceAccount.invoiceAccountId }, - { licenceId: licence.licenceId } - ) + const { chargeVersionId } = await ChargeVersionHelper.add({ + changeReasonId: changeReason.changeReasonId, + invoiceAccountId: invoiceAccount.invoiceAccountId, + licenceId: licence.licenceId + }) const { chargeElementId } = await ChargeElementHelper.add( { billingChargeCategoryId: billingChargeCategory.billingChargeCategoryId, chargeVersionId } ) @@ -194,10 +193,11 @@ describe('Process billing batch service', () => { describe('because creating the billing transactions', () => { beforeEach(async () => { - const { chargeVersionId } = await ChargeVersionHelper.add( - { changeReasonId: changeReason.changeReasonId, invoiceAccountId: invoiceAccount.invoiceAccountId }, - { licenceId: licence.licenceId } - ) + const { chargeVersionId } = await ChargeVersionHelper.add({ + changeReasonId: changeReason.changeReasonId, + invoiceAccountId: invoiceAccount.invoiceAccountId, + licenceId: licence.licenceId + }) const { chargeElementId } = await ChargeElementHelper.add( { billingChargeCategoryId: billingChargeCategory.billingChargeCategoryId, chargeVersionId } ) diff --git a/test/support/helpers/water/billing-invoice-licence.helper.js b/test/support/helpers/water/billing-invoice-licence.helper.js index 7fef5e549d..63aa4ac6b9 100644 --- a/test/support/helpers/water/billing-invoice-licence.helper.js +++ b/test/support/helpers/water/billing-invoice-licence.helper.js @@ -4,60 +4,29 @@ * @module BillingInvoiceLicenceHelper */ -const BillingInvoiceHelper = require('./billing-invoice.helper.js') const BillingInvoiceLicenceModel = require('../../../../app/models/water/billing-invoice-licence.model.js') -const LicenceHelper = require('./licence.helper.js') /** * Add a new billing invoice licence * - * A billing invoice licence is always linked to a licence and a billing invoice. So, creating a billing invoice licence will automatically - * create a new licence, a new billing invoice and handle linking them together by `licenceId` & `billingInvoiceId`. - * * If no `data` is provided, default values will be used. These are * + * - `billingInvoiceId` - 45f08fe4-5b8b-4cf7-aaf0-5a07534e1357 * - `licenceRef` - 01/123 - * - * See `LicenceHelper` for the licence defaults - * See `BillingInvoiceHelper` for the billing invoice defaults + * - `licenceId` - 2eb0623e-30c6-4bf4-9598-2d60a8366c7d * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database - * @param {Object} [licence] Any licence data you want to use instead of the defaults used here or in the database - * @param {Object} [billingInvoice] Any billing invoice data you want to use instead of the defaults used here or in the database * * @returns {module:BillingInvoiceLicenceModel} The instance of the newly created record */ -async function add (data = {}, licence = {}, billingInvoice = {}) { - const licenceId = await _licenceId(licence) - const billingInvoiceId = await _billingInvoiceId(billingInvoice) - - const insertData = defaults({ ...data, licenceId, billingInvoiceId }) +async function add (data = {}) { + const insertData = defaults(data) return BillingInvoiceLicenceModel.query() .insert({ ...insertData }) .returning('*') } -async function _licenceId (providedLicence) { - if (providedLicence?.licenceId) { - return providedLicence.licenceId - } - - const licence = await LicenceHelper.add(providedLicence) - - return licence.licenceId -} - -async function _billingInvoiceId (providedBillingInvoice) { - if (providedBillingInvoice?.billingInvoiceId) { - return providedBillingInvoice.billingInvoiceId - } - - const billingInvoice = await BillingInvoiceHelper.add(providedBillingInvoice) - - return billingInvoice.billingInvoiceId -} - /** * Returns the defaults used when creating a new billing invoice licence * @@ -68,7 +37,9 @@ async function _billingInvoiceId (providedBillingInvoice) { */ function defaults (data = {}) { const defaults = { - licenceRef: '01/123' + billingInvoiceId: '45f08fe4-5b8b-4cf7-aaf0-5a07534e1357', + licenceRef: '01/123', + licenceId: '2eb0623e-30c6-4bf4-9598-2d60a8366c7d' } return { diff --git a/test/support/helpers/water/billing-invoice.helper.js b/test/support/helpers/water/billing-invoice.helper.js index 3c630f7334..38c6616335 100644 --- a/test/support/helpers/water/billing-invoice.helper.js +++ b/test/support/helpers/water/billing-invoice.helper.js @@ -5,16 +5,10 @@ */ const BillingInvoiceModel = require('../../../../app/models/water/billing-invoice.model.js') -const BillingBatchHelper = require('./billing-batch.helper.js') /** * Add a new billing invoice * - * A billing invoice is always linked to a billing batch. So, creating a billing invoice will automatically - * create a new billing batch and handle linking the two together by `billingBatchId`. If a `financialYearEnding` has - * been provided for the billing invoice, but not for the billing batch. The billing batch will use the 'financialYearEnding' - * from the billing invoice to populate it's `fromFinancialYearEnding` & `toFinancialYearEnding` items. - * * If no `data` is provided, default values will be used. These are * * - `invoiceAccountId` - 396ee68f-d665-4770-b0ad-d70a007f9bd5 @@ -23,38 +17,18 @@ const BillingBatchHelper = require('./billing-batch.helper.js') * - `billingBatchId` - 1d9e3142-8893-4dff-9043-f4b3b34e230d * - `financialYearEnding` - 2023 * - * See `BillingBatchHelper` for the billing batch defaults - * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database - * @param {Object} [billingBatch] Any billing batch data you want to use instead of the defaults used here or in the database * * @returns {module:BillingInvoiceModel} The instance of the newly created record */ -async function add (data = {}, billingBatch = {}) { - if (data.financialYearEnding && !billingBatch.fromFinancialYearEnding) { - billingBatch.fromFinancialYearEnding = data.financialYearEnding - billingBatch.toFinancialYearEnding = data.financialYearEnding - } - - const billingBatchId = await _billingBatchId(billingBatch) - - const insertData = defaults({ ...data, billingBatchId }) +async function add (data = {}) { + const insertData = defaults(data) return BillingInvoiceModel.query() .insert({ ...insertData }) .returning('*') } -async function _billingBatchId (providedBillingBatch) { - if (providedBillingBatch?.billingBatchId) { - return providedBillingBatch.billingBatchId - } - - const billingBatch = await BillingBatchHelper.add(providedBillingBatch) - - return billingBatch.billingBatchId -} - /** * Returns the defaults used when creating a new billing invoice * diff --git a/test/support/helpers/water/charge-version.helper.js b/test/support/helpers/water/charge-version.helper.js index 2caa08c027..f722e50940 100644 --- a/test/support/helpers/water/charge-version.helper.js +++ b/test/support/helpers/water/charge-version.helper.js @@ -5,14 +5,10 @@ */ const ChargeVersionModel = require('../../../../app/models/water/charge-version.model.js') -const LicenceHelper = require('./licence.helper.js') /** * Add a new charge version * - * A charge version is always linked to a licence. So, creating a charge version will automatically create a new - * licence and handle linking the two together by `licence_id`. - * * If no `data` is provided, default values will be used. These are * * - `licenceRef` - 01/123 @@ -20,34 +16,20 @@ const LicenceHelper = require('./licence.helper.js') * - `startDate` - 2022-04-01 * - `invoiceAccountId` - 01931031-4680-4950-87d6-50f8fe784f6d * - `status` - current - * - * See `LicenceHelper` for the licence defaults + * - `licenceId` - 4c9d2d86-fc88-4fb6-b49d-8a30f52f7997 * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database - * @param {Object} [licence] Any licence data you want to use instead of the defaults used here or in the database * * @returns {module:ChargeVersionModel} The instance of the newly created record */ -async function add (data = {}, licence = {}) { - const licenceId = await _licenceId(licence) - - const insertData = defaults({ ...data, licenceId }) +async function add (data = {}) { + const insertData = defaults(data) return ChargeVersionModel.query() .insert({ ...insertData }) .returning('*') } -async function _licenceId (providedLicence) { - if (providedLicence?.licenceId) { - return providedLicence.licenceId - } - - const licence = await LicenceHelper.add(providedLicence) - - return licence.licenceId -} - /** * Returns the defaults used when creating a new charge version * @@ -62,7 +44,8 @@ function defaults (data = {}) { scheme: 'sroc', startDate: new Date('2022-04-01'), invoiceAccountId: '01931031-4680-4950-87d6-50f8fe784f6d', - status: 'current' + status: 'current', + licenceId: '4c9d2d86-fc88-4fb6-b49d-8a30f52f7997' } return {