Skip to content

Commit

Permalink
Implement chage to query
Browse files Browse the repository at this point in the history
We aso needed to tweak the helper to allow us to support this scenario.
  • Loading branch information
Cruikshanks committed Dec 7, 2022
1 parent 0903217 commit db839c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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
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 @@ -30,10 +31,10 @@ describe('Fetch Licences service', () => {

describe('and that have an SROC charge version', () => {
beforeEach(async () => {
// testRecords = await LicenceHelper.add({ include_in_supplementary_billing: 'yes' })
await ChargeVersionHelper.add({}, testRecords[0])
})

it('returns results', async () => {
it.only('returns results', async () => {
const result = await FetchLicencesService.go(region)

expect(result.length).to.equal(1)
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

0 comments on commit db839c0

Please sign in to comment.