diff --git a/test/presenters/bill-runs/create-bill-run-event.presenter.test.js b/test/presenters/bill-runs/create-bill-run-event.presenter.test.js index 7a9d7afeb8..034d034ff2 100644 --- a/test/presenters/bill-runs/create-bill-run-event.presenter.test.js +++ b/test/presenters/bill-runs/create-bill-run-event.presenter.test.js @@ -10,17 +10,12 @@ const { expect } = Code // Test helpers const BillRunHelper = require('../../support/helpers/bill-run.helper.js') const BillRunModel = require('../../../app/models/bill-run.model.js') -const DatabaseSupport = require('../../support/database.js') const RegionHelper = require('../../support/helpers/region.helper.js') // Thing under test const CreateBillRunEventPresenter = require('../../../app/presenters/bill-runs/create-bill-run-event.presenter.js') describe('Create Bill Run Event presenter', () => { - beforeEach(async () => { - await DatabaseSupport.clean() - }) - describe('when a BillRunModel instance is provided', () => { let billRun diff --git a/test/presenters/charging-module/create-transaction.presenter.test.js b/test/presenters/charging-module/create-transaction.presenter.test.js index 98c8e91631..18ece2cee8 100644 --- a/test/presenters/charging-module/create-transaction.presenter.test.js +++ b/test/presenters/charging-module/create-transaction.presenter.test.js @@ -8,7 +8,6 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../support/database.js') const LicenceHelper = require('../../support/helpers/licence.helper.js') const LicenceModel = require('../../../app/models/licence.model.js') const { ref } = require('objection') @@ -25,10 +24,6 @@ describe('Charging Module Create Transaction presenter', () => { let licence let region - beforeEach(async () => { - await DatabaseSupport.clean() - }) - describe('when provided with a Transaction and Licence instance', () => { beforeEach(async () => { region = RegionHelper.select() diff --git a/test/services/bill-runs/annual/process-bill-run.service.test.js b/test/services/bill-runs/annual/process-bill-run.service.test.js index 4ee8d4460e..6eda12173a 100644 --- a/test/services/bill-runs/annual/process-bill-run.service.test.js +++ b/test/services/bill-runs/annual/process-bill-run.service.test.js @@ -16,7 +16,6 @@ const { determineCurrentFinancialYear } = require('../../../../app/lib/general.l // Things we need to stub const ChargingModuleGenerateRequest = require('../../../../app/requests/charging-module/generate-bill-run.request.js') -const DatabaseSupport = require('../../../support/database.js') const FetchBillingAccountsService = require('../../../../app/services/bill-runs/annual/fetch-billing-accounts.service.js') const HandleErroredBillRunService = require('../../../../app/services/bill-runs/handle-errored-bill-run.service.js') const LegacyRefreshBillRunRequest = require('../../../../app/requests/legacy/refresh-bill-run.request.js') @@ -32,7 +31,6 @@ describe('Annual Process Bill Run service', () => { let notifierStub beforeEach(async () => { - await DatabaseSupport.clean() const financialYearEnd = billingPeriod.startDate.getFullYear() billRun = await BillRunHelper.add({ diff --git a/test/services/bill-runs/setup/create.service.test.js b/test/services/bill-runs/setup/create.service.test.js index 626e41c7d5..97f000c2ac 100644 --- a/test/services/bill-runs/setup/create.service.test.js +++ b/test/services/bill-runs/setup/create.service.test.js @@ -9,7 +9,7 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') +const RegionHelper = require('../../../support/helpers/region.helper.js') const SessionHelper = require('../../../support/helpers/session.helper.js') const SessionModel = require('../../../../app/models/session.model.js') @@ -25,11 +25,12 @@ describe('Bill Runs Setup Create service', () => { let existsResults let legacyCreateBillRunRequestStub + let region let session let startBillRunProcessServiceStub beforeEach(async () => { - await DatabaseSupport.clean() + region = RegionHelper.data[0] legacyCreateBillRunRequestStub = Sinon.stub(LegacyCreateBillRunRequest, 'send') startBillRunProcessServiceStub = Sinon.stub(StartBillRunProcessService, 'go') @@ -42,7 +43,7 @@ describe('Bill Runs Setup Create service', () => { describe('when called and the bill runs have been triggered', () => { beforeEach(async () => { session = await SessionHelper.add({ - data: { region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', type: 'annual' } + data: { region: region.id, type: 'annual' } }) // NOTE: We make these additional $afterFind() calls to trigger the hook that would have been called when the // create service queries for the session. The hook elevates properties from `data` onto the session instance @@ -64,7 +65,7 @@ describe('Bill Runs Setup Create service', () => { describe('when the user wishes to create an annual bill run', () => { beforeEach(async () => { session = await SessionHelper.add({ - data: { region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', type: 'annual' } + data: { region: region.id, type: 'annual' } }) session.$afterFind() @@ -76,7 +77,7 @@ describe('Bill Runs Setup Create service', () => { expect(legacyCreateBillRunRequestStub.called).to.be.false() expect(startBillRunProcessServiceStub.calledWith( - '19a027c6-4aad-47d3-80e3-3917a4579a5b', + region.id, 'annual', 'carol.shaw@atari.com', 2024) @@ -87,7 +88,7 @@ describe('Bill Runs Setup Create service', () => { describe('when the user wishes to create a supplementary bill run', () => { beforeEach(async () => { session = await SessionHelper.add({ - data: { region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', type: 'supplementary' } + data: { region: region.id, type: 'supplementary' } }) session.$afterFind() }) @@ -102,7 +103,7 @@ describe('Bill Runs Setup Create service', () => { expect(legacyCreateBillRunRequestStub.called).to.be.true() expect(startBillRunProcessServiceStub.calledWith( - '19a027c6-4aad-47d3-80e3-3917a4579a5b', + region.id, 'supplementary', 'carol.shaw@atari.com', 2024) @@ -120,7 +121,7 @@ describe('Bill Runs Setup Create service', () => { expect(legacyCreateBillRunRequestStub.called).to.be.false() expect(startBillRunProcessServiceStub.calledWith( - '19a027c6-4aad-47d3-80e3-3917a4579a5b', + region.id, 'supplementary', 'carol.shaw@atari.com', 2024) @@ -147,7 +148,7 @@ describe('Bill Runs Setup Create service', () => { beforeEach(async () => { session = await SessionHelper.add({ data: { - region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', + region: region.id, type: 'two_part_tariff', year: 2022, season: 'summer' @@ -170,7 +171,7 @@ describe('Bill Runs Setup Create service', () => { beforeEach(async () => { session = await SessionHelper.add({ data: { - region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', + region: region.id, type: 'two_part_tariff', year: 2023 } @@ -185,7 +186,7 @@ describe('Bill Runs Setup Create service', () => { expect(legacyCreateBillRunRequestStub.called).to.be.false() expect(startBillRunProcessServiceStub.calledWith( - '19a027c6-4aad-47d3-80e3-3917a4579a5b', + region.id, 'two_part_tariff', 'carol.shaw@atari.com', 2023) diff --git a/test/services/bill-runs/setup/exists.service.test.js b/test/services/bill-runs/setup/exists.service.test.js index 50e95d22bb..29d5177677 100644 --- a/test/services/bill-runs/setup/exists.service.test.js +++ b/test/services/bill-runs/setup/exists.service.test.js @@ -9,9 +9,9 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') -const { determineCurrentFinancialYear } = require('../../../../app/lib/general.lib.js') +const RegionHelper = require('../../../support/helpers/region.helper.js') const SessionHelper = require('../../../support/helpers/session.helper.js') +const { determineCurrentFinancialYear } = require('../../../../app/lib/general.lib.js') // Things we need to stub const DetermineBlockingBillRunService = require('../../../../app/services/bill-runs/determine-blocking-bill-run.service.js') @@ -23,9 +23,10 @@ const ExistsService = require('../../../../app/services/bill-runs/setup/exists.s describe('Bill Runs Setup Exists service', () => { let currentFinancialEndYear let setupSession + let region beforeEach(async () => { - await DatabaseSupport.clean() + region = RegionHelper.select() const { endDate } = determineCurrentFinancialYear() @@ -42,7 +43,7 @@ describe('Bill Runs Setup Exists service', () => { setupSession = await SessionHelper.add({ data: { type: 'two_part_tariff', - region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', + region: region.id, year: '2022', season: 'summer' } @@ -75,7 +76,7 @@ describe('Bill Runs Setup Exists service', () => { batchType: 'two_part_tariff', billRunNumber: 12345, createdAt: new Date('2022-05-01'), - region: { id: '19a027c6-4aad-47d3-80e3-3917a4579a5b', displayName: 'stormlands' }, + region, scheme: 'alcs', status: 'sent', summer: true, @@ -104,7 +105,7 @@ describe('Bill Runs Setup Exists service', () => { setupSession = await SessionHelper.add({ data: { type: 'annual', - region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', + region, year: '2022', season: 'summer' } @@ -137,7 +138,7 @@ describe('Bill Runs Setup Exists service', () => { batchType: 'annual', billRunNumber: 12345, createdAt: new Date('2023-05-01'), - region: { id: '19a027c6-4aad-47d3-80e3-3917a4579a5b', displayName: 'stormlands' }, + region, scheme: 'sroc', status: 'sent', summer: false, @@ -166,7 +167,7 @@ describe('Bill Runs Setup Exists service', () => { setupSession = await SessionHelper.add({ data: { type: 'supplementary', - region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', + region: region.id, year: '2022', season: 'summer' } @@ -199,7 +200,7 @@ describe('Bill Runs Setup Exists service', () => { batchType: 'supplementary', billRunNumber: 12345, createdAt: new Date('2023-05-01'), - region: { id: '19a027c6-4aad-47d3-80e3-3917a4579a5b', displayName: 'stormlands' }, + region, scheme: 'sroc', status: 'ready', summer: false, @@ -229,7 +230,7 @@ describe('Bill Runs Setup Exists service', () => { batchType: 'supplementary', billRunNumber: 12345, createdAt: new Date('2023-05-01'), - region: { id: '19a027c6-4aad-47d3-80e3-3917a4579a5b', displayName: 'stormlands' }, + region, scheme: 'sroc', status: 'ready', summer: false, @@ -240,7 +241,7 @@ describe('Bill Runs Setup Exists service', () => { batchType: 'supplementary', billRunNumber: 12345, createdAt: new Date('2023-05-01'), - region: { id: '19a027c6-4aad-47d3-80e3-3917a4579a5b', displayName: 'stormlands' }, + region, scheme: 'presroc', status: 'ready', summer: false, diff --git a/test/services/bill-runs/setup/fetch-regions.service.test.js b/test/services/bill-runs/setup/fetch-regions.service.test.js index d6ae9182fe..0891bb27f5 100644 --- a/test/services/bill-runs/setup/fetch-regions.service.test.js +++ b/test/services/bill-runs/setup/fetch-regions.service.test.js @@ -18,7 +18,8 @@ describe('Bill Runs Setup - Fetch Regions service', () => { it('returns the ID and display name for each region ordered by display name', async () => { const results = await FetchRegionsService.go() - // This is necessary because other region helpers are adding regions into the database as part of their tests. + // TODO: This is necessary because other region helpers are adding regions into the database as part + // of their tests. (Remove when cleans have been removed) const expectedRegions = RegionHelper.data.map((region) => { return { id: region.id, diff --git a/test/services/bill-runs/setup/initialise-session.service.test.js b/test/services/bill-runs/setup/initialise-session.service.test.js index 41f29c827a..2afb1f6990 100644 --- a/test/services/bill-runs/setup/initialise-session.service.test.js +++ b/test/services/bill-runs/setup/initialise-session.service.test.js @@ -4,21 +4,16 @@ const Lab = require('@hapi/lab') const Code = require('@hapi/code') -const { describe, it, beforeEach } = exports.lab = Lab.script() +const { describe, it } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const SessionModel = require('../../../../app/models/session.model.js') // Thing under test const InitiateSessionService = require('../../../../app/services/bill-runs/setup/initiate-session.service.js') describe('Bill Run Initiate Session service', () => { - beforeEach(async () => { - await DatabaseSupport.clean() - }) - describe('when called', () => { it('creates a new session record with an empty data property', async () => { const result = await InitiateSessionService.go() diff --git a/test/services/bill-runs/setup/region.service.test.js b/test/services/bill-runs/setup/region.service.test.js index 2306934e28..1f0be2cd5f 100644 --- a/test/services/bill-runs/setup/region.service.test.js +++ b/test/services/bill-runs/setup/region.service.test.js @@ -9,7 +9,7 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') +const RegionHelper = require('../../../support/helpers/region.helper.js') const SessionHelper = require('../../../support/helpers/session.helper.js') // Things we need to stub @@ -19,18 +19,15 @@ const FetchRegionsService = require('../../../../app/services/bill-runs/setup/fe const RegionService = require('../../../../app/services/bill-runs/setup/region.service.js') describe('Bill Runs Setup Region service', () => { - const regions = [ - { id: 'e21b987c-7a5f-4eb3-a794-e4aae4a96a28', displayName: 'Riverlands' }, - { id: '19a027c6-4aad-47d3-80e3-3917a4579a5b', displayName: 'Stormlands' }, - { id: '3334054e-03b6-4696-9d74-62b8b76a3c64', displayName: 'Westerlands' } - ] - let session + let regions + let region beforeEach(async () => { - await DatabaseSupport.clean() + regions = RegionHelper.data + region = RegionHelper.select() - session = await SessionHelper.add({ data: { region: '19a027c6-4aad-47d3-80e3-3917a4579a5b' } }) + session = await SessionHelper.add({ data: { region: region.id } }) Sinon.stub(FetchRegionsService, 'go').resolves(regions) }) @@ -46,7 +43,7 @@ describe('Bill Runs Setup Region service', () => { expect(result).to.equal({ sessionId: session.id, regions, - selectedRegion: '19a027c6-4aad-47d3-80e3-3917a4579a5b' + selectedRegion: region.id }) }) }) diff --git a/test/services/bill-runs/setup/season.service.test.js b/test/services/bill-runs/setup/season.service.test.js index e109de25ad..8c24de33a0 100644 --- a/test/services/bill-runs/setup/season.service.test.js +++ b/test/services/bill-runs/setup/season.service.test.js @@ -8,7 +8,6 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const SessionHelper = require('../../../support/helpers/session.helper.js') // Thing under test @@ -18,8 +17,6 @@ describe('Bill Runs Setup Type service', () => { let session beforeEach(async () => { - await DatabaseSupport.clean() - session = await SessionHelper.add({ data: { season: 'summer' } }) }) diff --git a/test/services/bill-runs/setup/submit-region.service.test.js b/test/services/bill-runs/setup/submit-region.service.test.js index a8e7dc0a5b..9c14d197ae 100644 --- a/test/services/bill-runs/setup/submit-region.service.test.js +++ b/test/services/bill-runs/setup/submit-region.service.test.js @@ -9,7 +9,7 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') +const RegionHelper = require('../../../support/helpers/region.helper.js') const SessionHelper = require('../../../support/helpers/session.helper.js') // Things we need to stub @@ -19,17 +19,14 @@ const FetchRegionsService = require('../../../../app/services/bill-runs/setup/fe const SubmitRegionService = require('../../../../app/services/bill-runs/setup/submit-region.service.js') describe('Bill Runs Setup Submit Region service', () => { - const regions = [ - { id: 'e21b987c-7a5f-4eb3-a794-e4aae4a96a28', displayName: 'Riverlands' }, - { id: '19a027c6-4aad-47d3-80e3-3917a4579a5b', displayName: 'Stormlands' }, - { id: '3334054e-03b6-4696-9d74-62b8b76a3c64', displayName: 'Westerlands' } - ] - let payload + let region + let regions let session beforeEach(async () => { - await DatabaseSupport.clean() + regions = RegionHelper.data + region = RegionHelper.select() session = await SessionHelper.add({ data: {} }) @@ -44,7 +41,7 @@ describe('Bill Runs Setup Submit Region service', () => { describe('with a valid payload', () => { beforeEach(() => { payload = { - region: '19a027c6-4aad-47d3-80e3-3917a4579a5b' + region: region.id } }) @@ -58,7 +55,7 @@ describe('Bill Runs Setup Submit Region service', () => { const refreshedSession = await session.$query() - expect(refreshedSession.region).to.equal('19a027c6-4aad-47d3-80e3-3917a4579a5b') + expect(refreshedSession.region).to.equal(region.id) expect(result.setupComplete).to.be.true() }) }) @@ -73,7 +70,7 @@ describe('Bill Runs Setup Submit Region service', () => { const refreshedSession = await session.$query() - expect(refreshedSession.region).to.equal('19a027c6-4aad-47d3-80e3-3917a4579a5b') + expect(refreshedSession.region).to.equal(region.id) expect(result.setupComplete).to.be.false() }) }) diff --git a/test/services/bill-runs/setup/submit-season.service.test.js b/test/services/bill-runs/setup/submit-season.service.test.js index 14450a768a..e594989a06 100644 --- a/test/services/bill-runs/setup/submit-season.service.test.js +++ b/test/services/bill-runs/setup/submit-season.service.test.js @@ -8,7 +8,6 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const SessionHelper = require('../../../support/helpers/session.helper.js') // Thing under test @@ -19,8 +18,6 @@ describe('Bill Runs Setup Submit Season service', () => { let session beforeEach(async () => { - await DatabaseSupport.clean() - session = await SessionHelper.add({ data: {} }) }) diff --git a/test/services/bill-runs/setup/submit-type.service.test.js b/test/services/bill-runs/setup/submit-type.service.test.js index fb273b1143..246c402a9b 100644 --- a/test/services/bill-runs/setup/submit-type.service.test.js +++ b/test/services/bill-runs/setup/submit-type.service.test.js @@ -8,7 +8,6 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const SessionHelper = require('../../../support/helpers/session.helper.js') // Thing under test @@ -19,8 +18,6 @@ describe('Bill Runs Setup Submit Type service', () => { let session beforeEach(async () => { - await DatabaseSupport.clean() - session = await SessionHelper.add({ data: {} }) }) diff --git a/test/services/bill-runs/setup/submit-year.service.test.js b/test/services/bill-runs/setup/submit-year.service.test.js index 76c79f5d9c..8d16cf37fd 100644 --- a/test/services/bill-runs/setup/submit-year.service.test.js +++ b/test/services/bill-runs/setup/submit-year.service.test.js @@ -8,7 +8,6 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const SessionHelper = require('../../../support/helpers/session.helper.js') // Thing under test @@ -19,8 +18,6 @@ describe('Bill Runs Setup Submit Year service', () => { let session beforeEach(async () => { - await DatabaseSupport.clean() - session = await SessionHelper.add({ data: {} }) }) diff --git a/test/services/bill-runs/setup/type.service.test.js b/test/services/bill-runs/setup/type.service.test.js index d49edde228..11229d6af3 100644 --- a/test/services/bill-runs/setup/type.service.test.js +++ b/test/services/bill-runs/setup/type.service.test.js @@ -8,7 +8,6 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const SessionHelper = require('../../../support/helpers/session.helper.js') // Thing under test @@ -18,8 +17,6 @@ describe('Bill Runs Setup Type service', () => { let session beforeEach(async () => { - await DatabaseSupport.clean() - session = await SessionHelper.add({ data: { type: 'annual' } }) }) diff --git a/test/services/bill-runs/setup/year.service.test.js b/test/services/bill-runs/setup/year.service.test.js index 2d73e97a63..67c1792412 100644 --- a/test/services/bill-runs/setup/year.service.test.js +++ b/test/services/bill-runs/setup/year.service.test.js @@ -8,7 +8,6 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const SessionHelper = require('../../../support/helpers/session.helper.js') // Thing under test @@ -18,8 +17,6 @@ describe('Bill Runs Setup Year service', () => { let session beforeEach(async () => { - await DatabaseSupport.clean() - session = await SessionHelper.add({ data: { year: 2024 } }) }) diff --git a/test/services/bill-runs/supplementary/fetch-billing-accounts.service.test.js b/test/services/bill-runs/supplementary/fetch-billing-accounts.service.test.js index 2b984080d1..11625f0f4d 100644 --- a/test/services/bill-runs/supplementary/fetch-billing-accounts.service.test.js +++ b/test/services/bill-runs/supplementary/fetch-billing-accounts.service.test.js @@ -9,16 +9,11 @@ const { expect } = Code // Test helpers const BillingAccountHelper = require('../../../support/helpers/billing-account.helper.js') -const DatabaseSupport = require('../../../support/database.js') // Thing under test const FetchBillingAccountsService = require('../../../../app/services/bill-runs/supplementary/fetch-billing-accounts.service.js') describe('Fetch Billing Accounts service', () => { - beforeEach(async () => { - await DatabaseSupport.clean() - }) - describe('when the service is called with an array of charge version', () => { let expectedResult let billingAccounts diff --git a/test/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.test.js b/test/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.test.js index f891e6ef1b..60ae9ba9bc 100644 --- a/test/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.test.js +++ b/test/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.test.js @@ -11,7 +11,6 @@ const { expect } = Code // Test helpers const BillRunHelper = require('../../../support/helpers/bill-run.helper.js') const DatabaseConfig = require('../../../../config/database.config.js') -const DatabaseSupport = require('../../../support/database.js') const RegionHelper = require('../../../support/helpers/region.helper.js') const ReviewLicenceHelper = require('../../../support/helpers/review-licence.helper.js') @@ -28,10 +27,6 @@ describe('Fetch Bill Run Licences service', () => { let testLicenceReview let testLicenceNoIssues - beforeEach(async () => { - await DatabaseSupport.clean() - }) - afterEach(() => { Sinon.restore() }) diff --git a/test/services/bill-runs/two-part-tariff/submit-amended-authorised-volume.service.test.js b/test/services/bill-runs/two-part-tariff/submit-amended-authorised-volume.service.test.js index 4464cb788c..1dfaac82ce 100644 --- a/test/services/bill-runs/two-part-tariff/submit-amended-authorised-volume.service.test.js +++ b/test/services/bill-runs/two-part-tariff/submit-amended-authorised-volume.service.test.js @@ -10,7 +10,6 @@ const { expect } = Code // Test helpers const AmendAuthorisedVolumePresenter = require('../../../../app/presenters/bill-runs/two-part-tariff/amend-authorised-volume.presenter.js') -const DatabaseSupport = require('../../../support/database.js') const FetchAuthorisedVolumeService = require('../../../../app/services/bill-runs/two-part-tariff/fetch-authorised-volume.service.js') const ReviewChargeReferenceHelper = require('../../../support/helpers/review-charge-reference.helper.js') const ReviewChargeReferenceModel = require('../../../../app/models/review-charge-reference.model.js') @@ -27,8 +26,6 @@ describe('Submit Amended Authorised Volume Service', () => { let yarStub beforeEach(async () => { - await DatabaseSupport.clean() - yarStub = { flash: Sinon.stub() } reviewChargeReference = await ReviewChargeReferenceHelper.add() diff --git a/test/services/bill-runs/two-part-tariff/submit-amended-billable-returns.service.test.js b/test/services/bill-runs/two-part-tariff/submit-amended-billable-returns.service.test.js index 02068db9f8..4e260a60b0 100644 --- a/test/services/bill-runs/two-part-tariff/submit-amended-billable-returns.service.test.js +++ b/test/services/bill-runs/two-part-tariff/submit-amended-billable-returns.service.test.js @@ -9,7 +9,6 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const ReviewChargeElementHelper = require('../../../support/helpers/review-charge-element.helper.js') const ReviewChargeElementModel = require('../../../../app/models/review-charge-element.model.js') @@ -28,8 +27,6 @@ describe('Submit Amended Billable Returns Service', () => { let yarStub beforeEach(async () => { - await DatabaseSupport.clean() - yarStub = { flash: Sinon.stub() } reviewChargeElement = await ReviewChargeElementHelper.add() diff --git a/test/services/bill-runs/two-part-tariff/submit-review-licence.service.test.js b/test/services/bill-runs/two-part-tariff/submit-review-licence.service.test.js index 4e928aadf8..e481dde7c3 100644 --- a/test/services/bill-runs/two-part-tariff/submit-review-licence.service.test.js +++ b/test/services/bill-runs/two-part-tariff/submit-review-licence.service.test.js @@ -9,7 +9,6 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const ReviewLicenceHelper = require('../../../support/helpers/review-licence.helper.js') // Thing under test @@ -24,8 +23,6 @@ describe('Submit Review Licence Service', () => { let yarStub beforeEach(async () => { - await DatabaseSupport.clean() - yarStub = { flash: Sinon.stub() } }) diff --git a/test/services/jobs/licence-updates/fetch-licence-updates.service.test.js b/test/services/jobs/licence-updates/fetch-licence-updates.service.test.js index 5706f2560e..e645efe358 100644 --- a/test/services/jobs/licence-updates/fetch-licence-updates.service.test.js +++ b/test/services/jobs/licence-updates/fetch-licence-updates.service.test.js @@ -13,7 +13,6 @@ const BillRunHelper = require('../../../support/helpers/bill-run.helper.js') const ChargeVersionHelper = require('../../../support/helpers/charge-version.helper.js') const LicenceHelper = require('../../../support/helpers/licence.helper.js') const LicenceVersionHelper = require('../../../support/helpers/licence-version.helper.js') -const DatabaseSupport = require('../../../support/database.js') const WorkflowHelper = require('../../../support/helpers/workflow.helper.js') // Thing under test @@ -24,8 +23,6 @@ describe('Fetch Licence Updates service', () => { let licenceVersion beforeEach(async () => { - await DatabaseSupport.clean() - licence = await LicenceHelper.add() }) @@ -38,7 +35,7 @@ describe('Fetch Licence Updates service', () => { it('returns the expected result', async () => { const results = await FetchLicenceUpdatesService.go() - const result = results[0] + const result = results.find((l) => { return l.id === licenceVersion.id }) expect(result.id).to.be.equal(licenceVersion.id) expect(result.licenceId).to.be.equal(licence.id) @@ -54,7 +51,7 @@ describe('Fetch Licence Updates service', () => { it('returns the expected result', async () => { const results = await FetchLicenceUpdatesService.go() - const result = results[0] + const result = results.find((l) => { return l.id === licenceVersion.id }) expect(result.id).to.be.equal(licenceVersion.id) expect(result.licenceId).to.be.equal(licence.id) @@ -70,7 +67,9 @@ describe('Fetch Licence Updates service', () => { }) it('returns no results', async () => { - const results = await FetchLicenceUpdatesService.go() + const data = await FetchLicenceUpdatesService.go() + + const results = data.filter((l) => { return l.licenceId === licence.id }) expect(results).to.be.empty() }) @@ -83,7 +82,9 @@ describe('Fetch Licence Updates service', () => { }) it('returns no results', async () => { - const results = await FetchLicenceUpdatesService.go() + const data = await FetchLicenceUpdatesService.go() + + const results = data.filter((l) => { return l.licenceId === licence.id }) expect(results).to.be.empty() }) @@ -102,7 +103,9 @@ describe('Fetch Licence Updates service', () => { }) it('returns no results', async () => { - const results = await FetchLicenceUpdatesService.go() + const data = await FetchLicenceUpdatesService.go() + + const results = data.filter((l) => { return l.licenceId === licence.id }) expect(results).to.be.empty() }) @@ -114,7 +117,9 @@ describe('Fetch Licence Updates service', () => { }) it('returns no results', async () => { - const results = await FetchLicenceUpdatesService.go() + const data = await FetchLicenceUpdatesService.go() + + const results = data.filter((l) => { return l.licenceId === licence.id }) expect(results).to.be.empty() }) diff --git a/test/services/jobs/session-cleanup/process-session-storage-cleanup.service.test.js b/test/services/jobs/session-cleanup/process-session-storage-cleanup.service.test.js index e0695e5a63..5cdf3c9043 100644 --- a/test/services/jobs/session-cleanup/process-session-storage-cleanup.service.test.js +++ b/test/services/jobs/session-cleanup/process-session-storage-cleanup.service.test.js @@ -9,7 +9,6 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const SessionHelper = require('../../../support/helpers/session.helper.js') const SessionModel = require('../../../../app/models/session.model.js') @@ -20,10 +19,9 @@ describe('Process Session Storage Cleanup service', () => { const todayMinusOneDay = new Date(new Date().setDate(new Date().getDate() - 1)).toISOString() let notifierStub + let session beforeEach(async () => { - await DatabaseSupport.clean() - // The service depends on GlobalNotifier to have been set. This happens in app/plugins/global-notifier.plugin.js // when the app starts up and the plugin is registered. As we're not creating an instance of Hapi server in this // test we recreate the condition by setting it directly with our own stub @@ -37,13 +35,13 @@ describe('Process Session Storage Cleanup service', () => { describe('when there is session data created more than 1 day ago', () => { beforeEach(async () => { - await SessionHelper.add({ createdAt: todayMinusOneDay }) + session = await SessionHelper.add({ createdAt: todayMinusOneDay }) }) it('removes the session data created more than 1 day ago', async () => { await ProcessSessionStorageCleanupService.go() - const results = await SessionModel.query() + const results = await SessionModel.query().whereIn('id', [session.id]) expect(results).to.have.length(0) }) @@ -62,13 +60,13 @@ describe('Process Session Storage Cleanup service', () => { describe('when there is session data created less than 1 day ago (today)', () => { beforeEach(async () => { - await SessionHelper.add() + session = await SessionHelper.add() }) it('does not remove the session data created less than 1 day ago', async () => { await ProcessSessionStorageCleanupService.go() - const results = await SessionModel.query() + const results = await SessionModel.query().whereIn('id', [session.id]) expect(results).to.have.length(1) }) diff --git a/test/services/jobs/time-limited/process-time-limited-licences.service.test.js b/test/services/jobs/time-limited/process-time-limited-licences.service.test.js index ca76233e18..67dc8ff24a 100644 --- a/test/services/jobs/time-limited/process-time-limited-licences.service.test.js +++ b/test/services/jobs/time-limited/process-time-limited-licences.service.test.js @@ -9,8 +9,8 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const DatabaseSupport = require('../../../support/database.js') const WorkflowModel = require('../../../../app/models/workflow.model.js') +const { generateUUID } = require('../../../../app/lib/general.lib.js') // Things we need to stub const FetchTimeLimitedLicencesService = require('../../../../app/services/jobs/time-limited/fetch-time-limited-licences.service.js') @@ -23,8 +23,6 @@ describe('Process Time Limited Licences service', () => { let notifierStub beforeEach(async () => { - await DatabaseSupport.clean() - // The service depends on GlobalNotifier to have been set. This happens in app/plugins/global-notifier.plugin.js // when the app starts up and the plugin is registered. As we're not creating an instance of Hapi server in this // test we recreate the condition by setting it directly with our own stub @@ -40,14 +38,14 @@ describe('Process Time Limited Licences service', () => { beforeEach(() => { fetchResults = [ { - id: 'ece3a745-d7b8-451e-8434-9977fbaa3bc1', - licenceVersionId: 'a3f0bdeb-edcb-427d-9f79-c345d19d8aa1', - chargeVersionId: 'dbb98ce9-2cfd-4d74-94ac-c4e6e8f42442' + id: generateUUID(), + licenceVersionId: generateUUID(), + chargeVersionId: generateUUID() }, { - id: 'cbd2195f-17c4-407d-b7ed-c3cd729c3dca', - licenceVersionId: 'fa25c580-710e-48f0-8932-b2d18e391994', - chargeVersionId: 'cc192da9-d0f4-489d-bf44-0de2544bc801' + id: generateUUID(), + licenceVersionId: generateUUID(), + chargeVersionId: generateUUID() } ] @@ -57,24 +55,26 @@ describe('Process Time Limited Licences service', () => { it('adds the licences to the workflow table', async () => { await ProcessTimeLimitedLicencesService.go() - const results = await WorkflowModel.query().orderBy('createdAt', 'asc') + const results = await WorkflowModel.query() + .whereIn('licenceId', [fetchResults[0].id, fetchResults[1].id]) + .orderBy('createdAt', 'asc') expect(results).to.have.length(2) - expect(results[0].licenceId).to.equal('ece3a745-d7b8-451e-8434-9977fbaa3bc1') - expect(results[0].licenceVersionId).to.equal('a3f0bdeb-edcb-427d-9f79-c345d19d8aa1') + expect(results[0].licenceId).to.equal(fetchResults[0].id) + expect(results[0].licenceVersionId).to.equal(fetchResults[0].licenceVersionId) expect(results[0].status).to.equal('to_setup') expect(results[0].data).to.equal({ chargeVersion: null, - timeLimitedChargeVersionId: 'dbb98ce9-2cfd-4d74-94ac-c4e6e8f42442' + timeLimitedChargeVersionId: fetchResults[0].chargeVersionId }) - expect(results[1].licenceId).to.equal('cbd2195f-17c4-407d-b7ed-c3cd729c3dca') - expect(results[1].licenceVersionId).to.equal('fa25c580-710e-48f0-8932-b2d18e391994') + expect(results[1].licenceId).to.equal(fetchResults[1].id) + expect(results[1].licenceVersionId).to.equal(fetchResults[1].licenceVersionId) expect(results[1].status).to.equal('to_setup') expect(results[1].data).to.equal({ chargeVersion: null, - timeLimitedChargeVersionId: 'cc192da9-d0f4-489d-bf44-0de2544bc801' + timeLimitedChargeVersionId: fetchResults[1].chargeVersionId }) }) @@ -102,7 +102,10 @@ describe('Process Time Limited Licences service', () => { it('adds nothing to workflow', async () => { await ProcessTimeLimitedLicencesService.go() - const results = await WorkflowModel.query().orderBy('createdAt', 'asc') + const results = await WorkflowModel.query() + // Matches the fetched results for FetchTimeLimitedLicencesService + .whereIn('licenceId', []) + .orderBy('createdAt', 'asc') expect(results).to.be.empty() }) diff --git a/test/support/database.js b/test/support/database.js index 2bcc9802ce..16922a8360 100644 --- a/test/support/database.js +++ b/test/support/database.js @@ -120,6 +120,10 @@ async function _viewNames (schema) { }) } +/** + * Close the connection to the database + * + */ async function closeConnection () { await db.destroy() }