From 8bc8aa213c4893c25a8f3a1dc09e4e999e51c2fa Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Mon, 6 Nov 2023 11:44:17 +0000 Subject: [PATCH 01/11] Handle create 2PT bill run requests https://eaflood.atlassian.net/browse/WATER-4204 We need to update the validation logic used that checks the incoming request to accept an optional start and end year for 2PT requests. We then need to pass this information down to our `app/services/billing/start-bill-run-process.service.js`. The logic in that service will need to be updated to handle both 2PT and supplementary bill runs. For example, it assumes there will be multiple building periods calculated from the current year. For 2PT it will only be the current year, else the financial year provided in the request. From 3c8844bdc20b462aa0d57db4935983b802df1e53 Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Mon, 6 Nov 2023 14:43:27 +0000 Subject: [PATCH 02/11] Add `financialYear` to controller --- app/controllers/bill-runs.controller.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/bill-runs.controller.js b/app/controllers/bill-runs.controller.js index a13cb03f2f..fbc15e844f 100644 --- a/app/controllers/bill-runs.controller.js +++ b/app/controllers/bill-runs.controller.js @@ -19,7 +19,9 @@ async function create (request, h) { try { const { region, type, user } = validatedData.value - const result = await StartBillRunProcessService.go(region, type, user) + // For Two Part Tariff bill runs an additional value for the `financialYear` will be included in the payload + const financialYear = validatedData.value?.financialYear + const result = await StartBillRunProcessService.go(region, type, user, financialYear) return h.response(result).code(200) } catch (error) { From f075e0e750ca56e6b97f9d30a62a1146e7035af6 Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Mon, 6 Nov 2023 14:43:55 +0000 Subject: [PATCH 03/11] Add `financialYear` to validator --- app/validators/create-bill-run.validator.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/validators/create-bill-run.validator.js b/app/validators/create-bill-run.validator.js index 0d61dae0c9..ca9069e09f 100644 --- a/app/validators/create-bill-run.validator.js +++ b/app/validators/create-bill-run.validator.js @@ -17,7 +17,8 @@ function go (data) { scheme: Joi.string().valid('sroc').required(), region: Joi.string().guid().required(), user: Joi.string().email().required(), - previousBillRunId: Joi.string().guid().optional() + previousBillRunId: Joi.string().guid().optional(), + financialYear: Joi.number().integer().optional() }) return schema.validate(data) From de41b8ba06f83414bec44abb05d0bef7d4b2cc3a Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Mon, 6 Nov 2023 14:44:31 +0000 Subject: [PATCH 04/11] Pass `financialYear` to 2PT service --- app/services/billing/start-bill-run-process.service.js | 8 ++++---- .../billing/two-part-tariff/process-bill-run.service.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/services/billing/start-bill-run-process.service.js b/app/services/billing/start-bill-run-process.service.js index 76d77db2c6..923aaa66da 100644 --- a/app/services/billing/start-bill-run-process.service.js +++ b/app/services/billing/start-bill-run-process.service.js @@ -20,13 +20,13 @@ const TwoPartTariffProcessBillRunService = require('./two-part-tariff/process-bi * * @returns {Object} Object that will be the JSON response returned to the client */ -async function go (regionId, batchType, userEmail) { +async function go (regionId, batchType, userEmail, financialYear) { const billingPeriods = DetermineBillingPeriodsService.go() const financialYearEndings = _financialYearEndings(billingPeriods) const billRun = await InitiateBillRunService.go(financialYearEndings, regionId, batchType, userEmail) - _processBillRun(billRun, billingPeriods) + _processBillRun(billRun, billingPeriods, financialYear) return _response(billRun) } @@ -38,14 +38,14 @@ function _financialYearEndings (billingPeriods) { } } -function _processBillRun (billRun, billingPeriods) { +function _processBillRun (billRun, billingPeriods, financialYear) { // We do not `await` the bill run being processed so we can leave it to run in the background while we return an immediate response switch (billRun.batchType) { case 'supplementary': SupplementaryProcessBillRunService.go(billRun, billingPeriods) break case 'two_part_tariff': - TwoPartTariffProcessBillRunService.go(billRun, billingPeriods) + TwoPartTariffProcessBillRunService.go(billRun, billingPeriods, financialYear) break } } diff --git a/app/services/billing/two-part-tariff/process-bill-run.service.js b/app/services/billing/two-part-tariff/process-bill-run.service.js index 2c8e8dfebe..f804af2488 100644 --- a/app/services/billing/two-part-tariff/process-bill-run.service.js +++ b/app/services/billing/two-part-tariff/process-bill-run.service.js @@ -8,8 +8,8 @@ /** * Functionality not yet implemented */ -async function go (_billRun, _billingPeriods) { - throw new Error('Two Part Tariff is not yet implemented') +async function go (_billRun, _billingPeriods, financialYear) { + throw new Error(`Two Part Tariff is not yet implemented for Financial Year: ${financialYear}`) } module.exports = { From d0faea6da8967126702aaf8e98c4e188e5d90847 Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Mon, 6 Nov 2023 14:54:30 +0000 Subject: [PATCH 05/11] Fix test --- .../billing/two-part-tariff/process-bill-run.service.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/services/billing/two-part-tariff/process-bill-run.service.test.js b/test/services/billing/two-part-tariff/process-bill-run.service.test.js index b356e89373..141d521033 100644 --- a/test/services/billing/two-part-tariff/process-bill-run.service.test.js +++ b/test/services/billing/two-part-tariff/process-bill-run.service.test.js @@ -13,10 +13,10 @@ const TwoPartTariffProcessBillRunService = require('../../../../app/services/bil describe('Two Part Tariff Process Bill Run service', () => { describe('when the service is called', () => { it('throws an error', async () => { - const error = await expect(TwoPartTariffProcessBillRunService.go()).to.reject() + const error = await expect(TwoPartTariffProcessBillRunService.go('billRun', 'billingPeriods', 2022)).to.reject() expect(error).to.be.an.instanceOf(Error) - expect(error.message).to.equal('Two Part Tariff is not yet implemented') + expect(error.message).to.equal('Two Part Tariff is not yet implemented for Financial Year: 2022') }) }) }) From 7064bb68e293729d4065af831baec5836fdb7556 Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Mon, 6 Nov 2023 16:35:20 +0000 Subject: [PATCH 06/11] Rename `financialYear` to `financialYearEnding` --- app/controllers/bill-runs.controller.js | 6 ++---- app/services/billing/start-bill-run-process.service.js | 8 ++++---- .../billing/two-part-tariff/process-bill-run.service.js | 4 ++-- app/validators/create-bill-run.validator.js | 4 ++-- .../two-part-tariff/process-bill-run.service.test.js | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/controllers/bill-runs.controller.js b/app/controllers/bill-runs.controller.js index fbc15e844f..8c00bfbe9d 100644 --- a/app/controllers/bill-runs.controller.js +++ b/app/controllers/bill-runs.controller.js @@ -18,10 +18,8 @@ async function create (request, h) { } try { - const { region, type, user } = validatedData.value - // For Two Part Tariff bill runs an additional value for the `financialYear` will be included in the payload - const financialYear = validatedData.value?.financialYear - const result = await StartBillRunProcessService.go(region, type, user, financialYear) + const { region, type, user, financialYearEnding } = validatedData.value + const result = await StartBillRunProcessService.go(region, type, user, financialYearEnding) return h.response(result).code(200) } catch (error) { diff --git a/app/services/billing/start-bill-run-process.service.js b/app/services/billing/start-bill-run-process.service.js index 923aaa66da..c0237ff379 100644 --- a/app/services/billing/start-bill-run-process.service.js +++ b/app/services/billing/start-bill-run-process.service.js @@ -20,13 +20,13 @@ const TwoPartTariffProcessBillRunService = require('./two-part-tariff/process-bi * * @returns {Object} Object that will be the JSON response returned to the client */ -async function go (regionId, batchType, userEmail, financialYear) { +async function go (regionId, batchType, userEmail, financialYearEnding) { const billingPeriods = DetermineBillingPeriodsService.go() const financialYearEndings = _financialYearEndings(billingPeriods) const billRun = await InitiateBillRunService.go(financialYearEndings, regionId, batchType, userEmail) - _processBillRun(billRun, billingPeriods, financialYear) + _processBillRun(billRun, billingPeriods, financialYearEnding) return _response(billRun) } @@ -38,14 +38,14 @@ function _financialYearEndings (billingPeriods) { } } -function _processBillRun (billRun, billingPeriods, financialYear) { +function _processBillRun (billRun, billingPeriods, financialYearEnding) { // We do not `await` the bill run being processed so we can leave it to run in the background while we return an immediate response switch (billRun.batchType) { case 'supplementary': SupplementaryProcessBillRunService.go(billRun, billingPeriods) break case 'two_part_tariff': - TwoPartTariffProcessBillRunService.go(billRun, billingPeriods, financialYear) + TwoPartTariffProcessBillRunService.go(billRun, billingPeriods, financialYearEnding) break } } diff --git a/app/services/billing/two-part-tariff/process-bill-run.service.js b/app/services/billing/two-part-tariff/process-bill-run.service.js index f804af2488..601a394b61 100644 --- a/app/services/billing/two-part-tariff/process-bill-run.service.js +++ b/app/services/billing/two-part-tariff/process-bill-run.service.js @@ -8,8 +8,8 @@ /** * Functionality not yet implemented */ -async function go (_billRun, _billingPeriods, financialYear) { - throw new Error(`Two Part Tariff is not yet implemented for Financial Year: ${financialYear}`) +async function go (_billRun, _billingPeriods, financialYearEnding) { + throw new Error(`Two Part Tariff is not yet implemented for Financial Year Ending: ${financialYearEnding}`) } module.exports = { diff --git a/app/validators/create-bill-run.validator.js b/app/validators/create-bill-run.validator.js index ca9069e09f..800fe3e7c4 100644 --- a/app/validators/create-bill-run.validator.js +++ b/app/validators/create-bill-run.validator.js @@ -17,8 +17,8 @@ function go (data) { scheme: Joi.string().valid('sroc').required(), region: Joi.string().guid().required(), user: Joi.string().email().required(), - previousBillRunId: Joi.string().guid().optional(), - financialYear: Joi.number().integer().optional() + financialYearEnding: Joi.number().integer().optional(), + previousBillRunId: Joi.string().guid().optional() }) return schema.validate(data) diff --git a/test/services/billing/two-part-tariff/process-bill-run.service.test.js b/test/services/billing/two-part-tariff/process-bill-run.service.test.js index 141d521033..1ab89da7e2 100644 --- a/test/services/billing/two-part-tariff/process-bill-run.service.test.js +++ b/test/services/billing/two-part-tariff/process-bill-run.service.test.js @@ -16,7 +16,7 @@ describe('Two Part Tariff Process Bill Run service', () => { const error = await expect(TwoPartTariffProcessBillRunService.go('billRun', 'billingPeriods', 2022)).to.reject() expect(error).to.be.an.instanceOf(Error) - expect(error.message).to.equal('Two Part Tariff is not yet implemented for Financial Year: 2022') + expect(error.message).to.equal('Two Part Tariff is not yet implemented for Financial Year Ending: 2022') }) }) }) From 2cd9c71f242beebe9e56db52d24c820f2cb127de Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 7 Nov 2023 16:43:47 +0000 Subject: [PATCH 07/11] Create period from 'financialYearEnding` --- .../determine-billing-periods.service.js | 23 +++++++++++++++---- .../billing/start-bill-run-process.service.js | 8 +++---- .../process-bill-run.service.js | 4 ++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/services/billing/determine-billing-periods.service.js b/app/services/billing/determine-billing-periods.service.js index 5036305519..4692d69483 100644 --- a/app/services/billing/determine-billing-periods.service.js +++ b/app/services/billing/determine-billing-periods.service.js @@ -15,7 +15,7 @@ * * @returns {Object[]} An array of billing periods each containing a `startDate` and `endDate`. */ -function go () { +function go (financialYearEnding) { const SROC_FIRST_FIN_YEAR_END = 2023 const NO_OF_YEARS_TO_LOOK_BACK = 5 @@ -27,14 +27,20 @@ function go () { end: { day: 31, month: 2 } } + // Two-part-tariff bill runs will always be a single period and will provide a value for `financialYearEnding` so we + // just return a single period based on that value. `financialYearEnding` is null for other bill run types. + if (financialYearEnding) { + _addBillingPeriod(billingPeriods, financialPeriod, financialYearEnding - 1, financialYearEnding) + + return billingPeriods + } + const years = _determineStartAndEndYear(financialPeriod) const earliestSrocFinYearEnd = Math.max(SROC_FIRST_FIN_YEAR_END, (years.endYear - NO_OF_YEARS_TO_LOOK_BACK)) while (earliestSrocFinYearEnd <= years.endYear) { - billingPeriods.push({ - startDate: new Date(years.startYear, financialPeriod.start.month, financialPeriod.start.day), - endDate: new Date(years.endYear, financialPeriod.end.month, financialPeriod.end.day) - }) + _addBillingPeriod(billingPeriods, financialPeriod, years.startYear, years.endYear) + years.startYear-- years.endYear-- } @@ -42,6 +48,13 @@ function go () { return billingPeriods } +function _addBillingPeriod (billingPeriods, financialPeriod, startYear, endYear) { + billingPeriods.push({ + startDate: new Date(startYear, financialPeriod.start.month, financialPeriod.start.day), + endDate: new Date(endYear, financialPeriod.end.month, financialPeriod.end.day) + }) +} + function _determineStartAndEndYear (financialPeriod) { const currentDate = new Date() const currentYear = currentDate.getFullYear() diff --git a/app/services/billing/start-bill-run-process.service.js b/app/services/billing/start-bill-run-process.service.js index c0237ff379..f5da8d81ff 100644 --- a/app/services/billing/start-bill-run-process.service.js +++ b/app/services/billing/start-bill-run-process.service.js @@ -21,12 +21,12 @@ const TwoPartTariffProcessBillRunService = require('./two-part-tariff/process-bi * @returns {Object} Object that will be the JSON response returned to the client */ async function go (regionId, batchType, userEmail, financialYearEnding) { - const billingPeriods = DetermineBillingPeriodsService.go() + const billingPeriods = DetermineBillingPeriodsService.go(financialYearEnding) const financialYearEndings = _financialYearEndings(billingPeriods) const billRun = await InitiateBillRunService.go(financialYearEndings, regionId, batchType, userEmail) - _processBillRun(billRun, billingPeriods, financialYearEnding) + _processBillRun(billRun, billingPeriods) return _response(billRun) } @@ -38,14 +38,14 @@ function _financialYearEndings (billingPeriods) { } } -function _processBillRun (billRun, billingPeriods, financialYearEnding) { +function _processBillRun (billRun, billingPeriods) { // We do not `await` the bill run being processed so we can leave it to run in the background while we return an immediate response switch (billRun.batchType) { case 'supplementary': SupplementaryProcessBillRunService.go(billRun, billingPeriods) break case 'two_part_tariff': - TwoPartTariffProcessBillRunService.go(billRun, billingPeriods, financialYearEnding) + TwoPartTariffProcessBillRunService.go(billRun, billingPeriods) break } } diff --git a/app/services/billing/two-part-tariff/process-bill-run.service.js b/app/services/billing/two-part-tariff/process-bill-run.service.js index 601a394b61..ecba5d8232 100644 --- a/app/services/billing/two-part-tariff/process-bill-run.service.js +++ b/app/services/billing/two-part-tariff/process-bill-run.service.js @@ -8,8 +8,8 @@ /** * Functionality not yet implemented */ -async function go (_billRun, _billingPeriods, financialYearEnding) { - throw new Error(`Two Part Tariff is not yet implemented for Financial Year Ending: ${financialYearEnding}`) +async function go (_billRun, billingPeriods) { + throw new Error(`Two Part Tariff is not yet implemented for Financial Year Ending: ${billingPeriods[0].endDate.getFullYear()}`) } module.exports = { From 4a847bae0e265013eaf5c14bb1f20a000624e7d6 Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 7 Nov 2023 17:03:30 +0000 Subject: [PATCH 08/11] Update `process-bill-run` test --- .../two-part-tariff/process-bill-run.service.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/services/billing/two-part-tariff/process-bill-run.service.test.js b/test/services/billing/two-part-tariff/process-bill-run.service.test.js index 1ab89da7e2..702baca1ca 100644 --- a/test/services/billing/two-part-tariff/process-bill-run.service.test.js +++ b/test/services/billing/two-part-tariff/process-bill-run.service.test.js @@ -10,13 +10,15 @@ const { expect } = Code // Thing under test const TwoPartTariffProcessBillRunService = require('../../../../app/services/billing/two-part-tariff/process-bill-run.service.js') -describe('Two Part Tariff Process Bill Run service', () => { +describe.only('Two Part Tariff Process Bill Run service', () => { describe('when the service is called', () => { + const billingPeriods = [{ endDate: new Date('2023-03-31') }] + it('throws an error', async () => { - const error = await expect(TwoPartTariffProcessBillRunService.go('billRun', 'billingPeriods', 2022)).to.reject() + const error = await expect(TwoPartTariffProcessBillRunService.go('billRun', billingPeriods)).to.reject() expect(error).to.be.an.instanceOf(Error) - expect(error.message).to.equal('Two Part Tariff is not yet implemented for Financial Year Ending: 2022') + expect(error.message).to.equal('Two Part Tariff is not yet implemented for Financial Year Ending: 2023') }) }) }) From f020013e9304b3398f1d55bf53f5fc3a169f3b0e Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 7 Nov 2023 18:41:10 +0000 Subject: [PATCH 09/11] Update and add validator tests --- .../create-bill-run.validator.test.js | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/test/validators/create-bill-run.validator.test.js b/test/validators/create-bill-run.validator.test.js index 43a73f6acc..6c49c2f3bc 100644 --- a/test/validators/create-bill-run.validator.test.js +++ b/test/validators/create-bill-run.validator.test.js @@ -18,6 +18,7 @@ describe('Create Bill Run validator', () => { scheme: 'sroc', region: '07ae7f3a-2677-4102-b352-cc006828948c', user: 'test.user@defra.gov.uk', + financialYearEnding: 2023, previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603' } @@ -28,17 +29,41 @@ describe('Create Bill Run validator', () => { scheme: 'sroc', region: '07ae7f3a-2677-4102-b352-cc006828948c', user: 'test.user@defra.gov.uk', + financialYearEnding: 2023, previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603' }) }) + describe('which does not include `financialYearEnding`', () => { + it('returns validated data', async () => { + const validData = { + type: 'supplementary', + scheme: 'sroc', + region: '07ae7f3a-2677-4102-b352-cc006828948c', + user: 'test.user@defra.gov.uk', + previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603' + } + + const result = await CreateBillRunValidator.go(validData) + + expect(result.value).to.equal({ + type: 'supplementary', + scheme: 'sroc', + region: '07ae7f3a-2677-4102-b352-cc006828948c', + user: 'test.user@defra.gov.uk', + previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603' + }) + }) + }) + describe('which does not include `previousBillRunId`', () => { it('returns validated data', async () => { const validData = { type: 'supplementary', scheme: 'sroc', region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk' + user: 'test.user@defra.gov.uk', + financialYearEnding: 2023 } const result = await CreateBillRunValidator.go(validData) @@ -47,7 +72,8 @@ describe('Create Bill Run validator', () => { type: 'supplementary', scheme: 'sroc', region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk' + user: 'test.user@defra.gov.uk', + financialYearEnding: 2023 }) }) }) @@ -169,5 +195,21 @@ describe('Create Bill Run validator', () => { expect(result.error).to.not.be.empty() }) }) + + describe('because `financialYearEnding` has an invalid value', () => { + it('returns an error', async () => { + const invalidData = { + type: 'supplementary', + scheme: 'sroc', + region: '07ae7f3a-2677-4102-b352-cc006828948c', + user: 'test.user@defra.gov.uk', + financialYearEnding: 'INVALID' + } + + const result = await CreateBillRunValidator.go(invalidData) + + expect(result.error).to.not.be.empty() + }) + }) }) }) From 16aa03ddf00671e79d5a61402bd63df25480bb4b Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 7 Nov 2023 18:58:24 +0000 Subject: [PATCH 10/11] Add and update `determin-billing-periods` test --- .../determine-billing-periods.service.test.js | 28 ++++++++++++++++--- .../process-bill-run.service.test.js | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/test/services/billing/determine-billing-periods.service.test.js b/test/services/billing/determine-billing-periods.service.test.js index 8e0f047877..93c001a0f9 100644 --- a/test/services/billing/determine-billing-periods.service.test.js +++ b/test/services/billing/determine-billing-periods.service.test.js @@ -22,7 +22,7 @@ describe('Billing Periods service', () => { }) describe('when the date is in 2022 and falls within the 2022 financial year', () => { - beforeEach(async () => { + beforeEach(() => { testDate = new Date('2022-04-01') expectedResult = { startDate: new Date('2022-04-01'), @@ -41,7 +41,7 @@ describe('Billing Periods service', () => { }) describe('when the date is in 2023 and falls within the 2022 financial year', () => { - beforeEach(async () => { + beforeEach(() => { testDate = new Date('2023-03-01') expectedResult = { startDate: new Date('2022-04-01'), @@ -60,7 +60,7 @@ describe('Billing Periods service', () => { }) describe('when the date is in 2023 and falls within the 2023 financial year', () => { - beforeEach(async () => { + beforeEach(() => { testDate = new Date('2023-10-10') expectedResult = [ { @@ -82,10 +82,30 @@ describe('Billing Periods service', () => { expect(result).to.have.length(2) expect(result).to.equal(expectedResult) }) + + describe('when the `financialYearEnding` of 2023 is passed to the service', () => { + const financialYearEnding = 2023 + + beforeEach(() => { + expectedResult = [ + { + startDate: new Date('2022-04-01'), + endDate: new Date('2023-03-31') + } + ] + }) + + it('returns the expected date range', () => { + const result = DetermineBillingPeriodsService.go(financialYearEnding) + + expect(result).to.have.length(1) + expect(result).to.equal(expectedResult) + }) + }) }) describe('when the date is in 2030 and falls within the 2030 financial year', () => { - beforeEach(async () => { + beforeEach(() => { testDate = new Date('2030-10-10') expectedResult = [ { diff --git a/test/services/billing/two-part-tariff/process-bill-run.service.test.js b/test/services/billing/two-part-tariff/process-bill-run.service.test.js index 702baca1ca..4c75241ed5 100644 --- a/test/services/billing/two-part-tariff/process-bill-run.service.test.js +++ b/test/services/billing/two-part-tariff/process-bill-run.service.test.js @@ -10,7 +10,7 @@ const { expect } = Code // Thing under test const TwoPartTariffProcessBillRunService = require('../../../../app/services/billing/two-part-tariff/process-bill-run.service.js') -describe.only('Two Part Tariff Process Bill Run service', () => { +describe('Two Part Tariff Process Bill Run service', () => { describe('when the service is called', () => { const billingPeriods = [{ endDate: new Date('2023-03-31') }] From 07af7b028094a3bb2987119af6eba7091091e05c Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 7 Nov 2023 19:32:58 +0000 Subject: [PATCH 11/11] Tidy up --- app/services/billing/determine-billing-periods.service.js | 4 ++++ app/services/billing/start-bill-run-process.service.js | 1 + 2 files changed, 5 insertions(+) diff --git a/app/services/billing/determine-billing-periods.service.js b/app/services/billing/determine-billing-periods.service.js index 4692d69483..80fb2d318a 100644 --- a/app/services/billing/determine-billing-periods.service.js +++ b/app/services/billing/determine-billing-periods.service.js @@ -13,6 +13,10 @@ * periods for the current year plus a maximum of the previous 5 years. Or to the earliest possible `endYear` for SROC * which is 2023, whichever is the greatest. * + * If a `financialYearEnding` is passed to this service a single billing period will be generated based on that value. + * + * @param {Number} financialYearEnding End year of the bill run. Only populated for two-part-tariff + * * @returns {Object[]} An array of billing periods each containing a `startDate` and `endDate`. */ function go (financialYearEnding) { diff --git a/app/services/billing/start-bill-run-process.service.js b/app/services/billing/start-bill-run-process.service.js index f5da8d81ff..00412bdf25 100644 --- a/app/services/billing/start-bill-run-process.service.js +++ b/app/services/billing/start-bill-run-process.service.js @@ -17,6 +17,7 @@ const TwoPartTariffProcessBillRunService = require('./two-part-tariff/process-bi * @param {String} regionId Id of the region the bill run is for * @param {String} batchType Type of bill run, for example, supplementary * @param {String} userEmail Email address of the user who initiated the bill run + * @param {Number} financialYearEnding End year of the bill run. Only populated for two-part-tariff * * @returns {Object} Object that will be the JSON response returned to the client */