Skip to content

Remove more DatabaseSupport.clean() from tests #1241

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

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions test/services/bills/fetch-bill-summary.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ const { describe, it, beforeEach } = exports.lab = Lab.script()
const { expect } = Code

// Test helpers
const BillingAccountHelper = require('../../support/helpers/billing-account.helper.js')
const BillingAccountAddressHelper = require('../../support/helpers/billing-account-address.helper.js')
const BillHelper = require('../../support/helpers/bill.helper.js')
const BillLicenceHelper = require('../../support/helpers/bill-licence.helper.js')
const BillRunHelper = require('../../support/helpers/bill-run.helper.js')
const BillingAccountAddressHelper = require('../../support/helpers/billing-account-address.helper.js')
const BillingAccountHelper = require('../../support/helpers/billing-account.helper.js')
const CompanyHelper = require('../../support/helpers/company.helper.js')
const ContactHelper = require('../../support/helpers/contact.helper.js')
const DatabaseSupport = require('../../support/database.js')
const RegionHelper = require('../../support/helpers/region.helper.js')

// Thing under test
Expand All @@ -26,46 +25,56 @@ describe('Fetch Bill Summary service', () => {

let agentCompanyId
let bill
let billingAccountId
let billingAccountAddressId
let billRunId
let billingAccount
let billingAccountAddressId
let billingAccountId
let companyId
let contactId
let regionId

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

const company = await CompanyHelper.add()

companyId = company.id

const billingAccount = await BillingAccountHelper.add({ accountNumber: 'T65757520A', companyId })
billingAccount = await BillingAccountHelper.add({ companyId })

billingAccountId = billingAccount.id

const agentCompany = await CompanyHelper.add({ name: 'Agent Company Ltd' })

agentCompanyId = agentCompany.id

const contact = await ContactHelper.add()

contactId = contact.id

const billingAccountAddress = await BillingAccountAddressHelper.add({
billingAccountId, companyId: agentCompanyId, contactId, endDate: null
})

billingAccountAddressId = billingAccountAddress.id

const region = await RegionHelper.add({ displayName: 'Stormlands' })

regionId = region.id

const billRun = await BillRunHelper.add({
billRunNumber: 1075, createdAt: new Date('2023-05-01'), status: 'ready', regionId
})

billRunId = billRun.id

bill = await BillHelper.add({ accountNumber: 'T65757520A', billingAccountId, billRunId, netAmount: 1045 })
bill = await BillHelper
.add({ accountNumber: billingAccount.accountNumber, billingAccountId, billRunId, netAmount: 1045 })

const billId = bill.id

for (let i = 0; i < 2; i++) {
const billLicence = await BillLicenceHelper.add({ billId, licenceRef: `01/0${i + 1}/26/9400` })
const billLicence = await BillLicenceHelper
.add({ billId, licenceRef: `01/0${i + 1}/26/9400` })

billLicences.push(billLicence)
}
})
Expand All @@ -79,7 +88,7 @@ describe('Fetch Bill Summary service', () => {
netAmount: 1045,
billingAccount: {
id: billingAccountId,
accountNumber: 'T65757520A',
accountNumber: billingAccount.accountNumber,
company: {
id: companyId,
name: 'Example Trading Ltd',
Expand Down
5 changes: 1 addition & 4 deletions test/services/bills/fetch-bill.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ const { expect } = Code

// Test helpers
const BillHelper = require('../../support/helpers/bill.helper.js')
const BillLicenceHelper = require('../../support/helpers/bill-licence.helper.js')
const BillModel = require('../../../app/models/bill.model.js')
const BillRunHelper = require('../../support/helpers/bill-run.helper.js')
const BillRunModel = require('../../../app/models/bill-run.model.js')
const BillLicenceHelper = require('../../support/helpers/bill-licence.helper.js')
const DatabaseSupport = require('../../support/database.js')
const RegionHelper = require('../../support/helpers/region.helper.js')
const RegionModel = require('../../../app/models/region.model.js')
const TransactionHelper = require('../../support/helpers/transaction.helper.js')
Expand All @@ -29,8 +28,6 @@ describe('Fetch Bill service', () => {
let unlinkedBillLicence

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

linkedRegion = await RegionHelper.add()
linkedBillRun = await BillRunHelper.add({ regionId: linkedRegion.id })

Expand Down
3 changes: 0 additions & 3 deletions test/services/bills/submit-remove-bill.services.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { expect } = Code

// Test helpers
const BillHelper = require('../../support/helpers/bill.helper.js')
const DatabaseSupport = require('../../support/database.js')

// Things we need to stub
const LegacyDeleteBillRequest = require('../../../app/requests/legacy/delete-bill.request.js')
Expand All @@ -25,8 +24,6 @@ describe('Submit Remove Bill service', () => {
let legacyDeleteBillRequestStub

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

bill = await BillHelper.add()

legacyDeleteBillRequestStub = Sinon.stub(LegacyDeleteBillRequest, 'send').resolves()
Expand Down
24 changes: 12 additions & 12 deletions test/services/data/deduplicate/de-duplicate-licence.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@ 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 { generateLicenceRef } = require('../../../support/helpers/licence.helper.js')

// Thing under test
const DeDuplicateLicenceService = require('../../../../app/services/data/deduplicate/de-duplicate-licence.service.js')

describe('De-duplicate Licence service', () => {
const licenceRef = '01/120'

let invalidLicence
let licenceRef
let validLicences

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

validLicences = []

// Create our valid licence
let licence = await LicenceHelper.add({ licenceRef })

validLicences.push(licence.id)

// Create other valid licences that will match our search. We need to ensure these do not get deleted by the service
licence = await LicenceHelper.add({ licenceRef: 'WA/01/120' })
licence = await LicenceHelper.add({ licenceRef: generateLicenceRef() })
validLicences.push(licence.id)
licence = await LicenceHelper.add({ licenceRef: '02/01/120/R01' })
licence = await LicenceHelper.add({ licenceRef: generateLicenceRef() })
validLicences.push(licence.id)
})

describe('when there is a duplicate licence', () => {
describe('with a space', () => {
describe('at the start of the reference', () => {
beforeEach(async () => {
invalidLicence = await LicenceHelper.add({ licenceRef: ' 01/120' })
invalidLicence = await LicenceHelper.add({ licenceRef: ` ${licenceRef}` })
})

it('removes just that invalid licence', async () => {
Expand All @@ -59,7 +59,7 @@ describe('De-duplicate Licence service', () => {

describe('at the end of the reference', () => {
beforeEach(async () => {
invalidLicence = await LicenceHelper.add({ licenceRef: '01/120 ' })
invalidLicence = await LicenceHelper.add({ licenceRef: `${licenceRef} ` })
})

it('removes just that invalid licence', async () => {
Expand All @@ -77,7 +77,7 @@ describe('De-duplicate Licence service', () => {

describe('at the start and end of the reference', () => {
beforeEach(async () => {
invalidLicence = await LicenceHelper.add({ licenceRef: ' 01/120 ' })
invalidLicence = await LicenceHelper.add({ licenceRef: ` ${licenceRef} ` })
})

it('removes just that invalid licence', async () => {
Expand All @@ -97,7 +97,7 @@ describe('De-duplicate Licence service', () => {
describe('with a newline', () => {
describe('at the start of the reference', () => {
beforeEach(async () => {
invalidLicence = await LicenceHelper.add({ licenceRef: '\n01/120' })
invalidLicence = await LicenceHelper.add({ licenceRef: `\n${licenceRef}` })
})

it('removes just that invalid licence', async () => {
Expand All @@ -115,7 +115,7 @@ describe('De-duplicate Licence service', () => {

describe('at the end of the reference', () => {
beforeEach(async () => {
invalidLicence = await LicenceHelper.add({ licenceRef: '01/120\n' })
invalidLicence = await LicenceHelper.add({ licenceRef: `${licenceRef}\n` })
})

it('removes just that invalid licence', async () => {
Expand All @@ -133,7 +133,7 @@ describe('De-duplicate Licence service', () => {

describe('at the start and end of the reference', () => {
beforeEach(async () => {
invalidLicence = await LicenceHelper.add({ licenceRef: '\n01/120\n' })
invalidLicence = await LicenceHelper.add({ licenceRef: `\n${licenceRef}\n` })
})

it('removes just that invalid licence', async () => {
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 ReturnVersionHelper = require('../../support/helpers/return-version.helper.js')

// Thing under test
Expand All @@ -18,10 +17,6 @@ const FetchLicenceHasRequirementsService =
describe('Fetch Licence Has Requirements service', () => {
const licenceId = 'e004c0c9-0316-42fc-a6e3-5ae9a271b3c6'

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

describe('when the licence has return versions', () => {
beforeEach(async () => {
await ReturnVersionHelper.add({ licenceId })
Expand Down
6 changes: 2 additions & 4 deletions test/services/licences/fetch-communications.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ const { describe, it, beforeEach } = exports.lab = Lab.script()
const { expect } = Code

// Test helpers
const DatabaseSupport = require('../../support/database.js')
const EventHelper = require('../../support/helpers/event.helper.js')
const ScheduledNotificationModel = require('../../support/helpers/scheduled-notification.helper.js')
const { generateLicenceRef } = require('../../support/helpers/licence.helper.js')

// Thing under test
const FetchCommunicationsService =
require('../../../app/services/licences/fetch-communications.service.js')

describe('Fetch Communications service', () => {
const licenceRef = '01/01'
const licenceRef = generateLicenceRef()

let event
let scheduledNotification

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

event = await EventHelper.add({
createdAt: new Date('2024-06-01'),
licences: JSON.stringify([licenceRef]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const { expect } = Code
const CompanyContactHelper = require('../../support/helpers/company-contact.helper.js')
const CompanyHelper = require('../../support/helpers/company.helper.js')
const ContactHelper = require('../../support/helpers/contact.helper.js')
const DatabaseSupport = require('../../support/database.js')
const LicenceDocumentHelper = require('../../support/helpers/licence-document.helper.js')
const LicenceDocumentRoleHelper = require('../../support/helpers/licence-document-role.helper.js')
const LicenceHelper = require('../../support/helpers/licence.helper.js')
Expand All @@ -26,19 +25,18 @@ describe('Fetch Customer Contacts service', () => {
let contactId
let licenceId

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

describe('when the licence has customer contact details', () => {
beforeEach(async () => {
const licence = await LicenceHelper.add()

licenceId = licence.id

const company = await CompanyHelper.add()

companyId = company.id

const contact = await ContactHelper.add()

contactId = contact.id

const { id: licenceDocumentId } = await LicenceDocumentHelper.add({ licenceRef: licence.licenceRef })
Expand Down
9 changes: 4 additions & 5 deletions test/services/licences/fetch-licence-contacts.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const { expect } = Code
const AddressHelper = require('../../support/helpers/address.helper.js')
const CompanyHelper = require('../../support/helpers/company.helper.js')
const ContactHelper = require('../../support/helpers/contact.helper.js')
const DatabaseSupport = require('../../support/database.js')
const LicenceDocumentHelper = require('../../support/helpers/licence-document.helper.js')
const LicenceDocumentRolesHelper = require('../../support/helpers/licence-document-role.helper.js')
const LicenceHelper = require('../../support/helpers/licence.helper.js')
Expand All @@ -25,24 +24,24 @@ describe('Fetch Licence Contacts service', () => {
let companyId
let contactId

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

describe('when the licence has contact details', () => {
beforeEach(async () => {
const licence = await LicenceHelper.add()

licenceId = licence.id

const company = await CompanyHelper.add()

companyId = company.id

const contact = await ContactHelper.add()

contactId = contact.id

const { id: licenceDocumentId } = await LicenceDocumentHelper.add({ licenceRef: licence.licenceRef })
const { id: licenceRoleId } = await LicenceRoleHelper.add()
const { id: addressId } = await AddressHelper.add()

await LicenceDocumentRolesHelper.add({
endDate: null,
licenceDocumentId,
Expand Down
22 changes: 9 additions & 13 deletions test/services/licences/fetch-licence-returns.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@ 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')
const LicenceHelper = require('../../support/helpers/licence.helper.js')
const ReturnLogHelper = require('../../support/helpers/return-log.helper.js')
const { generateUUID } = require('../../../app/lib/general.lib.js')

// Thing under test
const FetchLicenceReturnsService = require('../../../app/services/licences/fetch-licence-returns.service')
const FetchLicenceReturnsService = require('../../../app/services/licences/fetch-licence-returns.service.js')

describe('Fetch licence returns service', () => {
const licenceId = 'fef693fd-eb6f-478d-9f79-ab24749c5dc6'

beforeEach(async () => {
await DatabaseSupport.clean()
})
let licenceId

describe('when the licence has return logs', () => {
const dueDate = new Date('2020-04-01')
const endDate = new Date('2020-06-01')
const startDate = new Date('2020-02-01')
const latestDueDate = new Date('2020-05-01')
const firstReturn = {
id: '5fef371e-d0b5-4fd5-a7ff-a67d04b3f451',
id: generateUUID(),
dueDate,
endDate,
metadata: '323',
Expand All @@ -39,15 +35,15 @@ describe('Fetch licence returns service', () => {

const latestReturn = {
...firstReturn,
id: 'b80f87a3-a274-4232-b536-750670d79928',
id: generateUUID(),
returnReference: '123',
dueDate: latestDueDate
}

beforeEach(async () => {
const license = await LicenceHelper.add({
id: licenceId
})
const license = await LicenceHelper.add()

licenceId = license.id

firstReturn.licenceRef = license.licenceRef
latestReturn.licenceRef = license.licenceRef
Expand Down
Loading
Loading