Skip to content

Commit

Permalink
Fix test licences query (#50)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-3787

We've built a query to demonstrate what licences we are considering when building an SROC supplementary bill run. It's been highlighted that the query is returning duplicate results. A quick check found it's where we have a licence flagged for supplementary billing that has more than 1 SROC charge version. The inner join means we get a row per charge version.

This change fixes the issue, making our results distinct.
  • Loading branch information
Cruikshanks authored Dec 13, 2022
1 parent 7c5b1e7 commit 0c20573
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function go (region) {

async function _fetch (region) {
const result = await LicenceModel.query()
.distinctOn('licence_id')
.innerJoinRelated('chargeVersions')
.where('region_id', region.regionId)
.where('include_in_supplementary_billing', 'yes')
Expand Down
14 changes: 14 additions & 0 deletions test/services/supplementary-billing/fetch-licences.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ describe('Fetch Licences service', () => {
})
})

describe('and that have multiple SROC charge versions', () => {
beforeEach(async () => {
await ChargeVersionHelper.add({}, testRecords[0])
await ChargeVersionHelper.add({}, testRecords[0])
})

it('returns a licence only once in the results', async () => {
const result = await FetchLicencesService.go(region)

expect(result.length).to.equal(1)
expect(result[0].licenceId).to.equal(testRecords[0].licenceId)
})
})

describe('but do not have an SROC charge version', () => {
it('returns no results', async () => {
const result = await FetchLicencesService.go(region)
Expand Down

0 comments on commit 0c20573

Please sign in to comment.