From e6fa1e83a0930bc6c75a786312d97172d32b6c6a Mon Sep 17 00:00:00 2001 From: Stuart Adair <43574728+StuAA78@users.noreply.github.com> Date: Fri, 17 Feb 2023 09:29:14 +0000 Subject: [PATCH 1/5] Generate Billing Invoice Licence record for SROC https://eaflood.atlassian.net/browse/WATER-3897 In order to 'piggy-back' onto the existing functions in the legacy service for reviewing, confirming, sending, viewing, deleting a bill run etc we need to create the same base database records as it does for a Bill run.' We already have billing_batches and events and are working on the billing_transactions in https://eaflood.atlassian.net/browse/WATER-3895 and https://eaflood.atlassian.net/browse/WATER-3894 We are also planning on building the billing_invoice record in https://eaflood.atlassian.net/browse/WATER-3896 So, the next entity we need is the billing_invoice_licence. This is the link between the billing_batch, the invoice account, and from there to the transactions to be included in the bill run. We'll need to dig into the legacy code to understand where the previous team extracts the data that forms the billing_invoice_licence records. From 0242b26e3c3b61d6c6b4f064b17a2dcbd865992b Mon Sep 17 00:00:00 2001 From: Stuart Adair <43574728+StuAA78@users.noreply.github.com> Date: Fri, 17 Feb 2023 10:59:01 +0000 Subject: [PATCH 2/5] Initial service and unit test --- .../create-billing-invoice-licence.service.js | 34 +++++++++++++++ ...te-billing-invoice-licence.service.test.js | 43 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 app/services/supplementary-billing/create-billing-invoice-licence.service.js create mode 100644 test/services/supplementary-billing/create-billing-invoice-licence.service.test.js diff --git a/app/services/supplementary-billing/create-billing-invoice-licence.service.js b/app/services/supplementary-billing/create-billing-invoice-licence.service.js new file mode 100644 index 0000000000..71900fe3fc --- /dev/null +++ b/app/services/supplementary-billing/create-billing-invoice-licence.service.js @@ -0,0 +1,34 @@ +'use strict' + +/** + * Creates a billing invoice licence record + * + * @module CreateBillingInvoiceLicenceService + */ + +const BillingInvoiceLicenceModel = require('../../models/water/billing-invoice-licence.model.js') + +/** + * Create a billing invoice licence record for the provided billing invoice and licence + * + * @param {module:BillingInvoiceModel} billingInvoice An instance of `BillingInvoiceModel` + * @param {module:licenceModel} licence An instance of `LicenceModel` + * + * @returns {Object} The newly-created billing invoice licence record + */ +async function go (billingInvoice, licence) { + const event = await BillingInvoiceLicenceModel.query() + .insert({ + billingInvoiceId: billingInvoice.billingInvoiceId, + licenceRef: licence.licenceRef, + licenceId: licence.licenceId + + }) + .returning('*') + + return event +} + +module.exports = { + go +} diff --git a/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js b/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js new file mode 100644 index 0000000000..6d0c2b7a62 --- /dev/null +++ b/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js @@ -0,0 +1,43 @@ +'use strict' + +// Test framework dependencies +const Lab = require('@hapi/lab') +const Code = require('@hapi/code') + +const { describe, it, beforeEach } = exports.lab = Lab.script() +const { expect } = Code + +// Test helpers +const BillingBatchHelper = require('../../support/helpers/water/billing-invoice.helper.js') +const BillingInvoiceLicenceModel = require('../../../app/models/water/billing-invoice-licence.model.js') +const LicenceHelper = require('../../support/helpers/water/licence.helper.js') +const DatabaseHelper = require('../../support/helpers/database.helper.js') + +// Thing under test +const CreateBillingInvoiceLicenceService = require('../../../app/services/supplementary-billing/create-billing-invoice-licence.service.js') + +describe.only('Create Billing Invoice Licence service', () => { + beforeEach(async () => { + await DatabaseHelper.clean() + }) + + describe('when a BillingBatchModel instance is provided', () => { + let billingInvoice + let licence + + beforeEach(async () => { + billingInvoice = await BillingBatchHelper.add() + licence = await LicenceHelper.add() + }) + + it('creates an event record', async () => { + const result = await CreateBillingInvoiceLicenceService.go(billingInvoice, licence) + + expect(result).to.be.an.instanceOf(BillingInvoiceLicenceModel) + + expect(result.billingInvoiceId).to.equal(billingInvoice.billingInvoiceId) + expect(result.licenceRef).to.equal(licence.licenceRef) + expect(result.licenceId).to.equal(licence.licenceId) + }) + }) +}) From 4b21cd18d0572b10d76e4469aaa73bfb5aa399a1 Mon Sep 17 00:00:00 2001 From: Stuart Adair <43574728+StuAA78@users.noreply.github.com> Date: Mon, 20 Feb 2023 12:34:36 +0000 Subject: [PATCH 3/5] Remove `.only` --- .../create-billing-invoice-licence.service.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js b/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js index 6d0c2b7a62..c47ab84720 100644 --- a/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js +++ b/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js @@ -16,7 +16,7 @@ const DatabaseHelper = require('../../support/helpers/database.helper.js') // Thing under test const CreateBillingInvoiceLicenceService = require('../../../app/services/supplementary-billing/create-billing-invoice-licence.service.js') -describe.only('Create Billing Invoice Licence service', () => { +describe('Create Billing Invoice Licence service', () => { beforeEach(async () => { await DatabaseHelper.clean() }) From 61b4fb146ec08a1d831dc6cd897c337f41097e78 Mon Sep 17 00:00:00 2001 From: Stuart Adair <43574728+StuAA78@users.noreply.github.com> Date: Mon, 20 Feb 2023 13:29:23 +0000 Subject: [PATCH 4/5] Remove unnecessary white space --- .../create-billing-invoice-licence.service.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/services/supplementary-billing/create-billing-invoice-licence.service.js b/app/services/supplementary-billing/create-billing-invoice-licence.service.js index 71900fe3fc..2ef39ceb17 100644 --- a/app/services/supplementary-billing/create-billing-invoice-licence.service.js +++ b/app/services/supplementary-billing/create-billing-invoice-licence.service.js @@ -22,7 +22,6 @@ async function go (billingInvoice, licence) { billingInvoiceId: billingInvoice.billingInvoiceId, licenceRef: licence.licenceRef, licenceId: licence.licenceId - }) .returning('*') From 8ccc73ef345e50e5868581d484bb75182a89890a Mon Sep 17 00:00:00 2001 From: Stuart Adair <43574728+StuAA78@users.noreply.github.com> Date: Mon, 20 Feb 2023 13:40:13 +0000 Subject: [PATCH 5/5] Update test/services/supplementary-billing/create-billing-invoice-licence.service.test.js Co-authored-by: Alan Cruikshanks --- .../create-billing-invoice-licence.service.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js b/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js index c47ab84720..399df473c2 100644 --- a/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js +++ b/test/services/supplementary-billing/create-billing-invoice-licence.service.test.js @@ -30,7 +30,7 @@ describe('Create Billing Invoice Licence service', () => { licence = await LicenceHelper.add() }) - it('creates an event record', async () => { + it('returns the new billing invoice licence instance', async () => { const result = await CreateBillingInvoiceLicenceService.go(billingInvoice, licence) expect(result).to.be.an.instanceOf(BillingInvoiceLicenceModel)