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

Update licence query to just return SROC #43

Merged
merged 4 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions app/services/supplementary-billing/fetch-licences.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class FetchLicencesService {

static async _fetch (region) {
const result = await LicenceModel.query()
.innerJoinRelated('chargeVersions')
.where('region_id', region.regionId)
.where('include_in_supplementary_billing', 'yes')
.where('chargeVersions.scheme', 'sroc')

return result
}
Expand Down
23 changes: 19 additions & 4 deletions test/services/supplementary-billing/fetch-licences.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { describe, it, beforeEach } = exports.lab = Lab.script()
const { expect } = Code

// Test helpers
const ChargeVersionHelper = require('../../support/helpers/charge-version.helper.js')
const DatabaseHelper = require('../../support/helpers/database.helper.js')
const LicenceHelper = require('../../support/helpers/licence.helper.js')

Expand All @@ -28,11 +29,25 @@ describe('Fetch Licences service', () => {
testRecords = await LicenceHelper.add({ include_in_supplementary_billing: 'yes' })
})

it('returns results', async () => {
const result = await FetchLicencesService.go(region)
describe('and that have an SROC charge version', () => {
beforeEach(async () => {
await ChargeVersionHelper.add({}, testRecords[0])
})

it('returns 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)

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

Expand Down
6 changes: 5 additions & 1 deletion test/support/helpers/charge-version.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class ChargeVersionHelper {
* @returns {string} The ID of the newly created record
*/
static async add (data = {}, licence = {}) {
const licenceId = await this._addLicence(licence)
let licenceId = licence?.licenceId
if (!licenceId) {
licenceId = await this._addLicence(licence)
}

const insertData = this.defaults({ ...data, licence_id: licenceId })

const result = await db.table('water.charge_versions')
Expand Down