diff --git a/app/services/billing/supplementary/fetch-charge-versions.service.js b/app/services/billing/supplementary/fetch-charge-versions.service.js index 79bcb18537..a3c7546781 100644 --- a/app/services/billing/supplementary/fetch-charge-versions.service.js +++ b/app/services/billing/supplementary/fetch-charge-versions.service.js @@ -130,9 +130,10 @@ async function _fetch (regionId, billingPeriod) { * We are interested in the associated licences to ensure that their supplementary billing flag is unset. */ function _extractLicenceIdsThenRemoveNonChargeableChargeVersions (allChargeVersions) { - const licenceIdsForPeriod = [] const chargeVersions = [] + let licenceIdsForPeriod = [] + for (const chargeVersion of allChargeVersions) { licenceIdsForPeriod.push(chargeVersion.licence.licenceId) @@ -141,6 +142,11 @@ function _extractLicenceIdsThenRemoveNonChargeableChargeVersions (allChargeVersi } } + // NOTE: If a licence appears multiple times in the results it will be pushed multiple times into the array. We have + // found a handy way to de-dupe an array of values is to create a new Set and then destructure it back to an array + // of values. + licenceIdsForPeriod = [...new Set(licenceIdsForPeriod)] + return { chargeVersions, licenceIdsForPeriod } } diff --git a/test/presenters/charging-module/create-transaction.presenter.test.js b/test/presenters/charging-module/create-transaction.presenter.test.js index 2a4d38edd7..71c7341653 100644 --- a/test/presenters/charging-module/create-transaction.presenter.test.js +++ b/test/presenters/charging-module/create-transaction.presenter.test.js @@ -27,6 +27,7 @@ describe('Charging Module Create Transaction presenter', () => { let transaction let licence + let region beforeEach(async () => { await DatabaseHelper.clean() @@ -34,7 +35,7 @@ describe('Charging Module Create Transaction presenter', () => { describe('when provided with a Transaction and Licence instance', () => { beforeEach(async () => { - const region = await RegionHelper.add() + region = await RegionHelper.add() // NOTE: In the context the presenter is used it is from a Licence instance returned by // FetchChargeVersionsService. We recreate how that instance is formed here, including extracting some of the @@ -65,6 +66,7 @@ describe('Charging Module Create Transaction presenter', () => { // standard transaction instance and amend some of the properties to match what FormatSrocTransactionLineService // does. transaction = await TransactionHelper.add() + transaction.chargeCategoryCode = '4.5.6' transaction.section127Agreement = false transaction.section130Agreement = false }) @@ -90,10 +92,10 @@ describe('Charging Module Create Transaction presenter', () => { expect(result.chargePeriod).to.equal('01-APR-2022 - 31-MAR-2023') expect(result.compensationCharge).to.equal(false) expect(result.customerReference).to.equal(invoiceAccountNumber) - expect(result.licenceNumber).to.equal('01/123') + expect(result.licenceNumber).to.equal(licence.licenceRef) expect(result.lineDescription).to.equal('Water abstraction charge: Agriculture other than spray irrigation at East Rudham') expect(result.loss).to.equal('medium') - expect(result.region).to.equal('S') + expect(result.region).to.equal(region.chargeRegionId) expect(result.regionalChargingArea).to.equal('Southern') expect(result.section127Agreement).to.equal(false) expect(result.section130Agreement).to.equal(false) diff --git a/test/services/billing-accounts/change-address.service.test.js b/test/services/billing-accounts/change-address.service.test.js index 5306eb65f7..0f6d74314d 100644 --- a/test/services/billing-accounts/change-address.service.test.js +++ b/test/services/billing-accounts/change-address.service.test.js @@ -27,13 +27,20 @@ const ChangeAddressService = require('../../../app/services/billing-accounts/cha describe('Change address service', () => { const addressFromLookup = { - addressLine1: 'NATURAL ENGLAND', addressLine2: 'HORIZON HOUSE', town: 'BRISTOL', postcode: 'BS1 5AH', uprn: 340116 + addressLine1: 'NATURAL ENGLAND', + addressLine2: 'HORIZON HOUSE', + town: 'BRISTOL', + postcode: 'BS1 5AH', + uprn: AddressHelper.generateUprn() } const addressFromManual = { addressLine1: '62 High St', town: 'Harpenden', postcode: 'AL5 2SP' } const companyCompaniesHouse = { - type: 'organisation', name: 'SCP Foundation', companyNumber: '04296934', organisationType: 'limitedCompany' + type: 'organisation', + name: 'SCP Foundation', + companyNumber: CompanyHelper.generateCompanyNumber(), + organisationType: 'limitedCompany' } const contactDepartment = { type: 'department', department: 'Humanoid Risk Assessment' @@ -90,7 +97,8 @@ describe('Change address service', () => { let existingAddress beforeEach(async () => { - existingAddress = await AddressHelper.add() + const { uprn } = address + existingAddress = await AddressHelper.add({ uprn }) }) it('overwrites the existing address with the latest OS Places details', async () => { @@ -100,7 +108,7 @@ describe('Change address service', () => { expect(reFetchedExistingAddress.addressId).to.equal(existingAddress.addressId) expect(reFetchedExistingAddress.createdAt).to.equal(existingAddress.createdAt) - expect(reFetchedExistingAddress.address1).to.equal('NATURAL ENGLAND') + expect(reFetchedExistingAddress.address1).to.equal(address.addressLine1) expect(reFetchedExistingAddress.updatedAt).not.to.equal(existingAddress.updatedAt) }) @@ -118,8 +126,8 @@ describe('Change address service', () => { const result = await AddressModel.query() expect(result.length).to.equal(1) - expect(result[0].address1).to.equal('NATURAL ENGLAND') - expect(result[0].uprn).to.equal(340116) + expect(result[0].address1).to.equal(address.addressLine1) + expect(result[0].uprn).to.equal(address.uprn) }) it('links the invoice account address record to the new address', async () => { @@ -193,7 +201,8 @@ describe('Change address service', () => { let existingCompany beforeEach(async () => { - existingCompany = await CompanyHelper.add() + const { companyNumber } = agentCompany + existingCompany = await CompanyHelper.add({ companyNumber }) }) it('overwrites the existing company with the latest Companies House details', async () => { @@ -203,7 +212,7 @@ describe('Change address service', () => { expect(reFetchedExistingCompany.companyId).to.equal(existingCompany.companyId) expect(reFetchedExistingCompany.createdAt).to.equal(existingCompany.createdAt) - expect(reFetchedExistingCompany.name).to.equal('SCP Foundation') + expect(reFetchedExistingCompany.name).to.equal(agentCompany.name) expect(reFetchedExistingCompany.updatedAt).not.to.equal(existingCompany.updatedAt) }) @@ -221,8 +230,8 @@ describe('Change address service', () => { const result = await CompanyModel.query() expect(result.length).to.equal(1) - expect(result[0].name).to.equal('SCP Foundation') - expect(result[0].companyNumber).to.equal('04296934') + expect(result[0].name).to.equal(agentCompany.name) + expect(result[0].companyNumber).to.equal(agentCompany.companyNumber) }) it('links the invoice account address record to the new company', async () => { diff --git a/test/services/billing/fetch-region.service.test.js b/test/services/billing/fetch-region.service.test.js index b53bf3536b..0f960587f2 100644 --- a/test/services/billing/fetch-region.service.test.js +++ b/test/services/billing/fetch-region.service.test.js @@ -24,7 +24,7 @@ describe('Fetch Region service', () => { describe('when there is a region with a matching NALD region id', () => { beforeEach(async () => { - testRegion = await RegionHelper.add() + testRegion = await RegionHelper.add({ naldRegionId }) }) it('returns results', async () => { @@ -36,7 +36,7 @@ describe('Fetch Region service', () => { describe('when there is no region with a matching NALD region id', () => { beforeEach(async () => { - RegionHelper.add({ naldRegionId: 99 }) + testRegion = await RegionHelper.add({ naldRegionId: 99 }) }) it('returns no results', async () => { diff --git a/test/services/billing/supplementary/fetch-charge-versions.service.test.js b/test/services/billing/supplementary/fetch-charge-versions.service.test.js index 68a7247858..9222f0dcf4 100644 --- a/test/services/billing/supplementary/fetch-charge-versions.service.test.js +++ b/test/services/billing/supplementary/fetch-charge-versions.service.test.js @@ -52,39 +52,41 @@ describe('Fetch Charge Versions service', () => { startDate: new Date('2023-04-01'), endDate: new Date('2024-03-31') } - licence = await LicenceHelper.add({ regionId, isWaterUndertaker: true, includeInSrocSupplementaryBilling: true, includeInSupplementaryBilling: 'yes' }) - const { licenceId } = licence changeReason = await ChangeReasonHelper.add({ triggersMinimumCharge: true }) + const { licenceId, licenceRef } = licence + const { changeReasonId } = changeReason + const invoiceAccountId = '77483323-daec-443e-912f-b87e1e9d0721' + // This creates a 'current' SROC charge version which covers only FYE 2024 const sroc2024ChargeVersion = await ChargeVersionHelper.add( - { startDate: new Date('2023-11-01'), changeReasonId: changeReason.changeReasonId, licenceId } + { startDate: new Date('2023-11-01'), changeReasonId, invoiceAccountId, licenceId, licenceRef } ) // This creates a 'current' SROC charge version which covers both FYE 2023 and 2024 const sroc2023And24ChargeVersion = await ChargeVersionHelper.add( - { endDate: new Date('2023-10-31'), changeReasonId: changeReason.changeReasonId, licenceId } + { endDate: new Date('2023-10-31'), changeReasonId, invoiceAccountId, licenceId, licenceRef } ) // This creates a 'current' SROC charge version which covers only FYE 2023 const sroc2023ChargeVersion = await ChargeVersionHelper.add( - { endDate: new Date('2022-10-31'), changeReasonId: changeReason.changeReasonId, licenceId } + { endDate: new Date('2022-10-31'), changeReasonId, invoiceAccountId, licenceId, licenceRef } ) // This creates a 'superseded' SROC charge version const srocSupersededChargeVersion = await ChargeVersionHelper.add( - { changeReasonId: changeReason.changeReasonId, status: 'superseded', licenceId } + { changeReasonId, status: 'superseded', invoiceAccountId, licenceId, licenceRef } ) // This creates an ALCS (presroc) charge version const alcsChargeVersion = await ChargeVersionHelper.add( - { scheme: 'alcs', licenceId } + { scheme: 'alcs', invoiceAccountId, licenceId, licenceRef } ) testRecords = [ @@ -136,20 +138,22 @@ describe('Fetch Charge Versions service', () => { const result = await FetchChargeVersionsService.go(regionId, billingPeriod) expect(result.chargeVersions).to.have.length(4) - expect(result.chargeVersions[0].chargeVersionId).to.equal(testRecords[0].chargeVersionId) - expect(result.chargeVersions[1].chargeVersionId).to.equal(testRecords[1].chargeVersionId) - expect(result.chargeVersions[2].chargeVersionId).to.equal(testRecords[2].chargeVersionId) - expect(result.chargeVersions[3].chargeVersionId).to.equal(testRecords[3].chargeVersionId) + + const chargeVersionIds = result.chargeVersions.map((chargeVersion) => { + return chargeVersion.chargeVersionId + }) + + expect(chargeVersionIds).to.include(testRecords[0].chargeVersionId) + expect(chargeVersionIds).to.include(testRecords[1].chargeVersionId) + expect(chargeVersionIds).to.include(testRecords[2].chargeVersionId) + expect(chargeVersionIds).to.include(testRecords[3].chargeVersionId) }) - it('returns the licenceIds from SROC charge versions that are applicable', async () => { + it('returns a unique list of licenceIds from SROC charge versions that are applicable', async () => { const result = await FetchChargeVersionsService.go(regionId, billingPeriod) - expect(result.licenceIdsForPeriod).to.have.length(4) + expect(result.licenceIdsForPeriod).to.have.length(1) expect(result.licenceIdsForPeriod[0]).to.equal(licence.licenceId) - expect(result.licenceIdsForPeriod[1]).to.equal(licence.licenceId) - expect(result.licenceIdsForPeriod[2]).to.equal(licence.licenceId) - expect(result.licenceIdsForPeriod[3]).to.equal(licence.licenceId) }) }) @@ -157,16 +161,21 @@ describe('Fetch Charge Versions service', () => { const result = await FetchChargeVersionsService.go(regionId, billingPeriod) expect(result.chargeVersions).to.have.length(4) - expect(result.chargeVersions[0].chargeVersionId).to.equal(testRecords[0].chargeVersionId) - expect(result.chargeVersions[1].chargeVersionId).to.equal(testRecords[1].chargeVersionId) - expect(result.chargeVersions[2].chargeVersionId).to.equal(testRecords[2].chargeVersionId) - expect(result.chargeVersions[3].chargeVersionId).to.equal(testRecords[3].chargeVersionId) + + const chargeVersionIds = result.chargeVersions.map((chargeVersion) => { + return chargeVersion.chargeVersionId + }) + + expect(chargeVersionIds).to.include(testRecords[0].chargeVersionId) + expect(chargeVersionIds).to.include(testRecords[1].chargeVersionId) + expect(chargeVersionIds).to.include(testRecords[2].chargeVersionId) + expect(chargeVersionIds).to.include(testRecords[3].chargeVersionId) }) it('includes the related licence and region', async () => { const result = await FetchChargeVersionsService.go(regionId, billingPeriod) - expect(result.chargeVersions[0].licence.licenceRef).to.equal(licenceDefaults.licenceRef) + expect(result.chargeVersions[0].licence.licenceRef).to.equal(licence.licenceRef) expect(result.chargeVersions[0].licence.isWaterUndertaker).to.equal(true) expect(result.chargeVersions[0].licence.historicalAreaCode).to.equal(licenceDefaults.regions.historicalAreaCode) expect(result.chargeVersions[0].licence.regionalChargeArea).to.equal(licenceDefaults.regions.regionalChargeArea) diff --git a/test/services/billing/supplementary/fetch-previous-transactions.service.test.js b/test/services/billing/supplementary/fetch-previous-transactions.service.test.js index 78b9633db9..2343b24eaf 100644 --- a/test/services/billing/supplementary/fetch-previous-transactions.service.test.js +++ b/test/services/billing/supplementary/fetch-previous-transactions.service.test.js @@ -8,19 +8,26 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseHelper = require('../../../support/helpers/database.helper.js') -const BillRunHelper = require('../../../support/helpers/water/bill-run.helper.js') const BillHelper = require('../../../support/helpers/water/bill.helper.js') const BillLicenceHelper = require('../../../support/helpers/water/bill-licence.helper.js') +const BillRunHelper = require('../../../support/helpers/water/bill-run.helper.js') +const DatabaseHelper = require('../../../support/helpers/database.helper.js') +const InvoiceAccountHelper = require('../../../support/helpers/crm-v2/invoice-account.helper.js') +const LicenceHelper = require('../../../support/helpers/water/licence.helper.js') const TransactionHelper = require('../../../support/helpers/water/transaction.helper.js') // Thing under test const FetchPreviousTransactionsService = require('../../../../app/services/billing/supplementary/fetch-previous-transactions.service.js') describe('Fetch Previous Transactions service', () => { + const chargeCategoryCode = '4.3.1' + const financialYearEnding = 2023 const invoiceAccountId = '4fe996c9-7641-4edc-9f42-0700dcde37b5' + const invoiceAccountNumber = InvoiceAccountHelper.generateInvoiceAccountNumber() const licenceId = '4492f1e2-f58c-4d4f-88a1-d4f9eb26fcba' - const financialYearEnding = 2023 + const licenceRef = LicenceHelper.generateLicenceRef() + + const billRunSetupValues = { invoiceAccountId, invoiceAccountNumber, licenceId, licenceRef } beforeEach(async () => { await DatabaseHelper.clean() @@ -41,8 +48,8 @@ describe('Fetch Previous Transactions service', () => { describe('when there is a bill run', () => { describe('for the same licence and invoice account', () => { beforeEach(async () => { - const billingInvoiceLicenceId = await _createBillRunAndBillAndBillLicence(invoiceAccountId, licenceId) - await TransactionHelper.add({ billingInvoiceLicenceId }) + const billingInvoiceLicenceId = await _createBillRunAndBillAndBillLicence(billRunSetupValues) + await TransactionHelper.add({ billingInvoiceLicenceId, chargeCategoryCode }) }) it('returns results', async () => { @@ -60,7 +67,7 @@ describe('Fetch Previous Transactions service', () => { let followUpBillingInvoiceLicenceId beforeEach(async () => { - followUpBillingInvoiceLicenceId = await _createBillRunAndBillAndBillLicence(invoiceAccountId, licenceId) + followUpBillingInvoiceLicenceId = await _createBillRunAndBillAndBillLicence(billRunSetupValues) }) describe('which only contains a credit', () => { @@ -68,6 +75,7 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, + chargeCategoryCode, isCredit: true }) }) @@ -89,6 +97,7 @@ describe('Fetch Previous Transactions service', () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, billableDays: 30, + chargeCategoryCode, isCredit: true }) }) @@ -109,6 +118,7 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, + chargeCategoryCode, chargeType: 'compensation', isCredit: true }) @@ -151,8 +161,9 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, - section126Factor: 0.5, - isCredit: true + chargeCategoryCode, + isCredit: true, + section126Factor: 0.5 }) }) @@ -172,8 +183,9 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, - section127Agreement: true, - isCredit: true + chargeCategoryCode, + isCredit: true, + section127Agreement: true }) }) @@ -193,8 +205,9 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, - section130Agreement: true, - isCredit: true + chargeCategoryCode, + isCredit: true, + section130Agreement: true }) }) @@ -215,6 +228,7 @@ describe('Fetch Previous Transactions service', () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, aggregateFactor: 0.5, + chargeCategoryCode, isCredit: true }) }) @@ -236,6 +250,7 @@ describe('Fetch Previous Transactions service', () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, adjustmentFactor: 0.5, + chargeCategoryCode, isCredit: true }) }) @@ -256,8 +271,9 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, - isWinterOnly: true, - isCredit: true + chargeCategoryCode, + isCredit: true, + isWinterOnly: true }) }) @@ -277,8 +293,9 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, - isSupportedSource: true, - isCredit: true + chargeCategoryCode, + isCredit: true, + isSupportedSource: true }) }) @@ -298,8 +315,9 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, - supportedSourceName: 'source name', - isCredit: true + chargeCategoryCode, + isCredit: true, + supportedSourceName: 'source name' }) }) @@ -319,8 +337,9 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, - isWaterCompanyCharge: true, - isCredit: true + chargeCategoryCode, + isCredit: true, + isWaterCompanyCharge: true }) }) @@ -350,6 +369,7 @@ describe('Fetch Previous Transactions service', () => { beforeEach(async () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, + chargeCategoryCode, isCredit: true }) }) @@ -372,6 +392,7 @@ describe('Fetch Previous Transactions service', () => { await TransactionHelper.add({ billingInvoiceLicenceId: followUpBillingInvoiceLicenceId, billableDays: 30, + chargeCategoryCode, isCredit: true }) }) @@ -394,8 +415,12 @@ describe('Fetch Previous Transactions service', () => { describe('but for a different licence', () => { beforeEach(async () => { - const billingInvoiceLicenceId = await _createBillRunAndBillAndBillLicence(invoiceAccountId, '66498337-e6a6-4a2a-9fb7-e39f43410f80') - await TransactionHelper.add({ billingInvoiceLicenceId }) + const billingInvoiceLicenceId = await _createBillRunAndBillAndBillLicence({ + ...billRunSetupValues, + licenceId: '66498337-e6a6-4a2a-9fb7-e39f43410f80' + }) + + await TransactionHelper.add({ billingInvoiceLicenceId, chargeCategoryCode }) }) it('returns no results', async () => { @@ -411,11 +436,12 @@ describe('Fetch Previous Transactions service', () => { describe('but for a different invoice account', () => { beforeEach(async () => { - const billingInvoiceLicenceId = await _createBillRunAndBillAndBillLicence( - 'b0b75e7a-e80a-4c28-9ac9-33b3a850722b', - licenceId - ) - await TransactionHelper.add({ billingInvoiceLicenceId }) + const billingInvoiceLicenceId = await _createBillRunAndBillAndBillLicence({ + ...billRunSetupValues, + invoiceAccountId: 'b0b75e7a-e80a-4c28-9ac9-33b3a850722b' + }) + + await TransactionHelper.add({ billingInvoiceLicenceId, chargeCategoryCode }) }) it('returns no results', async () => { @@ -431,10 +457,11 @@ describe('Fetch Previous Transactions service', () => { }) }) -async function _createBillRunAndBillAndBillLicence (invoiceAccountId, licenceId) { +async function _createBillRunAndBillAndBillLicence (billRunSetupValues) { + const { invoiceAccountId, invoiceAccountNumber, licenceId, licenceRef } = billRunSetupValues const { billingBatchId } = await BillRunHelper.add({ status: 'sent' }) - const { billingInvoiceId } = await BillHelper.add({ invoiceAccountId, billingBatchId }) - const { billingInvoiceLicenceId } = await BillLicenceHelper.add({ billingInvoiceId, licenceId }) + const { billingInvoiceId } = await BillHelper.add({ billingBatchId, invoiceAccountId, invoiceAccountNumber }) + const { billingInvoiceLicenceId } = await BillLicenceHelper.add({ billingInvoiceId, licenceId, licenceRef }) return billingInvoiceLicenceId } diff --git a/test/services/billing/supplementary/generate-transactions.service.test.js b/test/services/billing/supplementary/generate-transactions.service.test.js index 5c85a10b21..a39664b351 100644 --- a/test/services/billing/supplementary/generate-transactions.service.test.js +++ b/test/services/billing/supplementary/generate-transactions.service.test.js @@ -21,6 +21,8 @@ const CalculateAuthorisedAndBillableDaysService = require('../../../../app/servi const GenerateTransactionsService = require('../../../../app/services/billing/supplementary/generate-transactions.service.js') describe('Generate Transactions service', () => { + const reference = '4.4.5' + let chargePeriod let chargeElement let chargeReference @@ -33,7 +35,7 @@ describe('Generate Transactions service', () => { } beforeEach(async () => { - const chargeCategory = await ChargeCategoryHelper.add() + const chargeCategory = await ChargeCategoryHelper.add({ reference }) const { billingChargeCategoryId } = chargeCategory const baseChargeReference = await ChargeReferenceHelper.add({ billingChargeCategoryId }) diff --git a/test/services/data/export/write-table-to-file.service.test.js b/test/services/data/export/write-table-to-file.service.test.js index 227cb79c97..ccd07815a9 100644 --- a/test/services/data/export/write-table-to-file.service.test.js +++ b/test/services/data/export/write-table-to-file.service.test.js @@ -41,7 +41,8 @@ const headers = [ ] const csvValues = '"20146cdc-9b40-4769-aa78-b51c17080d56",' + -'"4.4.5",12000,' + +'"4.4.5",' + +'12000,' + '"Low loss non-tidal abstraction of restricted water up to and including 5,000 megalitres a year, where a Tier 1 model applies.",' + '"Low loss, non-tidal, restricted water, up to and including 5,000 ML/yr, Tier 1 model",' + 'false,' + @@ -66,14 +67,14 @@ const csvHeaders = '"billingChargeCategoryId",' + '"minVolume",' + '"maxVolume"\n' -describe('Write stream to file service', () => { +describe('Write table to file service', () => { let filePath describe('when successful', () => { beforeEach(async () => { await DatabaseHelper.clean() - await ChargeCategoryHelper.add({ createdAt: date, billingChargeCategoryId }) + await ChargeCategoryHelper.add({ billingChargeCategoryId, createdAt: date, reference: '4.4.5' }) const fileName = 'billing_charge_categories.csv' const __dirname = '/tmp/water' diff --git a/test/services/data/mock/generate-bill-run.service.test.js b/test/services/data/mock/generate-bill-run.service.test.js index ceab7fdf19..bef68e4aac 100644 --- a/test/services/data/mock/generate-bill-run.service.test.js +++ b/test/services/data/mock/generate-bill-run.service.test.js @@ -59,7 +59,11 @@ describe('Generate Bill Run service', () => { }) await ChargeElementHelper.add({ chargeElementId: chargeReference.chargeElementId, purposeUseId: purpose.purposeUseId }) const billRun = await BillRunHelper.add({ billRunNumber: 10029, regionId: region.regionId }) - const bill = await BillHelper.add({ billingBatchId: billRun.billingBatchId, invoiceNumber: 'TAI0000013T' }) + const bill = await BillHelper.add({ + billingBatchId: billRun.billingBatchId, + invoiceAccountNumber: 'T11345678A', + invoiceNumber: 'TAI0000013T' + }) const billLicence = await BillLicenceHelper.add({ billingInvoiceId: bill.billingInvoiceId, licenceId: licence.licenceId }) await TransactionHelper.add({ billingInvoiceLicenceId: billLicence.billingInvoiceLicenceId, diff --git a/test/support/helpers/crm-v2/address.helper.js b/test/support/helpers/crm-v2/address.helper.js index dddf4ca4fe..5e9c932dcb 100644 --- a/test/support/helpers/crm-v2/address.helper.js +++ b/test/support/helpers/crm-v2/address.helper.js @@ -5,6 +5,7 @@ */ const AddressModel = require('../../../../app/models/crm-v2/address.model.js') +const { randomInteger } = require('../general.helper.js') /** * Add a new address @@ -18,7 +19,7 @@ const AddressModel = require('../../../../app/models/crm-v2/address.model.js') * - `postcode` - BS1 5AH * - `country` - United Kingdom * - `dataSource` - wrls - * - `uprn` - 340116 + * - `uprn` - [randomly generated - 340116] * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -33,7 +34,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new address + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -49,7 +50,7 @@ function defaults (data = {}) { postcode: 'BS1 5AH', country: 'United Kingdom', dataSource: 'wrls', - uprn: 340116 + uprn: generateUprn() } return { @@ -58,7 +59,12 @@ function defaults (data = {}) { } } +function generateUprn () { + return randomInteger(100, 999999) +} + module.exports = { add, - defaults + defaults, + generateUprn } diff --git a/test/support/helpers/crm-v2/company.helper.js b/test/support/helpers/crm-v2/company.helper.js index d9b46e2b0f..d875cbd30c 100644 --- a/test/support/helpers/crm-v2/company.helper.js +++ b/test/support/helpers/crm-v2/company.helper.js @@ -5,6 +5,7 @@ */ const CompanyModel = require('../../../../app/models/crm-v2/company.model.js') +const { randomInteger } = require('../general.helper.js') /** * Add a new company @@ -13,7 +14,7 @@ const CompanyModel = require('../../../../app/models/crm-v2/company.model.js') * * - `name` - Example Trading Ltd * - `type` - organisation - * - `companyNumber` - 04296934 + * - `companyNumber` - [randomly generated - 24296934] * - `organisationType` - limitedCompany * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database @@ -29,7 +30,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new company + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -40,7 +41,7 @@ function defaults (data = {}) { const defaults = { name: 'Example Trading Ltd', type: 'organisation', - companyNumber: '04296934', + companyNumber: generateCompanyNumber(), organisationType: 'limitedCompany' } @@ -50,7 +51,12 @@ function defaults (data = {}) { } } +function generateCompanyNumber () { + return randomInteger(1000000, 9999999).toString() +} + module.exports = { add, - defaults + defaults, + generateCompanyNumber } diff --git a/test/support/helpers/crm-v2/contact.helper.js b/test/support/helpers/crm-v2/contact.helper.js index 2fd018b3b5..fb39f978b3 100644 --- a/test/support/helpers/crm-v2/contact.helper.js +++ b/test/support/helpers/crm-v2/contact.helper.js @@ -30,7 +30,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new contact + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. diff --git a/test/support/helpers/crm-v2/invoice-account-address.helper.js b/test/support/helpers/crm-v2/invoice-account-address.helper.js index 9a9e43515b..76a9993588 100644 --- a/test/support/helpers/crm-v2/invoice-account-address.helper.js +++ b/test/support/helpers/crm-v2/invoice-account-address.helper.js @@ -4,6 +4,7 @@ * @module InvoiceAccountAddressHelper */ +const { generateUUID } = require('../../../../app/lib/general.lib.js') const InvoiceAccountAddressModel = require('../../../../app/models/crm-v2/invoice-account-address.model.js') /** @@ -11,8 +12,8 @@ const InvoiceAccountAddressModel = require('../../../../app/models/crm-v2/invoic * * If no `data` is provided, default values will be used. These are * - * - `invoiceAccountId` - b16efa32-9271-4333-aecf-b9358ba42892 - * - `addressId` - 9570acde-752e-456a-a895-7b46a3c923a3 + * - `invoiceAccountId` - [random UUID] + * - `addressId` - [random UUID] * - `startDate` - 2023-08-18 * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database @@ -37,8 +38,8 @@ function add (data = {}) { */ function defaults (data = {}) { const defaults = { - invoiceAccountId: 'b16efa32-9271-4333-aecf-b9358ba42892', - addressId: '9570acde-752e-456a-a895-7b46a3c923a3', + invoiceAccountId: generateUUID(), + addressId: generateUUID(), startDate: new Date('2023-08-18') } diff --git a/test/support/helpers/crm-v2/invoice-account.helper.js b/test/support/helpers/crm-v2/invoice-account.helper.js index 298035d4b0..e70d5ff935 100644 --- a/test/support/helpers/crm-v2/invoice-account.helper.js +++ b/test/support/helpers/crm-v2/invoice-account.helper.js @@ -4,6 +4,7 @@ * @module InvoiceAccountHelper */ +const { randomInteger } = require('../general.helper.js') const InvoiceAccountModel = require('../../../../app/models/crm-v2/invoice-account.model.js') /** @@ -11,7 +12,7 @@ const InvoiceAccountModel = require('../../../../app/models/crm-v2/invoice-accou * * If no `data` is provided, default values will be used. These are * - * - `invoiceAccountNumber` - T12345678A + * - `invoiceAccountNumber` - [randomly generated - T12345678A] * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -26,7 +27,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new region + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -35,7 +36,7 @@ function add (data = {}) { */ function defaults (data = {}) { const defaults = { - invoiceAccountNumber: 'T12345678A' + invoiceAccountNumber: generateInvoiceAccountNumber() } return { @@ -44,7 +45,14 @@ function defaults (data = {}) { } } +function generateInvoiceAccountNumber () { + const numbering = randomInteger(10000000, 99999999) + + return `T${numbering}A` +} + module.exports = { add, - defaults + defaults, + generateInvoiceAccountNumber } diff --git a/test/support/helpers/general.helper.js b/test/support/helpers/general.helper.js new file mode 100644 index 0000000000..b818f450c5 --- /dev/null +++ b/test/support/helpers/general.helper.js @@ -0,0 +1,24 @@ +'use strict' + +/** + * General helper functions available to all helpers + * @module GeneralHelper + */ + +/** + * Generate a random integer within a range (inclusive) + * + * @param {Number} min lowest number (integer) in the range (inclusive) + * @param {Number} max largest number (integer) in the range (inclusive) + * + * Credit https://stackoverflow.com/a/7228322 + * + * @returns a number between min and max (inclusive) + */ +function randomInteger (min, max) { + return Math.floor(Math.random() * (max - min + 1) + min) +} + +module.exports = { + randomInteger +} diff --git a/test/support/helpers/idm/group-role.helper.js b/test/support/helpers/idm/group-role.helper.js index 9ecf159788..7c6be82cbf 100644 --- a/test/support/helpers/idm/group-role.helper.js +++ b/test/support/helpers/idm/group-role.helper.js @@ -4,6 +4,7 @@ * @module GroupRoleHelper */ +const { generateUUID } = require('../../../../app/lib/general.lib.js') const GroupRoleModel = require('../../../../app/models/idm/group-role.model.js') /** @@ -11,8 +12,8 @@ const GroupRoleModel = require('../../../../app/models/idm/group-role.model.js') * * If no `data` is provided, default values will be used. These are * - * - `groupId` - e814fc07-e6e3-4a50-8699-9ede17690674 - * - `roleId` - 66b54ff8-edec-417a-8c8b-48d98aad3843 + * - `groupId` - [random UUID] + * - `roleId` - [random UUID] * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -27,7 +28,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new record + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -36,8 +37,8 @@ function add (data = {}) { */ function defaults (data = {}) { const defaults = { - groupId: 'e814fc07-e6e3-4a50-8699-9ede17690674', - roleId: '66b54ff8-edec-417a-8c8b-48d98aad3843' + groupId: generateUUID(), + roleId: generateUUID() } return { diff --git a/test/support/helpers/idm/group.helper.js b/test/support/helpers/idm/group.helper.js index 5e50bb419d..d72e26a027 100644 --- a/test/support/helpers/idm/group.helper.js +++ b/test/support/helpers/idm/group.helper.js @@ -29,7 +29,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new record + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. diff --git a/test/support/helpers/idm/role.helper.js b/test/support/helpers/idm/role.helper.js index aa05d52679..eff283f1d6 100644 --- a/test/support/helpers/idm/role.helper.js +++ b/test/support/helpers/idm/role.helper.js @@ -28,7 +28,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new record + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. diff --git a/test/support/helpers/idm/user-group.helper.js b/test/support/helpers/idm/user-group.helper.js index 5e5eed7ae0..a2fc47f447 100644 --- a/test/support/helpers/idm/user-group.helper.js +++ b/test/support/helpers/idm/user-group.helper.js @@ -13,7 +13,7 @@ const UserGroupModel = require('../../../../app/models/idm/user-group.model.js') * If no `data` is provided, default values will be used. These are * * - `userId` - 100001 - * - `groupId` - e814fc07-e6e3-4a50-8699-9ede17690674 + * - `groupId` - [random UUID] * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -28,7 +28,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new record + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -40,7 +40,7 @@ function defaults (data = {}) { // We create a random uuid as the id is NOT generated by the db, unlike most other tables userGroupId: generateUUID(), userId: 100001, - groupId: 'e814fc07-e6e3-4a50-8699-9ede17690674' + groupId: generateUUID() } return { diff --git a/test/support/helpers/idm/user-role.helper.js b/test/support/helpers/idm/user-role.helper.js index 3c5077232f..ba718b1e70 100644 --- a/test/support/helpers/idm/user-role.helper.js +++ b/test/support/helpers/idm/user-role.helper.js @@ -13,7 +13,7 @@ const UserRoleModel = require('../../../../app/models/idm/user-role.model.js') * If no `data` is provided, default values will be used. These are * * - `userId` - 100001 - * - `roleId` - e814fc07-e6e3-4a50-8699-9ede17690674 + * - `roleId` - [random UUID] * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -28,7 +28,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new record + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -40,7 +40,7 @@ function defaults (data = {}) { // We create a random uuid as the id is NOT generated by the db, unlike most other tables userRoleId: generateUUID(), userId: 100001, - roleId: '66b54ff8-edec-417a-8c8b-48d98aad3843' + roleId: generateUUID() } return { diff --git a/test/support/helpers/idm/user.helper.js b/test/support/helpers/idm/user.helper.js index 033d46626e..0343a242d8 100644 --- a/test/support/helpers/idm/user.helper.js +++ b/test/support/helpers/idm/user.helper.js @@ -34,7 +34,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new record + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. diff --git a/test/support/helpers/returns/line.helper.js b/test/support/helpers/returns/line.helper.js index f82f1f4043..cc0a9591e4 100644 --- a/test/support/helpers/returns/line.helper.js +++ b/test/support/helpers/returns/line.helper.js @@ -12,7 +12,7 @@ const LineModel = require('../../../../app/models/returns/line.model.js') * * If no `data` is provided, default values will be used. These are * - * - `versionId` - 8ca74383-08fd-4ca8-93f0-21c21247cb22 + * - `versionId` - [random UUID] * - `substance` - water * - `quantity` - 4380 * - `unit` - m³ @@ -38,7 +38,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new line + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -48,7 +48,7 @@ function add (data = {}) { function defaults (data = {}) { const defaults = { lineId: generateUUID(), - versionId: '8ca74383-08fd-4ca8-93f0-21c21247cb22', + versionId: generateUUID(), substance: 'water', quantity: 4380, unit: 'm³', diff --git a/test/support/helpers/returns/return.helper.js b/test/support/helpers/returns/return.helper.js index 84978d8436..055bbd0652 100644 --- a/test/support/helpers/returns/return.helper.js +++ b/test/support/helpers/returns/return.helper.js @@ -4,6 +4,8 @@ * @module ReturnHelper */ +const { randomInteger } = require('../general.helper.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') const ReturnModel = require('../../../../app/models/returns/return.model.js') /** @@ -11,9 +13,10 @@ const ReturnModel = require('../../../../app/models/returns/return.model.js') * * If no `data` is provided, default values will be used. These are * - * - `returnId` - v1:1:9/99/99/99/9999:10021668:2022-04-01:2023-03-31 + * - `returnId` - v1:1:[the generated licenceRef]:[the generated returnRequirement]:2022-04-01:2023-03-31 * - `regime` - water * - `licenceType` - abstraction + * - `licenceRef` - [randomly generated - 1/23/45/76/3672] * - `startDate` - 2022-04-01 * - `endDate` - 2023-03-31 * - `returnsFrequency` - month @@ -21,9 +24,9 @@ const ReturnModel = require('../../../../app/models/returns/return.model.js') * - `source` - NALD * - `metadata` - {} * - `receivedDate` - 2023-04-12 - * - `returnRequirement` - 99999 + * - `returnRequirement` - [randomly generated - 10000321] * - `dueDate` - 2023-04-28 - * - `returnCycleId` - 2eb314fe-da45-4ae9-b418-7d89a8c49c51 + * - `returnCycleId` - [random UUID] * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -38,7 +41,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new return + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -46,11 +49,14 @@ function add (data = {}) { * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database */ function defaults (data = {}) { + const licenceRef = data.licenceRef ? data.licenceRef : _generateLicenceRef() + const returnRequirement = data.returnRequirement ? data.returnRequirement : randomInteger(10000000, 19999999) + const defaults = { - returnId: 'v1:1:9/99/99/99/9999:10021668:2022-04-01:2023-03-31', + returnId: generateReturnId('2022-04-01', '2023-03-31', 1, licenceRef, returnRequirement), regime: 'water', licenceType: 'abstraction', - licenceRef: '9/99/99/99/9999', + licenceRef, startDate: new Date('2022-04-01'), endDate: new Date('2023-03-31'), returnsFrequency: 'month', @@ -58,9 +64,9 @@ function defaults (data = {}) { source: 'NALD', metadata: {}, receivedDate: new Date('2023-04-12'), - returnRequirement: '99999', + returnRequirement, dueDate: new Date('2023-04-28'), - returnCycleId: '2eb314fe-da45-4ae9-b418-7d89a8c49c51' + returnCycleId: generateUUID() } return { @@ -69,7 +75,36 @@ function defaults (data = {}) { } } +function generateReturnId ( + startDate = '2022-04-01', + endDate = '2023-03-31', + version = 1, + licenceRef, + returnRequirement +) { + if (!licenceRef) { + licenceRef = _generateLicenceRef() + } + + if (!returnRequirement) { + returnRequirement = randomInteger(10000000, 19999999) + } + + return `v${version}:1:${licenceRef}:${returnRequirement}:${startDate}:${endDate}` +} + +function _generateLicenceRef () { + const part1 = randomInteger(1, 9) + const part2 = randomInteger(10, 99) + const part3 = randomInteger(10, 99) + const part4 = randomInteger(10, 99) + const part5 = randomInteger(1000, 9999) + + return `${part1}/${part2}/${part3}/${part4}/${part5}` +} + module.exports = { add, - defaults + defaults, + generateReturnId } diff --git a/test/support/helpers/returns/version.helper.js b/test/support/helpers/returns/version.helper.js index 016d3da2ac..f6722299b8 100644 --- a/test/support/helpers/returns/version.helper.js +++ b/test/support/helpers/returns/version.helper.js @@ -5,6 +5,7 @@ */ const { generateUUID } = require('../../../../app/lib/general.lib.js') +const { generateReturnId } = require('./return.helper.js') const VersionModel = require('../../../../app/models/returns/version.model.js') /** @@ -12,7 +13,7 @@ const VersionModel = require('../../../../app/models/returns/version.model.js') * * If no `data` is provided, default values will be used. These are * - * `returnId` - v1:2:03/28/78/0033:10025289:2021-11-01:2022-10-31 + * `returnId` - [randomly generated - v1:1:03/28/78/0033:10025289:2022-04-01:2023-03-31] * `userId` - admin-internal@wrls.gov.uk * `userType` - internal * `versionNumber` - 1 @@ -35,7 +36,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new line + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -45,7 +46,7 @@ function add (data = {}) { function defaults (data = {}) { const defaults = { versionId: generateUUID(), - returnId: 'v1:2:03/28/78/0033:10025289:2021-11-01:2022-10-31', + returnId: generateReturnId(), userId: 'admin-internal@wrls.gov.uk', userType: 'internal', versionNumber: 1, diff --git a/test/support/helpers/water/bill-licence.helper.js b/test/support/helpers/water/bill-licence.helper.js index aee22218f5..ef61c1abcd 100644 --- a/test/support/helpers/water/bill-licence.helper.js +++ b/test/support/helpers/water/bill-licence.helper.js @@ -5,15 +5,17 @@ */ const BillLicenceModel = require('../../../../app/models/water/bill-licence.model.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') +const LicenceHelper = require('./licence.helper.js') /** * Add a new bill licence * * If no `data` is provided, default values will be used. These are * - * - `billingInvoiceId` - 45f08fe4-5b8b-4cf7-aaf0-5a07534e1357 - * - `licenceRef` - 01/123 - * - `licenceId` - 2eb0623e-30c6-4bf4-9598-2d60a8366c7d + * - `billingInvoiceId` - [random UUID] + * - `licenceRef` - [randomly generated - 01/123] + * - `licenceId` - [random UUID] * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -37,9 +39,9 @@ async function add (data = {}) { */ function defaults (data = {}) { const defaults = { - billingInvoiceId: '45f08fe4-5b8b-4cf7-aaf0-5a07534e1357', - licenceRef: '01/123', - licenceId: '2eb0623e-30c6-4bf4-9598-2d60a8366c7d' + billingInvoiceId: generateUUID(), + licenceRef: LicenceHelper.generateLicenceRef(), + licenceId: generateUUID() } return { diff --git a/test/support/helpers/water/bill-run.helper.js b/test/support/helpers/water/bill-run.helper.js index 41ecca36ad..da7a8be314 100644 --- a/test/support/helpers/water/bill-run.helper.js +++ b/test/support/helpers/water/bill-run.helper.js @@ -5,13 +5,14 @@ */ const BillRunModel = require('../../../../app/models/water/bill-run.model.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') /** * Add a new bill run * * If no `data` is provided, default values will be used. These are * - * - `regionId` - bd114474-790f-4470-8ba4-7b0cc9c225d7 + * - `regionId` - [random UUID] * - `batchType` - supplementary * - `fromFinancialYearEnding` - 2023 * - `toFinancialYearEnding` - 2023 @@ -41,7 +42,7 @@ function add (data = {}) { */ function defaults (data = {}) { const defaults = { - regionId: 'bd114474-790f-4470-8ba4-7b0cc9c225d7', + regionId: generateUUID(), batchType: 'supplementary', fromFinancialYearEnding: 2023, toFinancialYearEnding: 2023, diff --git a/test/support/helpers/water/bill.helper.js b/test/support/helpers/water/bill.helper.js index 3ca71c4c78..fac8f0a0ae 100644 --- a/test/support/helpers/water/bill.helper.js +++ b/test/support/helpers/water/bill.helper.js @@ -5,16 +5,18 @@ */ const BillModel = require('../../../../app/models/water/bill.model.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') +const { generateInvoiceAccountNumber } = require('../crm-v2/invoice-account.helper.js') /** * Add a new bill * * If no `data` is provided, default values will be used. These are * - * - `invoiceAccountId` - 396ee68f-d665-4770-b0ad-d70a007f9bd5 + * - `invoiceAccountId` - [random UUID] * - `address` - {} - * - `invoiceAccountNumber` - T12345678A - * - `billingBatchId` - 1d9e3142-8893-4dff-9043-f4b3b34e230d + * - `invoiceAccountNumber` - [randomly generated - T12345678A] + * - `billingBatchId` - [random UUID] * - `financialYearEnding` - 2023 * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database @@ -39,10 +41,10 @@ async function add (data = {}) { */ function defaults (data = {}) { const defaults = { - invoiceAccountId: '396ee68f-d665-4770-b0ad-d70a007f9bd5', + invoiceAccountId: generateUUID(), address: {}, - invoiceAccountNumber: 'T12345678A', - billingBatchId: '1d9e3142-8893-4dff-9043-f4b3b34e230d', + invoiceAccountNumber: generateInvoiceAccountNumber(), + billingBatchId: generateUUID(), financialYearEnding: 2023 } diff --git a/test/support/helpers/water/charge-category.helper.js b/test/support/helpers/water/charge-category.helper.js index cb378b7ebd..0816101b0d 100644 --- a/test/support/helpers/water/charge-category.helper.js +++ b/test/support/helpers/water/charge-category.helper.js @@ -5,13 +5,14 @@ */ const ChargeCategoryModel = require('../../../../app/models/water/charge-category.model.js') +const { randomInteger } = require('../general.helper.js') /** * Add a new charge category * * If no `data` is provided, default values will be used. These are * - * - `reference` - 4.4.5 + * - `reference` - [randomly generated - 4.4.5] * - `subsistenceCharge` - 12000 * - `description` - Low loss non-tidal abstraction of restricted water up to and including 5,000 megalitres a year, * where a Tier 1 model applies. @@ -46,7 +47,7 @@ function add (data = {}) { */ function defaults (data = {}) { const defaults = { - reference: '4.4.5', + reference: generateChargeReference(), subsistenceCharge: 12000, description: 'Low loss non-tidal abstraction of restricted water up to and including 5,000 megalitres a year, where a Tier 1 model applies.', shortDescription: 'Low loss, non-tidal, restricted water, up to and including 5,000 ML/yr, Tier 1 model', @@ -71,7 +72,15 @@ function defaults (data = {}) { } } +function generateChargeReference () { + const secondPart = randomInteger(1, 6) + const thirdPart = randomInteger(1, 42) + + return `4.${secondPart}.${thirdPart}` +} + module.exports = { add, - defaults + defaults, + generateChargeReference } diff --git a/test/support/helpers/water/charge-element.helper.js b/test/support/helpers/water/charge-element.helper.js index fe26d90f4b..1efaba29d0 100644 --- a/test/support/helpers/water/charge-element.helper.js +++ b/test/support/helpers/water/charge-element.helper.js @@ -5,13 +5,14 @@ */ const ChargeElementModel = require('../../../../app/models/water/charge-element.model.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') /** * Add a new charge element * * If no `data` is provided, default values will be used. These are * - * - `chargeElementId` - 090f42a0-7718-453e-bc6a-d57ef8d65417 + * - `chargeElementId` - [random UUID] * - `abstractionPeriodStartDay` - 1 * - `abstractionPeriodStartMonth` - 4 * - `abstractionPeriodEndDay` - 31 @@ -23,9 +24,9 @@ const ChargeElementModel = require('../../../../app/models/water/charge-element. * - `timeLimitedStartDate` - 2022-04-01 * - `timeLimitedEndDate` - 2030-03-30 * - `description` - Trickle Irrigation - Direct - * - `purposePrimaryId` - 383ab43e-6d0b-4be0-b5d2-4226f333f1d7 - * - `purposeSecondaryId` - 0e92d79a-f17f-4364-955f-443360ebddb2 - * - `purposeUseId` - cc9f412c-22c6-483a-93b0-b955a3a644dc + * - `purposePrimaryId` - [random UUID] + * - `purposeSecondaryId` - [random UUID] + * - `purposeUseId` - [random UUID] * - `isSection127AgreementEnabled` - true * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database @@ -50,7 +51,7 @@ function add (data = {}) { */ function defaults (data = {}) { const defaults = { - chargeElementId: '090f42a0-7718-453e-bc6a-d57ef8d65417', + chargeElementId: generateUUID(), abstractionPeriodStartDay: 1, abstractionPeriodStartMonth: 4, abstractionPeriodEndDay: 31, @@ -62,9 +63,9 @@ function defaults (data = {}) { timeLimitedStartDate: new Date('2022-04-01'), timeLimitedEndDate: new Date('2030-03-30'), description: 'Trickle Irrigation - Direct', - purposePrimaryId: '383ab43e-6d0b-4be0-b5d2-4226f333f1d7', - purposeSecondaryId: '0e92d79a-f17f-4364-955f-443360ebddb2', - purposeUseId: 'cc9f412c-22c6-483a-93b0-b955a3a644dc', + purposePrimaryId: generateUUID(), + purposeSecondaryId: generateUUID(), + purposeUseId: generateUUID(), isSection127AgreementEnabled: true } diff --git a/test/support/helpers/water/charge-reference.helper.js b/test/support/helpers/water/charge-reference.helper.js index 983eadb8a7..5486872019 100644 --- a/test/support/helpers/water/charge-reference.helper.js +++ b/test/support/helpers/water/charge-reference.helper.js @@ -5,13 +5,14 @@ */ const ChargeReferenceModel = require('../../../../app/models/water/charge-reference.model.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') /** * Add a new charge reference * * If no `data` is provided, default values will be used. These are * - * - `chargeVersionId` - b033e8d1-3ad4-4782-930b-c1e10cb9110e + * - `chargeVersionId` - [random UUID] * - `source` - non-tidal * - `loss` - low * - `description` - Mineral washing @@ -20,7 +21,7 @@ const ChargeReferenceModel = require('../../../../app/models/water/charge-refere * - `isRestrictedSource` - true * - `waterModel` - no model * - `volume` - 6.819 - * - `billingChargeCategoryId` - cd9ca44d-2ddb-4d5d-ac62-79883176bdec + * - `billingChargeCategoryId` - [random UUID] * - `additionalCharges` - { isSupplyPublicWater: true } * - `adjustments` - { s126: null, s127: false, s130: false, charge: null, winter: false, aggregate: 0.562114443 } * - `eiucRegion` - Anglian @@ -51,7 +52,7 @@ function add (data = {}) { */ function defaults (data = {}) { const defaults = { - chargeVersionId: 'b033e8d1-3ad4-4782-930b-c1e10cb9110e', + chargeVersionId: generateUUID(), source: 'non-tidal', loss: 'low', description: 'Mineral washing', @@ -60,7 +61,7 @@ function defaults (data = {}) { isRestrictedSource: true, waterModel: 'no model', volume: 6.819, - billingChargeCategoryId: 'cd9ca44d-2ddb-4d5d-ac62-79883176bdec', + billingChargeCategoryId: generateUUID(), additionalCharges: { isSupplyPublicWater: true }, adjustments: { s126: null, s127: false, s130: false, charge: null, winter: false, aggregate: '0.562114443' }, eiucRegion: 'Anglian', diff --git a/test/support/helpers/water/charge-version.helper.js b/test/support/helpers/water/charge-version.helper.js index 9c4bc2600b..4997ee75e4 100644 --- a/test/support/helpers/water/charge-version.helper.js +++ b/test/support/helpers/water/charge-version.helper.js @@ -5,18 +5,20 @@ */ const ChargeVersionModel = require('../../../../app/models/water/charge-version.model.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') +const { generateLicenceRef } = require('./licence.helper.js') /** * Add a new charge version * * If no `data` is provided, default values will be used. These are * - * - `licenceRef` - 01/123 + * - `licenceRef` - [randomly generated - 01/123] * - `scheme` - sroc * - `startDate` - 2022-04-01 - * - `invoiceAccountId` - 01931031-4680-4950-87d6-50f8fe784f6d + * - `invoiceAccountId` - [random UUID] * - `status` - current - * - `licenceId` - 4c9d2d86-fc88-4fb6-b49d-8a30f52f7997 + * - `licenceId` - [random UUID] * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -40,12 +42,12 @@ async function add (data = {}) { */ function defaults (data = {}) { const defaults = { - licenceRef: '01/123', + licenceRef: generateLicenceRef(), scheme: 'sroc', startDate: new Date('2022-04-01'), - invoiceAccountId: '01931031-4680-4950-87d6-50f8fe784f6d', + invoiceAccountId: generateUUID(), status: 'current', - licenceId: '4c9d2d86-fc88-4fb6-b49d-8a30f52f7997' + licenceId: generateUUID() } return { diff --git a/test/support/helpers/water/event.helper.js b/test/support/helpers/water/event.helper.js index dc03e16f13..ff16c3f447 100644 --- a/test/support/helpers/water/event.helper.js +++ b/test/support/helpers/water/event.helper.js @@ -5,7 +5,7 @@ */ const EventModel = require('../../../../app/models/water/event.model.js') -const GeneralLib = require('../../../../app/lib/general.lib.js') +const { generateUUID, timestampForPostgres } = require('../../../../app/lib/general.lib.js') /** * Add a new event @@ -16,10 +16,10 @@ const GeneralLib = require('../../../../app/lib/general.lib.js') * - `subtype` - supplementary * - `issuer` - test.user@defra.gov.uk * - `metadata` - batch: { - id: '744c307f-904f-43c4-9458-24f062381d02', + id: [random UUID], type: 'supplementary', region: { - id: 'bd114474-790f-4470-8ba4-7b0cc9c225d7' + id: [random UUID] }, scheme: 'sroc' } @@ -41,7 +41,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new event + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -49,7 +49,7 @@ function add (data = {}) { * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database */ function defaults (data = {}) { - const timestamp = GeneralLib.timestampForPostgres() + const timestamp = timestampForPostgres() const defaults = { type: 'billing-batch', @@ -57,10 +57,10 @@ function defaults (data = {}) { issuer: 'test.user@defra.gov.uk', metadata: { batch: { - id: '744c307f-904f-43c4-9458-24f062381d02', + id: generateUUID(), type: 'supplementary', region: { - id: 'bd114474-790f-4470-8ba4-7b0cc9c225d7' + id: generateUUID() }, scheme: 'sroc' } diff --git a/test/support/helpers/water/licence.helper.js b/test/support/helpers/water/licence.helper.js index dd23945afb..d581a8f346 100644 --- a/test/support/helpers/water/licence.helper.js +++ b/test/support/helpers/water/licence.helper.js @@ -4,6 +4,8 @@ * @module LicenceHelper */ +const { randomInteger } = require('../general.helper.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') const LicenceModel = require('../../../../app/models/water/licence.model.js') /** @@ -11,8 +13,8 @@ const LicenceModel = require('../../../../app/models/water/licence.model.js') * * If no `data` is provided, default values will be used. These are * - * - `licenceRef` - 01/123 - * - `regionId` - bd114474-790f-4470-8ba4-7b0cc9c225d7 + * - `licenceRef` - [randomly generated - 01/123] + * - `regionId` - [random UUID] * - `regions` - { historicalAreaCode: 'SAAR', regionalChargeArea: 'Southern' } * - `startDate` - new Date('2022-01-01') * @@ -38,8 +40,8 @@ async function add (data = {}) { */ function defaults (data = {}) { const defaults = { - licenceRef: '01/123', - regionId: 'bd114474-790f-4470-8ba4-7b0cc9c225d7', + licenceRef: generateLicenceRef(), + regionId: generateUUID(), regions: { historicalAreaCode: 'SAAR', regionalChargeArea: 'Southern' }, startDate: new Date('2022-01-01') } @@ -50,7 +52,14 @@ function defaults (data = {}) { } } +function generateLicenceRef () { + const secondPart = randomInteger(100, 999) + + return `01/${secondPart}` +} + module.exports = { add, - defaults + defaults, + generateLicenceRef } diff --git a/test/support/helpers/water/purpose.helper.js b/test/support/helpers/water/purpose.helper.js index 4459c8db85..611a0d94d0 100644 --- a/test/support/helpers/water/purpose.helper.js +++ b/test/support/helpers/water/purpose.helper.js @@ -4,6 +4,7 @@ * @module PurposeHelper */ +const { randomInteger } = require('../general.helper.js') const PurposeModel = require('../../../../app/models/water/purpose.model.js') /** @@ -11,7 +12,7 @@ const PurposeModel = require('../../../../app/models/water/purpose.model.js') * * If no `data` is provided, default values will be used. These are * - * - `legacyId` - 420 + * - `legacyId` - [randomly generated - 420] * - `description` - Spray Irrigation - Storage * - `lossFactor` - high * - `isTwoPartTariff` - true @@ -38,7 +39,7 @@ function add (data = {}) { */ function defaults (data = {}) { const defaults = { - legacyId: '420', + legacyId: generateLegacyId(), description: 'Spray Irrigation - Storage', lossFactor: 'high', isTwoPartTariff: true @@ -50,6 +51,12 @@ function defaults (data = {}) { } } +function generateLegacyId () { + const numbering = randomInteger(10, 99) + + return `${numbering}0` +} + module.exports = { add, defaults diff --git a/test/support/helpers/water/region.helper.js b/test/support/helpers/water/region.helper.js index b9248f6bb3..f6ec0f465e 100644 --- a/test/support/helpers/water/region.helper.js +++ b/test/support/helpers/water/region.helper.js @@ -4,6 +4,7 @@ * @module RegionHelper */ +const { randomInteger } = require('../general.helper.js') const RegionModel = require('../../../../app/models/water/region.model.js') /** @@ -11,10 +12,10 @@ const RegionModel = require('../../../../app/models/water/region.model.js') * * If no `data` is provided, default values will be used. These are * - * - `chargeRegionId` - S - * - `naldRegionId` - 9 - * - `name` - Sroc Supplementary Bill (Test) - * - `displayName` - Sroc Test + * - `chargeRegionId` - [selected based on randomly generated naldRegionId] + * - `naldRegionId` - [randomly generated - 8] + * - `name` - Kingdom of Avalon + * - `displayName` - Avalon * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -29,7 +30,7 @@ function add (data = {}) { } /** - * Returns the defaults used when creating a new region + * Returns the defaults used * * It will override or append to them any data provided. Mainly used by the `add()` method, we make it available * for use in tests to avoid having to duplicate values. @@ -37,11 +38,12 @@ function add (data = {}) { * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database */ function defaults (data = {}) { + const naldRegionId = randomInteger(1, 8) const defaults = { - chargeRegionId: 'S', - naldRegionId: 9, - name: 'Sroc Supplementary Bill (Test)', - displayName: 'Sroc Test' + chargeRegionId: _chargeRegionId(naldRegionId), + naldRegionId, + name: 'Kingdom of Avalon', + displayName: 'Avalon' } return { @@ -50,6 +52,12 @@ function defaults (data = {}) { } } +function _chargeRegionId (naldRegionId) { + const chargeRegionIds = ['A', 'B', 'Y', 'N', 'E', 'S', 'T', 'W'] + + return chargeRegionIds[naldRegionId - 1] +} + module.exports = { add, defaults diff --git a/test/support/helpers/water/transaction.helper.js b/test/support/helpers/water/transaction.helper.js index 90cef1d037..587b807531 100644 --- a/test/support/helpers/water/transaction.helper.js +++ b/test/support/helpers/water/transaction.helper.js @@ -4,6 +4,8 @@ * @module TransactionHelper */ +const { generateChargeReference } = require('./charge-category.helper.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') const TransactionModel = require('../../../../app/models/water/transaction.model.js') /** @@ -11,8 +13,24 @@ const TransactionModel = require('../../../../app/models/water/transaction.model * * If no `data` is provided, default values will be used. These are * - * - `billingInvoiceLicenceId` - 7190937e-e176-4d50-ae4f-c00c5e76938a - * - `description` - River Beult at Boughton Monchelsea + * - `adjustmentFactor` - 1 + * - `aggregateFactor` - 1 + * - `authorisedDays` - 365 + * - `authorisedQuantity` - 11 + * - `billableDays` - 365 + * - `billableQuantity` - 11 + * - `billingInvoiceLicenceId` - [random UUID] + * - `chargeCategoryCode` - [randomly generated - 4.4.5] + * - `chargeCategoryDescription` - Medium loss, non-tidal, restricted water, up to and including 25 ML/yr, Tier 2 model + * - `chargeType` - standard, + * - `description` - Water abstraction charge: Agriculture other than spray irrigation at East Rudham + * - `isCredit` - false + * - `loss` - medium + * - `season` - all year + * - `section130Agreement` - false + * - `scheme` - sroc + * - `source` - non-tidal + * - `volume` - 11 * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -42,8 +60,8 @@ function defaults (data = {}) { authorisedQuantity: 11, billableDays: 365, billableQuantity: 11, - billingInvoiceLicenceId: '7190937e-e176-4d50-ae4f-c00c5e76938a', - chargeCategoryCode: '4.5.6', + billingInvoiceLicenceId: generateUUID(), + chargeCategoryCode: generateChargeReference(), chargeCategoryDescription: 'Medium loss, non-tidal, restricted water, up to and including 25 ML/yr, Tier 2 model', chargeType: 'standard', description: 'Water abstraction charge: Agriculture other than spray irrigation at East Rudham', diff --git a/test/support/helpers/water/workflow.helper.js b/test/support/helpers/water/workflow.helper.js index 3b4d4fea9d..ddf67129b7 100644 --- a/test/support/helpers/water/workflow.helper.js +++ b/test/support/helpers/water/workflow.helper.js @@ -4,6 +4,7 @@ * @module WorkflowHelper */ +const { generateUUID } = require('../../../../app/lib/general.lib.js') const WorkflowModel = require('../../../../app/models/water/workflow.model.js') /** @@ -11,7 +12,7 @@ const WorkflowModel = require('../../../../app/models/water/workflow.model.js') * * If no `data` is provided, default values will be used. These are * - * - `licenceId` - 1acfbded-9cd4-4933-8e98-04cd9e92d884 + * - `licenceId` - [random UUID] * - `status` - to_setup - Other possible values are: changes_requested & review * - `data` - { chargeVersion: null }, * - `createdAt` - the current date and time @@ -38,7 +39,7 @@ function add (data = {}) { */ function defaults (data = {}) { const defaults = { - licenceId: '1acfbded-9cd4-4933-8e98-04cd9e92d884', + licenceId: generateUUID(), status: 'to_setup', data: { chargeVersion: null }, // INFO: The charge_version_workflows table does not have a default for the date_created column. But it is set as