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

Fix reissuing ALCS invoice bug #311

Merged
merged 4 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Expand Up @@ -8,7 +8,7 @@
const BillingInvoiceModel = require('../../../models/water/billing-invoice.model.js')

/**
* Takes a region and fetches billing invoices in that region marked for reissuing, along with their transactions
* Takes a region and fetches sroc billing invoices in that region marked for reissuing, along with their transactions
*
* @param {String} regionId The uuid of the region
*
Expand All @@ -28,6 +28,7 @@ async function go (regionId) {
.where('isFlaggedForRebilling', true)
.joinRelated('billingBatch')
.where('billingBatch.regionId', regionId)
.where('billingBatch.scheme', 'sroc')
.withGraphFetched('billingInvoiceLicences.billingTransactions')
.modifyGraph('billingInvoiceLicences', (builder) => {
builder.select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const FetchInvoicesToBeReissuedService = require('../../../../app/services/billi
describe('Fetch Invoices To Be Reissued service', () => {
let billingBatch
let billingInvoice
let alcsBillingInvoice

beforeEach(async () => {
await DatabaseHelper.clean()
Expand All @@ -30,6 +31,15 @@ describe('Fetch Invoices To Be Reissued service', () => {
billingInvoice = await BillingInvoiceHelper.add({ billingBatchId: billingBatch.billingBatchId })
const { billingInvoiceLicenceId } = await BillingInvoiceLicenceHelper.add({ billingInvoiceId: billingInvoice.billingInvoiceId })
await BillingTransactionHelper.add({ billingInvoiceLicenceId })

// Set up a separate billing batch which we will manually patch to be alcs
const alcsBillingBatch = await BillingBatchHelper.add()
StuAA78 marked this conversation as resolved.
Show resolved Hide resolved
alcsBillingInvoice = await BillingInvoiceHelper.add({ billingBatchId: alcsBillingBatch.billingBatchId })
const { billingInvoiceLicenceId: alcsBillingInvoiceLicenceId } = await BillingInvoiceLicenceHelper.add({
billingInvoiceId: alcsBillingInvoice.billingInvoiceId
})
await BillingTransactionHelper.add({ billingInvoiceLicenceId: alcsBillingInvoiceLicenceId })
await alcsBillingBatch.$query().patch({ scheme: 'alcs' })
})

describe('when there are no billing invoices to be reissued', () => {
Expand Down Expand Up @@ -81,6 +91,19 @@ describe('Fetch Invoices To Be Reissued service', () => {
'billingTransactions'
])
})

describe('and there are alcs billing invoices to be reissued', () => {
beforeEach(async () => {
await alcsBillingInvoice.$query().patch({ isFlaggedForRebilling: true })
})

it('returns only sroc billing invoices', async () => {
const result = await FetchInvoicesToBeReissuedService.go(billingBatch.regionId)

expect(result).to.have.length(1)
expect(result[0].billingInvoiceId).to.equal(billingInvoice.billingInvoiceId)
})
})
})

describe('when fetching from the db fails', () => {
Expand Down