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 DatabaseSupport.clean() from unit tests #1327

Merged
merged 85 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
b453e88
Remove `DatabaseSupport.clean()` from unit tests
Jozzey Sep 12, 2024
8f5a353
Fix typos
Jozzey Sep 12, 2024
e4614a9
Remove clean from `create-bill-run.request.test.js`
Jozzey Sep 12, 2024
56f0a41
remove .only
Jozzey Sep 12, 2024
3f497e3
Remove clean from `fetch-billing-account.service.test.js`
Jozzey Sep 12, 2024
f516fae
Remove clean from `calculate-authorised-and-billable-days.service.tes…
Jozzey Sep 12, 2024
ef61387
Remove clean from `cancel-bill-run.service.test.js`
Jozzey Sep 12, 2024
df03771
Remove clean from `check-busy-bill-runs.service.test.js`
Jozzey Sep 12, 2024
97daaf6
Remove clean from `create-bill-run-event.service.test.js`
Jozzey Sep 12, 2024
496d33e
remove .only
Jozzey Sep 12, 2024
436f49c
Remove clean from `create-bill-run.service.test.js`
Jozzey Sep 12, 2024
ca20aa9
Remove clean from `fetch-bill-run.service.test.js`
Jozzey Sep 12, 2024
10ea9d7
Fix test
Jozzey Sep 12, 2024
96d5b36
Remove clean from `fetch-bill-runs.service.test.js`
Jozzey Sep 12, 2024
fdddcdc
Remove clean from `fetch-matching-bill-run.service.test.js`
Jozzey Sep 12, 2024
191bc88
Remove clean from `generate-transactions.service.test.js`
Jozzey Sep 12, 2024
fe25e7c
Remove clean from `initiate-bill-run.service.test.js`
Jozzey Sep 12, 2024
4c26306
Merge branch 'main' into remove-db-clean
Jozzey Sep 12, 2024
55f4a32
Remove clean from `send-bill-run.service.test.js`
Jozzey Sep 12, 2024
35c8a0a
Remove clean from `submit-cancel-bill-run.service.test.js`
Jozzey Sep 12, 2024
dbeb0ba
Remove clean from `submit-send-bill-run.service.test.js`
Jozzey Sep 13, 2024
1f7c798
Remove .only :roll_eyes:
Jozzey Sep 13, 2024
72fee59
Merge branch 'main' into remove-db-clean
Jozzey Sep 13, 2024
9e26f57
Remove clean from `process-billing-period.service.test.js`
Jozzey Sep 13, 2024
3e9e96e
Fix typo
Jozzey Sep 13, 2024
768e372
Fix test that was failing intermittently
Jozzey Sep 13, 2024
6575b87
Fix tests that were failing intermittently
Jozzey Sep 13, 2024
0997cc0
Remove clean from `fetch-bills-to-be-reissued.service.test.js`
Jozzey Sep 13, 2024
02fc0e2
.only again!
Jozzey Sep 13, 2024
64702d6
Merge branch 'main' into remove-db-clean
Jozzey Sep 13, 2024
31177a1
Fix test so `billRuns` doesn't need to be cleared
Jozzey Sep 13, 2024
230b4fe
Fix tests so `billRuns` doesn't need to be cleared
Jozzey Sep 13, 2024
0c07185
Fix tests so `billRuns` doesn't need to be cleared
Jozzey Sep 13, 2024
b8a891f
Merge branch 'main' into remove-db-clean
Jozzey Sep 16, 2024
823081c
Remove clean from `reissue-bill.service.test.js`
Jozzey Sep 16, 2024
91a7800
Remove clean from `reissue-bills.service.test.js`
Jozzey Sep 16, 2024
1aeb139
Remove clean from `unflag-billed-licences.service.test.js`
Jozzey Sep 16, 2024
e7f6bf2
Add actual random region ids to licence helper
Jozzey Sep 16, 2024
2398fe5
Remove clean from `determine-financial-year-end.service.test.js`
Jozzey Sep 16, 2024
8aaaaff
Remove clean from `fetch-previous-transactions.service.test.js`
Jozzey Sep 17, 2024
4633a7f
Merge branch 'main' into remove-db-clean
Jozzey Sep 17, 2024
92e652b
Remove clean from `process-bill-run.service.test.js`
Jozzey Sep 17, 2024
e019de4
another .only
Jozzey Sep 17, 2024
85711ed
Remove clean from `unflag-unbilled-licences.service.test.js`
Jozzey Sep 17, 2024
6ecaab5
Remove clean from `calculate-charge.service.test.js`
Jozzey Sep 17, 2024
20b67e6
Remove clean from `fetch-authorised-volume.service.test.js`
Jozzey Sep 17, 2024
0c1e69a
Remove clean from `fetch-match-details.service.test.js`
Jozzey Sep 17, 2024
aac777e
Remove clean from `fetch-return-logs-for-licence.service.test.js`
Jozzey Sep 17, 2024
f38ce0a
Remove clean from `fetch-review-charge-reference.service.test.js`
Jozzey Sep 17, 2024
a65ba33
Remove clean from `fetch-review-licence-results.service.test.js`
Jozzey Sep 17, 2024
fedc65b
Remove clean from `persist-allocated-licence-to-results.service.test.js`
Jozzey Sep 17, 2024
3faccbb
Remove clean from `process-bill-run.service.test.js`
Jozzey Sep 17, 2024
594725c
Remove clean from `remove-bill-run-licence.service.test.js`
Jozzey Sep 17, 2024
2ffb822
Remove clean from `remove-review-data.service.test.js`
Jozzey Sep 17, 2024
3340093
Remove clean from `submit-amended-adjustment-factor.service.test.js`
Jozzey Sep 17, 2024
ddbef62
Merge remote-tracking branch 'origin/main' into remove-db-clean
Jozzey Sep 18, 2024
49dc540
Merge branch 'main' into remove-db-clean
Jozzey Sep 19, 2024
882ab0d
Remove clean from `process-licence-updates.service.test.js`
Jozzey Sep 19, 2024
322f4a5
Remove clean from `fetch-time-limited-licences.service.test.js`
Jozzey Sep 19, 2024
90e1295
Merge branch 'main' into remove-db-clean
Jozzey Sep 19, 2024
f474d1d
Remove clean from `change-address.service.test.js` :weary:
Jozzey Sep 20, 2024
89932b4
Merge branch 'main' into remove-db-clean
Jozzey Sep 20, 2024
464f4fb
Merge branch 'main' into remove-db-clean
Jozzey Sep 23, 2024
8948cc0
Add new Bill Run region to region helper
Jozzey Sep 23, 2024
a0b8bce
Use new Bill Run region in `fetch-live-bill-runs.service.test.js`
Jozzey Sep 23, 2024
bd76be1
Fix intermittent failures in `DetermineExistingBillRunYearsService` u…
Jozzey Sep 23, 2024
e0ba723
Fix intermittent failures in `FetchBillsToBeReissuedService` unit tests
Jozzey Sep 23, 2024
6531b15
Fix issue in `ViewLicenceSetUpService` unit test
Jozzey Sep 23, 2024
21098b4
Merge branch 'main' into remove-db-clean
Jozzey Sep 24, 2024
aca0e54
Fix intermittent failures in `fetch-bill-runs.service.test.js` tests
Jozzey Sep 24, 2024
3194798
Merge branch 'main' into remove-db-clean
Jozzey Sep 24, 2024
044eeb9
Update `LicenceVersionHelper` to make the `externalId` a bit more random
Jozzey Sep 24, 2024
24fc553
Fix intermittent test failures in `fetch-charge-versions.service.test…
Jozzey Sep 24, 2024
7978bb7
Merge branch 'main' into remove-db-clean
Jozzey Sep 25, 2024
7329b25
Merge branch 'main' into remove-db-clean
Jozzey Sep 25, 2024
f510c54
Fix intermittent failures in `fetch-billing-accounts.service.test.js`
Jozzey Sep 25, 2024
b75c41f
Merge branch 'main' into remove-db-clean
Jozzey Sep 25, 2024
c0d20f4
Fix intermittent failures in `fetch-licence-supplementary-years.servi…
Jozzey Sep 25, 2024
1d120ef
Tidy up `fetch-live-bill-runs.service.test.js`
Jozzey Sep 25, 2024
1971544
Tidy up `fetch-charge-versions.service.test.js`
Jozzey Sep 25, 2024
21442fc
Sort out region helper in test as per review comment
Jozzey Sep 26, 2024
86fd131
Merge branch 'main' into remove-db-clean
Jozzey Sep 26, 2024
8469191
Merge branch 'main' into remove-db-clean
Jozzey Sep 26, 2024
428fbb5
Merge branch 'main' into remove-db-clean
Jozzey Sep 26, 2024
4018512
Fix intermittent failure in `licence-version-purpose.model.test.js`
Jozzey Sep 26, 2024
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
9 changes: 3 additions & 6 deletions app/services/bill-runs/reissue/reissue-bills.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ const TransactionModel = require('../../../models/transaction.model.js')
*
* @param {module:BillRunModel} reissueBillRun - The bill run that the reissued bills will be created on
*
* @returns {boolean} `true` if any bills were reissued; `false` if not
*/

* @returns {Promise<boolean>} `true` if any bills were reissued; `false` if not
*/
async function go (reissueBillRun) {
const sourceBills = await FetchBillsToBeReissuedService.go(reissueBillRun.regionId)

Expand All @@ -49,9 +48,7 @@ async function go (reissueBillRun) {
return true
}

/**
* Adds the data held in each key of `newData` to the corresponding keys in `dataToPersist`
*/
// Adds the data held in each key of `newData` to the corresponding keys in `dataToPersist`
function _addNewDataToDataToPersist (dataToPersist, newData) {
dataToPersist.bills.push(...newData.bills)
dataToPersist.billLicences.push(...newData.billLicences)
Expand Down
3 changes: 1 addition & 2 deletions app/services/licences/view-licence-set-up.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ async function go (licenceId, auth) {
const workflows = await FetchWorkflowsService.go(licenceId)
const returnVersions = await FetchReturnVersionsService.go(licenceId)

const licenceSetUpData = SetUpPresenter
.go(chargeVersions, workflows, agreements, returnVersions, auth, commonData)
const licenceSetUpData = SetUpPresenter.go(chargeVersions, workflows, agreements, returnVersions, auth, commonData)

return {
activeTab: 'set-up',
Expand Down
4 changes: 2 additions & 2 deletions db/seeds/01-regions.seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ async function _exists (region) {
}

async function _insert (region) {
// The Test region is only intended to be seeded in our non-production environments
if (region.name === 'Test' && ServerConfig.environment === 'production') {
// The Bill Run & Test regions are only intended to be seeded in our non-production environments
if ((region.name === 'Bill Run' || region.name === 'Test') && ServerConfig.environment === 'production') {
return
}

Expand Down
4 changes: 2 additions & 2 deletions db/seeds/13-charge-categories.seed.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const { timestampForPostgres } = require('../../app/lib/general.lib.js')
const { data: chargeCategories } = require('./data/charge-categories.js')
const ChargeCategoryModel = require('../../app/models/charge-category.model.js')
const { data: chargeCategories } = require('./data/charge-categories.js')
const { timestampForPostgres } = require('../../app/lib/general.lib.js')

async function seed () {
for (const chargeCategory of chargeCategories) {
Expand Down
7 changes: 7 additions & 0 deletions db/seeds/data/regions.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ const data = [
naldRegionId: 9,
name: 'Test',
displayName: 'Test Region'
},
{
id: 'c502e4ca-9ae9-469d-8180-9f347d8e2bfd',
chargeRegionId: 'S',
naldRegionId: 10,
name: 'Bill Run',
displayName: 'Bill Run Testing Region'
}
]

Expand Down
3 changes: 0 additions & 3 deletions test/requests/charging-module/create-bill-run.request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 RegionHelper = require('../../support/helpers/region.helper.js')

// Things we need to stub
Expand All @@ -22,8 +21,6 @@ describe('Charging Module Create Bill Run request', () => {
let testRegion

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

testRegion = RegionHelper.select()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Fetch Billing Accounts service', () => {
minimumChargeChangeReason = ChangeReasonHelper.select(CHANGE_REASON_NEW_LICENCE_PART_INDEX)
})

describe('when there are no billing accounts that should be considered for the annual bill run', () => {
describe('when the billing account should NOT be considered for the annual bill run', () => {
before(() => {
region = RegionHelper.select(REGION_MIDLANDS_INDEX)
})
Expand All @@ -59,10 +59,14 @@ describe('Fetch Billing Accounts service', () => {
})
})

it('returns empty results', async () => {
it('does not return the billing account', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

expect(results).to.be.empty()
const hasBillingAccountId = results.some((result) => {
return result.id === billingAccount.id
})

expect(hasBillingAccountId).to.be.false()
})
})

Expand All @@ -75,10 +79,14 @@ describe('Fetch Billing Accounts service', () => {
})
})

it('returns empty results', async () => {
it('does not return the billing account', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

expect(results).to.be.empty()
const hasBillingAccountId = results.some((result) => {
return result.id === billingAccount.id
})

expect(hasBillingAccountId).to.be.false()
})
})

Expand All @@ -94,10 +102,14 @@ describe('Fetch Billing Accounts service', () => {
})
})

it('returns empty results', async () => {
it('does not return the billing account', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

expect(results).to.be.empty()
const hasBillingAccountId = results.some((result) => {
return result.id === billingAccount.id
})

expect(hasBillingAccountId).to.be.false()
})
})

Expand All @@ -113,10 +125,14 @@ describe('Fetch Billing Accounts service', () => {
})
})

it('returns empty results', async () => {
it('does not return the billing account', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

expect(results).to.be.empty()
const hasBillingAccountId = results.some((result) => {
return result.id === billingAccount.id
})

expect(hasBillingAccountId).to.be.false()
})
})

Expand All @@ -128,10 +144,14 @@ describe('Fetch Billing Accounts service', () => {
await ChargeVersionHelper.add({ billingAccountId: billingAccount.id, licenceId })
})

it('returns empty results', async () => {
it('does not return the billing account', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

expect(results).to.be.empty()
const hasBillingAccountId = results.some((result) => {
return result.id === billingAccount.id
})

expect(hasBillingAccountId).to.be.false()
})
})

Expand All @@ -143,10 +163,14 @@ describe('Fetch Billing Accounts service', () => {
await ChargeVersionHelper.add({ billingAccountId: billingAccount.id, licenceId })
})

it('returns empty results', async () => {
it('does not return the billing account', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

expect(results).to.be.empty()
const hasBillingAccountId = results.some((result) => {
return result.id === billingAccount.id
})

expect(hasBillingAccountId).to.be.false()
})
})

Expand All @@ -156,10 +180,14 @@ describe('Fetch Billing Accounts service', () => {
await WorkflowHelper.add({ licenceId: licence.id })
})

it('returns empty results', async () => {
it('does not return the billing account', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

expect(results).to.be.empty()
const hasBillingAccountId = results.some((result) => {
return result.id === billingAccount.id
})

expect(hasBillingAccountId).to.be.false()
})
})
})
Expand Down Expand Up @@ -192,21 +220,26 @@ describe('Fetch Billing Accounts service', () => {
chargeElement = await ChargeElementHelper.add({ chargeReferenceId: chargeReference.id })
})

it('returns the applicable billing accounts', async () => {
it('returns the applicable billing account', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

expect(results).to.have.length(1)
const billingAccountRecord = results.find((result) => {
return result.id === billingAccount.id
})

expect(results[0]).to.be.instanceOf(BillingAccountModel)
expect(results[0].id).to.equal(billingAccount.id)
expect(results[0].accountNumber).to.equal(billingAccount.accountNumber)
expect(billingAccountRecord).to.be.instanceOf(BillingAccountModel)
expect(billingAccountRecord.accountNumber).to.equal(billingAccount.accountNumber)
})

describe('that have applicable related charge versions', () => {
it('includes the charge versions in each result', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

const { chargeVersions } = results[0]
const billingAccountRecord = results.find((result) => {
return result.id === billingAccount.id
})

const { chargeVersions } = billingAccountRecord

expect(chargeVersions[0].id).to.equal(chargeVersion.id)
expect(chargeVersions[0].scheme).to.equal('sroc')
Expand All @@ -219,7 +252,11 @@ describe('Fetch Billing Accounts service', () => {
it('includes the licence and region in each result', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

const { licence } = results[0].chargeVersions[0]
const billingAccountRecord = results.find((result) => {
return result.id === billingAccount.id
})

const { licence } = billingAccountRecord.chargeVersions[0]

expect(licence.id).to.equal(licence.id)
expect(licence.licenceRef).to.equal(licence.licenceRef)
Expand All @@ -233,7 +270,11 @@ describe('Fetch Billing Accounts service', () => {
it('includes the change reason in each result', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

const { changeReason } = results[0].chargeVersions[0]
const billingAccountRecord = results.find((result) => {
return result.id === billingAccount.id
})

const { changeReason } = billingAccountRecord.chargeVersions[0]

expect(changeReason.id).to.equal(changeReason.id)
expect(changeReason.triggersMinimumCharge).to.equal(changeReason.triggersMinimumCharge)
Expand All @@ -242,7 +283,11 @@ describe('Fetch Billing Accounts service', () => {
it('includes the charge references, charge category and charge elements in each result', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

const { chargeReferences } = results[0].chargeVersions[0]
const billingAccountRecord = results.find((result) => {
return result.id === billingAccount.id
})

const { chargeReferences } = billingAccountRecord.chargeVersions[0]

expect(chargeReferences).to.have.length(1)

Expand Down Expand Up @@ -288,7 +333,11 @@ describe('Fetch Billing Accounts service', () => {
it('excludes the charge versions in each result', async () => {
const results = await FetchBillingAccountsService.go(region.id, billingPeriod)

const { chargeVersions } = results[0]
const billingAccountRecord = results.find((result) => {
return result.id === billingAccount.id
})

const { chargeVersions } = billingAccountRecord

expect(chargeVersions.length).to.equal(1)
expect(chargeVersions[0].id).to.equal(chargeVersion.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { generateUUID } = require('../../../../app/lib/general.lib.js')
const { determineCurrentFinancialYear } = require('../../../../app/lib/general.lib.js')

Expand All @@ -25,18 +24,16 @@ const ProcessBillingPeriodService = require('../../../../app/services/bill-runs/

describe('Annual Process billing period service', () => {
const billingPeriod = determineCurrentFinancialYear()
const billRun = {
id: '8e0d4c8b-e9fe-4238-8f3e-dfca743316ef',
externalId: 'f6e052f5-37f9-43f3-a649-ff6398cec1a3'
}

let billingAccount
let billRun
let chargingModuleCreateTransactionRequestStub

beforeEach(async () => {
// NOTE: Although we don't rely on the helpers to create the data we pass into the service it does persist the
// results. If we don't clean the DB it causes the tests to fail because of unique constraints on the legacy tables.
await DatabaseSupport.clean()
billRun = {
id: generateUUID(),
externalId: generateUUID()
}

chargingModuleCreateTransactionRequestStub = Sinon.stub(ChargingModuleCreateTransactionRequest, 'send')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { expect } = Code
// Test helpers
const ChargeReferenceHelper = require('../../support/helpers/charge-reference.helper.js')
const ChargeElementHelper = require('../../support/helpers/charge-element.helper.js')
const DatabaseSupport = require('../../support/database.js')

// Thing under test
const CalculateAuthorisedAndBillableDaysService = require('../../../app/services/bill-runs/calculate-authorised-and-billable-days.service.js')
Expand All @@ -33,8 +32,6 @@ describe('Calculate Authorised and Billable days service', () => {
let chargeReference

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

chargeReference = await ChargeReferenceHelper.add()
})

Expand Down
3 changes: 0 additions & 3 deletions test/services/bill-runs/cancel-bill-run.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { expect } = Code

// Test helpers
const BillRunHelper = require('../../support/helpers/bill-run.helper.js')
const DatabaseSupport = require('../../support/database.js')
const RegionHelper = require('../../support/helpers/region.helper.js')

// Thing under test
Expand All @@ -20,8 +19,6 @@ describe('Cancel Bill Run service', () => {
let testBillRunId

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

region = RegionHelper.select()
const billRun = await BillRunHelper.add({
billRunNumber: 10101,
Expand Down
Loading
Loading