Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more DatabaseSupport.clean() #1285

Merged
merged 12 commits into from
Aug 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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({
Expand Down
23 changes: 12 additions & 11 deletions test/services/bill-runs/setup/create.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')
Expand All @@ -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
Expand All @@ -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()

Expand All @@ -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',
'[email protected]',
2024)
Expand All @@ -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()
})
Expand All @@ -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',
'[email protected]',
2024)
Expand All @@ -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',
'[email protected]',
2024)
Expand All @@ -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'
Expand All @@ -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
}
Expand All @@ -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',
'[email protected]',
2023)
Expand Down
23 changes: 12 additions & 11 deletions test/services/bill-runs/setup/exists.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()

Expand All @@ -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'
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/services/bill-runs/setup/fetch-regions.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 7 additions & 10 deletions test/services/bill-runs/setup/region.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
})
Expand All @@ -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
})
})
})
Expand Down
3 changes: 0 additions & 3 deletions test/services/bill-runs/setup/season.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,8 +17,6 @@ describe('Bill Runs Setup Type service', () => {
let session

beforeEach(async () => {
await DatabaseSupport.clean()

session = await SessionHelper.add({ data: { season: 'summer' } })
})

Expand Down
Loading
Loading