Skip to content

Commit

Permalink
Add changeReason to two-part-tariff fetch-charge-versions service (
Browse files Browse the repository at this point in the history
…#603)

https://eaflood.atlassian.net/browse/WATER-4188

Whilst hacking away at two-part-tariff we have found that we are not returning the `chargeVersion` `changeReason`. We need to persist this data so this PR will add it to the service.
  • Loading branch information
Jozzey authored Dec 18, 2023
1 parent fbae6f7 commit b585a78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ async function _fetch (regionCode, billingPeriod) {
.whereJsonPath('chargeReferences.adjustments', '$.s127', '=', true)
)
.orderBy('chargeVersions.licenceRef')
.withGraphFetched('changeReason')
.modifyGraph('changeReason', (builder) => {
builder.select([
'description'
])
})
.withGraphFetched('licence')
.modifyGraph('licence', (builder) => {
builder.select([
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 ChangeReasonHelper = require('../../../support/helpers/change-reason.helper.js')
const ChargeCategoryHelper = require('../../../support/helpers/charge-category.helper.js')
const ChargeElementHelper = require('../../../support/helpers/charge-element.helper.js')
const ChargeReferenceHelper = require('../../../support/helpers/charge-reference.helper.js')
Expand Down Expand Up @@ -49,10 +50,12 @@ describe('Fetch Charge Versions service', () => {
const chargeVersionId = '2c2f0ab5-4f73-416e-b3f8-5ed19d81bd59'

beforeEach(async () => {
const { id: changeReasonId } = await ChangeReasonHelper.add()

// NOTE: The first part of the setup creates a charge version we will test exactly matches what we expect. The
// second part is to create another charge version with a different licence ref so we can test the order of the
// results
await ChargeVersionHelper.add({ id: chargeVersionId, licenceId, licenceRef, regionCode })
await ChargeVersionHelper.add({ id: chargeVersionId, licenceId, licenceRef, regionCode, changeReasonId })

const { id: chargeReferenceId } = await ChargeReferenceHelper.add({
id: 'a86837fa-cf25-42fe-8216-ea8c2d2c939d',
Expand Down Expand Up @@ -81,7 +84,7 @@ describe('Fetch Charge Versions service', () => {
// Second charge version to test ordering
const otherLicence = await LicenceHelper.add({ licenceRef: '01/130', regionId })
const chargeVersion = await ChargeVersionHelper.add(
{ licenceId: otherLicence.id, licenceRef: '01/130', regionCode }
{ licenceId: otherLicence.id, licenceRef: '01/130', regionCode, changeReasonId }
)
const chargeReference = await ChargeReferenceHelper.add({
chargeVersionId: chargeVersion.id,
Expand Down Expand Up @@ -153,7 +156,10 @@ describe('Fetch Charge Versions service', () => {
}
}
]
}]
}],
changeReason: {
description: 'Strategic review of charges (SRoC)'
}
})
})

Expand Down

0 comments on commit b585a78

Please sign in to comment.