From f48c5d36b66a4b459319c2c7120182d9207ed6ca Mon Sep 17 00:00:00 2001 From: Becky Ransome <91424856+Beckyrose200@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:32:47 +0100 Subject: [PATCH] Fix fetching returns for two part tariff (#920) https://eaflood.atlassian.net/browse/WATER-4188 As part of the ongoing testing for the two-part tariff engine it was found that there were too many returns matching to a charge element. The returns were spread over two years (all within the financial year but starting and finishing outside). This wasn't a bug in the code but rather an A|C that wasn't fleshed out properly. The team don't want returns to be pulled in if the end date of the return is outside the financial year. This PR is to update the fetching query to adjust the start and end dates that the returns can be picked from. --- .../fetch-return-logs-for-licence.service.js | 2 +- ...ch-return-logs-for-licence.service.test.js | 42 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.js b/app/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.js index ef2230656f..d27deea78a 100644 --- a/app/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.js +++ b/app/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.js @@ -43,8 +43,8 @@ async function _fetch (licenceRef, billingPeriod) { .where('licenceRef', licenceRef) // water-abstraction-service filters out old return logs in this way: see `src/lib/services/returns/api-connector.js` .where('startDate', '>=', '2008-04-01') - .where('startDate', '<=', billingPeriod.endDate) .where('endDate', '>=', billingPeriod.startDate) + .where('endDate', '<=', billingPeriod.endDate) .whereJsonPath('metadata', '$.isTwoPartTariff', '=', true) .orderBy('startDate', 'ASC') .orderBy('returnReference', 'ASC') diff --git a/test/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.test.js b/test/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.test.js index b267991258..f6895eb443 100644 --- a/test/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.test.js +++ b/test/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.test.js @@ -146,10 +146,31 @@ describe('Fetch Return Logs for Licence service', () => { expect(result[0].returnSubmissions[0].returnSubmissionLines).to.have.length(0) }) }) + + describe('where the return logs start date is outside the billing period but the end date is inside', () => { + beforeEach(async () => { + await ReturnLogHelper.add({ + startDate: new Date('2022-01-01'), + endDate: new Date('2022-12-31') + }) + const { id } = returnLogRecord + + await ReturnSubmissionHelper.add({ returnLogId: id }) + }) + + it('returns the return log and return submission lines that are applicable', async () => { + const { licenceRef } = returnLogRecord + const result = await FetchReturnLogsForLicenceService.go(licenceRef, billingPeriod) + + expect(result).to.have.length(1) + expect(result[0].id).to.equal(returnLogRecord.id) + expect(result[0].description).to.equal('The Description') + }) + }) }) describe('when there are NO valid return logs that should be considered', () => { - describe('because the return log is outside the billing period', () => { + describe('because the return log is fully outside the billing period', () => { beforeEach(async () => { returnLogRecord = await ReturnLogHelper.add({ startDate: new Date('2023-04-01'), @@ -168,6 +189,25 @@ describe('Fetch Return Logs for Licence service', () => { }) }) + describe('because the return logs start date is inside the billing period but end date is outside', () => { + beforeEach(async () => { + returnLogRecord = await ReturnLogHelper.add({ + startDate: new Date('2023-01-01'), + endDate: new Date('2023-12-31') + }) + const { id } = returnLogRecord + + await ReturnSubmissionHelper.add({ returnLogId: id }) + }) + + it('returns no records', async () => { + const { licenceRef } = returnLogRecord + const result = await FetchReturnLogsForLicenceService.go(licenceRef, billingPeriod) + + expect(result).to.have.length(0) + }) + }) + describe('because the return log is not two-part-tariff', () => { beforeEach(async () => { const metadata = {