Skip to content

Commit

Permalink
Fix failing unit tests (#1445)
Browse files Browse the repository at this point in the history
This change fixes some unit tests that were failing in CI.

Some changes to return cycles introduced an intermittent fail. We tracked it down to the order of the results causing an issue. If we set the order on the query we use we remove the intermittent fail.

But, because they were failing someone who should have known (👉 @Cruikshanks 😳 ) better slammed in a change and didn't spot that some of the fails were their own.

So, fixes for those failing tests are included in this change as well.
  • Loading branch information
robertparkinson authored Oct 25, 2024
1 parent 5045158 commit ad5868a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 61 deletions.
4 changes: 2 additions & 2 deletions test/presenters/bills/remove-bill.presenter.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 BillingAccountHelper = require('../../../app/models/billing-account.model.js')
const BillingAccountModel = require('../../../app/models/billing-account.model.js')

// Thing under test
const RemoveBillPresenter = require('../../../app/presenters/bills/remove-bill.presenter.js')
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('Remove Bill presenter', () => {
})

function _billSummary () {
const billingAccount = BillingAccountHelper.fromJson({
const billingAccount = BillingAccountModel.fromJson({
id: 'e2b35a4a-7368-425f-9990-faa23efc0a25',
accountNumber: 'T65757520A',
company: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const Sinon = require('sinon')
const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script()
const { expect } = Code

// Test helpers
const BillingAccountModel = require('../../../../app/models/billing-account.model.js')

// Things we need to stub
const FetchReviewLicenceResultsService = require('../../../../app/services/bill-runs/two-part-tariff/fetch-review-licence-results.service.js')

Expand Down Expand Up @@ -51,6 +54,40 @@ describe('Review Licence Service', () => {
})

function _fetchReviewLicenceResults () {
const billingAccountDetails = BillingAccountModel.fromJson({
id: 'a17ae69b-8074-4d27-80bf-074f4c79a05a',
accountNumber: 'E88896464A',
company: {
id: 'e44491db-2b33-4473-9c3a-b57aceabb6e8',
name: 'Furland Farm',
type: 'organisation'
},
billingAccountAddresses: [
{
id: 'eb5cb54a-0b51-4e4a-8472-dab993eb6157',
billingAccountId: 'a17ae69b-8074-4d27-80bf-074f4c79a05a',
addressId: 'cc32fefd-7f3e-4581-b437-78a3fae66d4b',
startDate: new Date('2016-05-20'),
endDate: null,
companyId: null,
contactId: null,
company: null,
contact: null,
address: {
id: 'cc32fefd-7f3e-4581-b437-78a3fae66d4b',
address1: 'Furland Farm',
address2: 'Furland',
address3: null,
address4: null,
address5: 'Crewkerne',
address6: 'Somerset',
postcode: 'TA18 7TT',
country: 'England'
}
}
]
})

return {
billRun: {
id: '6620135b-0ecf-4fd4-924e-371f950c0526',
Expand Down Expand Up @@ -204,39 +241,7 @@ function _fetchReviewLicenceResults () {
chargeVersion: {
billingAccountId: '67d7cacb-5d10-4a08-b7f8-e6ce98cbf4c8'
},
billingAccountDetails: {
id: 'a17ae69b-8074-4d27-80bf-074f4c79a05a',
accountNumber: 'E88896464A',
company: {
id: 'e44491db-2b33-4473-9c3a-b57aceabb6e8',
name: 'Furland Farm',
type: 'organisation'
},
billingAccountAddresses: [
{
id: 'eb5cb54a-0b51-4e4a-8472-dab993eb6157',
billingAccountId: 'a17ae69b-8074-4d27-80bf-074f4c79a05a',
addressId: 'cc32fefd-7f3e-4581-b437-78a3fae66d4b',
startDate: new Date('2016-05-20'),
endDate: null,
companyId: null,
contactId: null,
company: null,
contact: null,
address: {
id: 'cc32fefd-7f3e-4581-b437-78a3fae66d4b',
address1: 'Furland Farm',
address2: 'Furland',
address3: null,
address4: null,
address5: 'Crewkerne',
address6: 'Somerset',
postcode: 'TA18 7TT',
country: 'England'
}
}
]
}
billingAccountDetails
}]
}]
}
Expand Down
55 changes: 30 additions & 25 deletions test/services/bills/remove-bill.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const Sinon = require('sinon')
const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script()
const { expect } = Code

// Test helpers
const BillingAccountModel = require('../../../app/models/billing-account.model.js')

// Things we need to stub
const FetchBillSummaryService = require('../../../app/services/bills/fetch-bill-summary.service.js')

Expand Down Expand Up @@ -51,34 +54,36 @@ describe('Remove Bill service', () => {
})

function _billSummary () {
const billingAccount = BillingAccountModel.fromJson({
id: 'e2b35a4a-7368-425f-9990-faa23efc0a25',
accountNumber: 'T65757520A',
company: {
id: '3b60ddd0-654f-4012-a349-000aab3e49c3',
name: 'Example Trading Ltd',
type: 'organisation'
},
billingAccountAddresses: [{
id: '1d440029-745a-47ec-a43e-9f4a36014126',
company: null,
contact: {
id: '95ba53be-543f-415b-90b1-08f58f63ff74',
contactType: 'person',
dataSource: 'wrls',
department: null,
firstName: 'Amara',
initials: null,
lastName: 'Gupta',
middleInitials: null,
salutation: null,
suffix: null
}
}]
})

return {
id: '71d03336-f683-42fe-b67c-c861f25f1fbd',
netAmount: 1045,
billingAccount: {
id: 'e2b35a4a-7368-425f-9990-faa23efc0a25',
accountNumber: 'T65757520A',
company: {
id: '3b60ddd0-654f-4012-a349-000aab3e49c3',
name: 'Example Trading Ltd',
type: 'organisation'
},
billingAccountAddresses: [{
id: '1d440029-745a-47ec-a43e-9f4a36014126',
company: null,
contact: {
id: '95ba53be-543f-415b-90b1-08f58f63ff74',
contactType: 'person',
dataSource: 'wrls',
department: null,
firstName: 'Amara',
initials: null,
lastName: 'Gupta',
middleInitials: null,
salutation: null,
suffix: null
}
}]
},
billingAccount,
billLicences: [
{
id: '9304f6b8-0664-4fec-98e1-8fd16144315c',
Expand Down
2 changes: 1 addition & 1 deletion test/support/helpers/return-cycle.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function defaults (data = {}) {
* @returns {object} The selected reference entry or one picked at random
*/
async function select (index = -1, summer = false) {
const returnCycles = await ReturnCycleModel.query().where('summer', summer)
const returnCycles = await ReturnCycleModel.query().where('summer', summer).orderBy('startDate', 'DESC')

if (index > -1) {
return returnCycles[index]
Expand Down

0 comments on commit ad5868a

Please sign in to comment.