-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate Billing Invoice Licence record for SROC (#124)
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. As part of this we need to generate`billing_invoice_licence` entities, which link billing invoices with licences. We already have this entity so this PR implements `CreateBillingInvoiceLicenceService` which can create these.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
app/services/supplementary-billing/create-billing-invoice-licence.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'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 | ||
} |
43 changes: 43 additions & 0 deletions
43
test/services/supplementary-billing/create-billing-invoice-licence.service.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('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('returns the new billing invoice licence instance', 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) | ||
}) | ||
}) | ||
}) |