Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Billing Invoice Licence record for SROC #124

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
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('creates an event record', async () => {
StuAA78 marked this conversation as resolved.
Show resolved Hide resolved
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)
})
})
})