From f849a6576c9710c0cf0f0aefe73268c3b193fa97 Mon Sep 17 00:00:00 2001 From: jonathangoulding Date: Fri, 9 Aug 2024 09:46:54 +0100 Subject: [PATCH] Fix all remaining lint issues As part of ongoing automation for our code practices and preferences we introduced eslint instead of the DEFRA standard linter standard.js. Our eslint setup uses standard.js as the base linter but we have our own rules on top. We have previously introduced a gradual adoption of eslint by using the git diff when running eslint. This appears to have some limitation with some rules not getting picked up. At this point it makes sense to fix the remaining lint issues and remove the git diff and lint the whole codebase. When we first moved over to eslint there were 1000+ issues now we only have 137 issues (with the majority being able to be fixed with --fix). This change fixes all outstanding linting issues and remove the previous lint with git diff lint to the basic eslint run. --- app/lib/legacy-db-snake-case-mappers.lib.js | 2 +- app/presenters/paginator.presenter.js | 1 + app/requests/charging-module/token.request.js | 1 + .../annual/process-billing-period.service.js | 2 ++ .../determine-billing-periods.service.js | 1 + .../generate-transactions.service.js | 1 + .../submit-cancel-bill-run.service.js | 1 + .../process-billing-period.service.js | 1 + .../fetch-bill-run-licences.service.js | 8 ++++++-- ...st-allocated-licence-to-results.service.js | 2 ++ .../change-address.service.js | 1 + .../deduplicate/submit-deduplicate.service.js | 1 + .../health/fetch-import-jobs.service.js | 1 + .../fetch-user-roles-and-groups.service.js | 2 ++ .../export/write-table-to-file.service.js | 2 ++ .../fetch-licence-updates.service.js | 1 + .../fetch-time-limited-licences.service.js | 1 + .../plugins/payload-cleaning.service.js | 2 ++ .../return-requirements/add.service.js | 1 + .../check-licence-ended.service.js | 1 + .../fetch-points.service.js | 1 + ...t-additional-submission-options.service.js | 1 + .../submit-note.service.js | 1 + db/db.js | 2 +- index.js | 2 +- knexfile.application.js | 2 +- package.json | 3 +-- test/lib/base-notifier.lib.test.js | 19 +++++++++++++++++++ test/lib/request-notifier.lib.test.js | 10 ++++++++++ .../process-billing-period.service.test.js | 1 + ...thorised-and-billable-days.service.test.js | 7 +++++++ .../consolidate-date-ranges.service.test.js | 2 +- .../determine-minimum-charge.service.test.js | 3 +++ .../generate-transactions.service.test.js | 1 + ...fetch-bills-to-be-reissued.service.test.js | 2 ++ .../reissue/reissue-bill.service.test.js | 1 + .../bill-runs/setup/exists.service.test.js | 1 + .../start-bill-run-process.service.test.js | 3 +++ .../submit-cancel-bill-run.service.test.js | 2 ++ .../submit-send-bill-run.service.test.js | 2 ++ ...etch-previous-transactions.service.test.js | 1 + .../pre-generate-billing-data.service.test.js | 4 ++++ .../unflag-billed-licences.service.test.js | 1 + .../unflag-unbilled-licences.service.test.js | 1 + .../calculate-charge.service.test.js | 3 +++ ...located-licence-to-results.service.test.js | 1 + .../prepare-return-logs.service.test.js | 2 ++ .../remove-review-data.service.test.js | 5 +++++ ...-amended-adjustment-factor.service.test.js | 18 ++++++++++++------ .../bill-runs/view-bill-run.service.test.js | 1 + .../change-address.service.test.js | 2 ++ .../fetch-billing-account.service.test.js | 2 ++ test/services/health/info.service.test.js | 6 ++++++ .../jobs/export/delete-files.service.test.js | 4 ++++ .../export/fetch-table-names.service.test.js | 2 +- .../export/send-to-s3-bucket.service.test.js | 1 + .../write-table-to-file.service.test.js | 1 + .../fetch-licence-updates.service.test.js | 2 ++ .../plugins/filter-routes.service.test.js | 1 + .../plugins/payload-cleaning.service.test.js | 2 ++ .../frequency-collected.service.test.js | 1 - .../frequency-reported.service.test.js | 1 - .../purpose.service.test.js | 1 - .../note.validator.test.js | 1 + .../site-description.validator.test.js | 2 +- 65 files changed, 145 insertions(+), 20 deletions(-) diff --git a/app/lib/legacy-db-snake-case-mappers.lib.js b/app/lib/legacy-db-snake-case-mappers.lib.js index 2fc601b0e3..825fc0a3c3 100644 --- a/app/lib/legacy-db-snake-case-mappers.lib.js +++ b/app/lib/legacy-db-snake-case-mappers.lib.js @@ -5,7 +5,7 @@ * @module LegacyDbSnakeCaseMappersLib */ -const { camelCase, knexIdentifierMappers, snakeCase } = require('objection/lib/utils/identifierMapping') +const { camelCase, knexIdentifierMappers, snakeCase } = require('objection/lib/utils/identifierMapping.js') /** * Return an object containing Knex postProcessResponse() and wrapIdentifier() hooks used in Db query and result parsing diff --git a/app/presenters/paginator.presenter.js b/app/presenters/paginator.presenter.js index f4be78ba1b..80e90a9cb4 100644 --- a/app/presenters/paginator.presenter.js +++ b/app/presenters/paginator.presenter.js @@ -195,6 +195,7 @@ function _items (selectedPageNumber, numberOfPages, path) { const paginatorType = _paginatorType(selectedPageNumber, numberOfPages) let items + switch (paginatorType) { case COMPLEX_START_PAGINATOR: items = _complexPaginatorStart(selectedPageNumber, numberOfPages, path) diff --git a/app/requests/charging-module/token.request.js b/app/requests/charging-module/token.request.js index 9761c22ac7..f2a8b979e1 100644 --- a/app/requests/charging-module/token.request.js +++ b/app/requests/charging-module/token.request.js @@ -50,6 +50,7 @@ function _parseResult (result) { if (result.succeeded) { const data = JSON.parse(result.response.body) + authentication.accessToken = data.access_token authentication.expiresIn = data.expires_in } diff --git a/app/services/bill-runs/annual/process-billing-period.service.js b/app/services/bill-runs/annual/process-billing-period.service.js index 1c5bc38bf2..b8cafc6b1e 100644 --- a/app/services/bill-runs/annual/process-billing-period.service.js +++ b/app/services/bill-runs/annual/process-billing-period.service.js @@ -67,6 +67,7 @@ async function go (billRun, billingPeriod, billingAccounts) { // supplementary it is extremely unlikely an annual bill run would generate no bills. But we play it safe and don't // make that assumption. const results = await Promise.all(processes) + if (!billRunIsPopulated) { billRunIsPopulated = results.some((result) => { return result @@ -142,6 +143,7 @@ function _extractBillableLicences (allBillLicences) { allBillLicences.forEach((billLicence) => { const { id, billId, licenceId, licenceRef, billable } = billLicence + if (billable) { billableBillLicences.push({ id, billId, licenceId, licenceRef }) } diff --git a/app/services/bill-runs/determine-billing-periods.service.js b/app/services/bill-runs/determine-billing-periods.service.js index 29e0debebc..02f287aa80 100644 --- a/app/services/bill-runs/determine-billing-periods.service.js +++ b/app/services/bill-runs/determine-billing-periods.service.js @@ -63,6 +63,7 @@ function _billingPeriods (billRunType, financialYear) { // It means we'll never pick a PRESROC for our billing periods. But also we are future proofed should we still be // here in 2029! const earliestSrocFinYearEnd = Math.max(SROC_FIRST_FIN_YEAR_END, (years.endYear - NO_OF_YEARS_TO_LOOK_BACK)) + while (earliestSrocFinYearEnd <= years.endYear) { _addBillingPeriod(billingPeriods, years.startYear, years.endYear) diff --git a/app/services/bill-runs/generate-transactions.service.js b/app/services/bill-runs/generate-transactions.service.js index 28285c1122..acfff2a875 100644 --- a/app/services/bill-runs/generate-transactions.service.js +++ b/app/services/bill-runs/generate-transactions.service.js @@ -60,6 +60,7 @@ function go (billLicenceId, chargeReference, billingPeriod, chargePeriod, newLic if (!waterUndertaker) { const compensationTransaction = _compensationTransaction(standardTransaction) + transactions.push(compensationTransaction) } diff --git a/app/services/bill-runs/submit-cancel-bill-run.service.js b/app/services/bill-runs/submit-cancel-bill-run.service.js index a16e38bd8a..70485e2ad3 100644 --- a/app/services/bill-runs/submit-cancel-bill-run.service.js +++ b/app/services/bill-runs/submit-cancel-bill-run.service.js @@ -42,6 +42,7 @@ async function go (billRunId) { const billRun = await _fetchBillRun(billRunId) const cannotBeDeleted = _cannotBeDeleted(billRun.status) + if (cannotBeDeleted) { return } diff --git a/app/services/bill-runs/supplementary/process-billing-period.service.js b/app/services/bill-runs/supplementary/process-billing-period.service.js index b7b148c4e7..adb3dcf412 100644 --- a/app/services/bill-runs/supplementary/process-billing-period.service.js +++ b/app/services/bill-runs/supplementary/process-billing-period.service.js @@ -119,6 +119,7 @@ function _buildBillingDataWithTransactions (chargeVersions, preGeneratedData, bi // We fetch the previous transactions for `superseded` (REPLACED) charge versions later in the process if (chargeVersion.status === 'current') { const calculatedTransactions = _generateCalculatedTransactions(billLicenceId, billingPeriod, chargeVersion) + acc[billLicenceId].calculatedTransactions.push(...calculatedTransactions) } diff --git a/app/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.js b/app/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.js index cfcac6d7a8..58d2152c20 100644 --- a/app/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.js +++ b/app/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.js @@ -46,7 +46,9 @@ async function go (id, filterIssues, filterLicenceHolderNumber, filterLicenceSta return { billRun, licences } } -function _applyFilters (reviewLicenceQuery, filterIssues, filterLicenceHolderNumber, filterLicenceStatus, filterProgress) { +function _applyFilters ( + reviewLicenceQuery, filterIssues, filterLicenceHolderNumber, filterLicenceStatus, filterProgress +) { if (filterIssues) { _filterIssues(filterIssues, reviewLicenceQuery) } @@ -84,7 +86,9 @@ async function _fetchBillRun (id) { }) } -async function _fetchBillRunLicences (id, filterIssues, filterLicenceHolderNumber, filterLicenceStatus, filterProgress, page = 1) { +async function _fetchBillRunLicences ( + id, filterIssues, filterLicenceHolderNumber, filterLicenceStatus, filterProgress, page = 1 +) { const reviewLicenceQuery = ReviewLicenceModel.query() .select('licenceId', 'licenceRef', 'licenceHolder', 'issues', 'progress', 'status') .where('billRunId', id) diff --git a/app/services/bill-runs/two-part-tariff/persist-allocated-licence-to-results.service.js b/app/services/bill-runs/two-part-tariff/persist-allocated-licence-to-results.service.js index f4ac7c8b3d..2977b9bc51 100644 --- a/app/services/bill-runs/two-part-tariff/persist-allocated-licence-to-results.service.js +++ b/app/services/bill-runs/two-part-tariff/persist-allocated-licence-to-results.service.js @@ -52,6 +52,7 @@ async function go (billRunId, licence) { async function _persistChargeElement (chargeElement, reviewReturnIds, reviewChargeReferenceId) { const reviewChargeElementId = await _persistReviewChargeElement(chargeElement, reviewChargeReferenceId) + for (const returnLog of chargeElement.returnLogs) { // When we persist the review result we need the Id's for both the charge element and return log's review result // records. Though it looks like we're iterating return logs here, these are copies assigned during matching and @@ -130,6 +131,7 @@ async function _persistReturnLogs (returnLogs, reviewLicenceId) { for (const returnLog of returnLogs) { const reviewReturnId = await _persistReviewReturn(returnLog, reviewLicenceId) + reviewReturnIds.push({ returnId: returnLog.id, reviewReturnId }) } diff --git a/app/services/billing-accounts/change-address.service.js b/app/services/billing-accounts/change-address.service.js index 8294a4a270..8bcf6e1e34 100644 --- a/app/services/billing-accounts/change-address.service.js +++ b/app/services/billing-accounts/change-address.service.js @@ -154,6 +154,7 @@ async function _patchExistingBillingAccountAddressEndDate (trx, billingAccountId // `endDate` to be today - 1 (yesterday). The following works it all out even if we're over a month or year boundary // and no moment() in sight! Thanks to https://stackoverflow.com/a/1296374 for how to do this const endDate = new Date() + endDate.setDate(timestamp.getDate() - 1) await BillingAccountAddressModel.query(trx) diff --git a/app/services/data/deduplicate/submit-deduplicate.service.js b/app/services/data/deduplicate/submit-deduplicate.service.js index 4f5394de4d..35c8eaee83 100644 --- a/app/services/data/deduplicate/submit-deduplicate.service.js +++ b/app/services/data/deduplicate/submit-deduplicate.service.js @@ -35,6 +35,7 @@ async function go (payload) { } const parsedLicenceRef = licenceRef.trim().toUpperCase() + await DeDuplicateService.go(parsedLicenceRef) return { diff --git a/app/services/health/fetch-import-jobs.service.js b/app/services/health/fetch-import-jobs.service.js index a450835231..d2840b80b8 100644 --- a/app/services/health/fetch-import-jobs.service.js +++ b/app/services/health/fetch-import-jobs.service.js @@ -80,6 +80,7 @@ async function go () { */ function _subtractDaysFromCurrentDate (days) { const date = new Date() + date.setDate(date.getDate() - days) return date diff --git a/app/services/idm/fetch-user-roles-and-groups.service.js b/app/services/idm/fetch-user-roles-and-groups.service.js index 1e92b299d3..cab868e1f4 100644 --- a/app/services/idm/fetch-user-roles-and-groups.service.js +++ b/app/services/idm/fetch-user-roles-and-groups.service.js @@ -56,6 +56,7 @@ async function go (userId) { */ function _extractRolesAndGroupsFromUser (user) { const { roles, groups } = user + delete user.roles delete user.groups @@ -71,6 +72,7 @@ function _extractRolesAndGroupsFromUser (user) { function _extractRolesFromGroups (groups) { return groups.flatMap((group) => { const { roles } = group + delete group.roles return roles diff --git a/app/services/jobs/export/write-table-to-file.service.js b/app/services/jobs/export/write-table-to-file.service.js index c88c5d493c..db924cfe3b 100644 --- a/app/services/jobs/export/write-table-to-file.service.js +++ b/app/services/jobs/export/write-table-to-file.service.js @@ -29,6 +29,7 @@ async function go (headers, rows, schemaFolderPath, tableName) { const transformDataStream = _transformDataStream() const convertedHeaders = ConvertToCSVService.go(headers) + writeToFileStream.write(convertedHeaders) await promisifiedPipeline(inputStream, transformDataStream, writeToFileStream) @@ -44,6 +45,7 @@ function _transformDataStream () { objectMode: true, transform: function (row, _encoding, callback) { const datRow = ConvertToCSVService.go(Object.values(row)) + callback(null, datRow) } }) diff --git a/app/services/jobs/licence-updates/fetch-licence-updates.service.js b/app/services/jobs/licence-updates/fetch-licence-updates.service.js index 73ecc96021..cd566e9a08 100644 --- a/app/services/jobs/licence-updates/fetch-licence-updates.service.js +++ b/app/services/jobs/licence-updates/fetch-licence-updates.service.js @@ -62,6 +62,7 @@ async function go () { function _twoMonthsAgo () { const today = new Date() + today.setMonth(today.getMonth() - 2) return today diff --git a/app/services/jobs/time-limited/fetch-time-limited-licences.service.js b/app/services/jobs/time-limited/fetch-time-limited-licences.service.js index d4610b0603..b8783c33d1 100644 --- a/app/services/jobs/time-limited/fetch-time-limited-licences.service.js +++ b/app/services/jobs/time-limited/fetch-time-limited-licences.service.js @@ -57,6 +57,7 @@ async function go () { function _offSetCurrentDateByDays (days) { const date = new Date() + date.setDate(date.getDate() + days) return date diff --git a/app/services/plugins/payload-cleaning.service.js b/app/services/plugins/payload-cleaning.service.js index 06af3ab595..24918d808f 100644 --- a/app/services/plugins/payload-cleaning.service.js +++ b/app/services/plugins/payload-cleaning.service.js @@ -105,6 +105,7 @@ function _cleanObject (obj) { for (const [key, value] of Object.entries(obj)) { let result + if (typeof value === 'object') { if (Array.isArray(value)) { result = _cleanArray(value) @@ -202,6 +203,7 @@ function _keepValue (value) { function _cleanValue (value) { if (typeof value === 'string') { let cleanedValue = Sanitizer.sanitize(value) + cleanedValue = cleanedValue.trim() cleanedValue = Sanitizer.unescapeEntities(cleanedValue) diff --git a/app/services/return-requirements/add.service.js b/app/services/return-requirements/add.service.js index e3c90d715e..33573e7179 100644 --- a/app/services/return-requirements/add.service.js +++ b/app/services/return-requirements/add.service.js @@ -33,6 +33,7 @@ async function _save (session) { return session.$update() } + module.exports = { go } diff --git a/app/services/return-requirements/check-licence-ended.service.js b/app/services/return-requirements/check-licence-ended.service.js index 5110318065..6d64bc1683 100644 --- a/app/services/return-requirements/check-licence-ended.service.js +++ b/app/services/return-requirements/check-licence-ended.service.js @@ -48,6 +48,7 @@ function _licenceEnded (licence) { } const today = new Date() + today.setHours(0, 0, 0, 0) return ends.date <= today diff --git a/app/services/return-requirements/fetch-points.service.js b/app/services/return-requirements/fetch-points.service.js index 540859270e..9980393db3 100644 --- a/app/services/return-requirements/fetch-points.service.js +++ b/app/services/return-requirements/fetch-points.service.js @@ -42,6 +42,7 @@ function _abstractPointsData (result) { result.purposes.forEach((purpose) => { purpose.purposePoints.forEach((point) => { const pointDetail = point.point_detail + pointsData.push(pointDetail) }) }) diff --git a/app/services/return-requirements/submit-additional-submission-options.service.js b/app/services/return-requirements/submit-additional-submission-options.service.js index 6f90d63e3c..4db3b78f31 100644 --- a/app/services/return-requirements/submit-additional-submission-options.service.js +++ b/app/services/return-requirements/submit-additional-submission-options.service.js @@ -34,6 +34,7 @@ async function go (sessionId, payload, yar) { if (!validationResult) { const notification = _notification(session, payload) + await _save(session, payload) if (notification) { diff --git a/app/services/return-requirements/submit-note.service.js b/app/services/return-requirements/submit-note.service.js index ba2bc6d0a3..1da8cda904 100644 --- a/app/services/return-requirements/submit-note.service.js +++ b/app/services/return-requirements/submit-note.service.js @@ -32,6 +32,7 @@ async function go (sessionId, payload, user, yar) { if (!validationResult) { const notification = _notification(session, payload.note) + await _save(session, payload, user) if (notification) { diff --git a/db/db.js b/db/db.js index 3bd7c3a38e..6e323d6f32 100644 --- a/db/db.js +++ b/db/db.js @@ -2,7 +2,7 @@ const environment = process.env.NODE_ENV || 'development' -const dbConfig = require('../knexfile.application')[environment] +const dbConfig = require('../knexfile.application.js')[environment] // Where the 'pg' package has concern that parsing a DB value into its JavaScript equivalent will lead to a loss of // data it will return the value as a string. For example, a PostgreSQL BigInt has the range -9223372036854775808 to diff --git a/index.js b/index.js index 426f3e547f..9041500ceb 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ 'use strict' -const { start } = require('./app/server') +const { start } = require('./app/server.js') start() diff --git a/knexfile.application.js b/knexfile.application.js index 0e5bc7f439..74ef2e2ff3 100644 --- a/knexfile.application.js +++ b/knexfile.application.js @@ -21,7 +21,7 @@ const { legacyDbSnakeCaseMappers } = require('./app/lib/legacy-db-snake-case-map * to migrations. */ -const knexfile = require('./knexfile') +const knexfile = require('./knexfile.js') for (const environment in knexfile) { Object.assign(knexfile[environment], legacyDbSnakeCaseMappers({ underscoreBeforeDigits: true })) diff --git a/package.json b/package.json index 4ec5e324e0..112eab2e60 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,7 @@ "rollback:all": "knex migrate:rollback --all", "rollback:all:test": "NODE_ENV=test knex migrate:rollback --all", "seed": "knex seed:run --knexfile knexfile.application.js", - "lint": "eslint $(git diff --name-only --diff-filter=ACMRTUXB | grep -E \"\\.(js)$\")", - "lint:all": "eslint .", + "lint": "eslint .", "pretest": "NODE_ENV=test node db/clean.js", "test": "lab --silent-skips --shuffle", "postinstall": "npm run build", diff --git a/test/lib/base-notifier.lib.test.js b/test/lib/base-notifier.lib.test.js index 35bd51057e..90ee824ee2 100644 --- a/test/lib/base-notifier.lib.test.js +++ b/test/lib/base-notifier.lib.test.js @@ -37,6 +37,7 @@ describe('BaseNotifierLib class', () => { describe('when just a message is logged', () => { it('logs a correctly formatted "info" level entry', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omg(message) expect(pinoFake.info.calledOnceWith({}, message)).to.be.true() @@ -46,6 +47,7 @@ describe('BaseNotifierLib class', () => { describe('when a message and some data is to be logged', () => { it('logs a correctly formatted "info" level entry', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omg(message, { id }) expect(pinoFake.info.calledOnceWith({ id }, message)).to.be.true() @@ -54,6 +56,7 @@ describe('BaseNotifierLib class', () => { it('does not send a notification to "Errbit"', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omg(message) expect(airbrakeFake.notify.notCalled).to.be.true() @@ -61,6 +64,7 @@ describe('BaseNotifierLib class', () => { it('does not log an "error" message', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omg(message) expect(pinoFake.error.notCalled).to.be.true() @@ -79,6 +83,7 @@ describe('BaseNotifierLib class', () => { describe('and just a message is logged', () => { it('logs a correctly formatted "error" level entry', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message) const logPacketArgs = pinoFake.error.args[0] @@ -90,6 +95,7 @@ describe('BaseNotifierLib class', () => { it('sends the expected notification to "Errbit"', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message) const { error, session } = airbrakeFake.notify.args[0][0] @@ -103,6 +109,7 @@ describe('BaseNotifierLib class', () => { describe('and a message and some data is to be logged', () => { it('logs a correctly formatted "error" level entry', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message, { id }) const logPacketArgs = pinoFake.error.args[0] @@ -115,6 +122,7 @@ describe('BaseNotifierLib class', () => { it('sends the expected notification to "Errbit"', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message, { id }) const { error, session } = airbrakeFake.notify.args[0][0] @@ -128,6 +136,7 @@ describe('BaseNotifierLib class', () => { describe('and a message, some data and an error is to be logged', () => { it('logs a correctly formatted "error" level entry', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message, { id }, testError) const logPacketArgs = pinoFake.error.args[0] @@ -140,6 +149,7 @@ describe('BaseNotifierLib class', () => { it('sends the expected notification to "Errbit"', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message, { id }, testError) const { error, session } = airbrakeFake.notify.args[0][0] @@ -153,6 +163,7 @@ describe('BaseNotifierLib class', () => { describe('and a message, no data but an error is to be logged', () => { it('logs a correctly formatted "error" level entry', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message, null, testError) const logPacketArgs = pinoFake.error.args[0] @@ -164,6 +175,7 @@ describe('BaseNotifierLib class', () => { it('sends the expected notification to "Errbit"', () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message, null, testError) const { error, session } = airbrakeFake.notify.args[0][0] @@ -190,6 +202,7 @@ describe('BaseNotifierLib class', () => { it('logs 2 "error" messages, the second containing details of the Airbrake failure', async () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message) // We use Sinon callsFake() here in order to test our expectations. This is because Airbrake notify() actually @@ -200,11 +213,13 @@ describe('BaseNotifierLib class', () => { // when pinoFake.error is called i.e. the Airbrake.notify() promise has resolved. pinoFake.error.callsFake(async () => { const firstCallArgs = pinoFake.error.firstCall.args + expect(firstCallArgs[0].err).to.be.an.error() expect(firstCallArgs[0].err.message).to.equal(message) expect(firstCallArgs[1]).to.equal(message) const secondCallArgs = pinoFake.error.secondCall.args + expect(secondCallArgs[0]).to.be.an.error() expect(secondCallArgs[0].message).to.equal(airbrakeFailure.message) expect(secondCallArgs[1]).to.equal('BaseNotifierLib - Airbrake failed') @@ -225,15 +240,18 @@ describe('BaseNotifierLib class', () => { it('logs 2 "error" messages, the second containing details of the Airbrake errors', async () => { const testNotifier = new BaseNotifierLib() + testNotifier.omfg(message) pinoFake.error.callsFake(async () => { const firstCallArgs = pinoFake.error.firstCall.args + expect(firstCallArgs[0].err).to.be.an.error() expect(firstCallArgs[0].err.message).to.equal(message) expect(firstCallArgs[1]).to.equal(message) const secondCallArgs = pinoFake.error.secondCall.args + expect(secondCallArgs[0]).to.be.an.error() expect(secondCallArgs[0].message).to.equal(airbrakeError.message) expect(secondCallArgs[1]).to.equal('BaseNotifierLib - Airbrake errored') @@ -249,6 +267,7 @@ describe('BaseNotifierLib class', () => { it('tells the underlying Airbrake notifier to flush its queue of notifications', () => { const testNotifier = new BaseNotifierLib() + testNotifier.flush() expect(airbrakeFake.flush.called).to.be.true() diff --git a/test/lib/request-notifier.lib.test.js b/test/lib/request-notifier.lib.test.js index 86ab417de6..ce10b08e6f 100644 --- a/test/lib/request-notifier.lib.test.js +++ b/test/lib/request-notifier.lib.test.js @@ -31,6 +31,7 @@ describe('RequestNotifierLib class', () => { describe('when just a message is logged', () => { it('logs a correctly formatted "info" level entry', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omg(message) expect(pinoFake.info.calledOnceWith({ req: { id } }, message)).to.be.true() @@ -40,6 +41,7 @@ describe('RequestNotifierLib class', () => { describe('when a message and some data is to be logged', () => { it('logs a correctly formatted "info" level entry', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omg(message, { name: 'foo' }) expect(pinoFake.info.calledOnceWith({ name: 'foo', req: { id } }, message)).to.be.true() @@ -53,6 +55,7 @@ describe('RequestNotifierLib class', () => { describe('when just a message is logged', () => { it('logs a correctly formatted "error" level entry', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omfg(message) const logPacketArgs = pinoFake.error.args[0] @@ -65,6 +68,7 @@ describe('RequestNotifierLib class', () => { it('sends the expected notification to "Errbit"', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omfg(message) const { error, session } = airbrakeFake.notify.args[0][0] @@ -78,6 +82,7 @@ describe('RequestNotifierLib class', () => { describe('when a message and some data is to be logged', () => { it('logs a correctly formatted "error" level entry', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omfg(message, { name: 'foo' }) const logPacketArgs = pinoFake.error.args[0] @@ -91,6 +96,7 @@ describe('RequestNotifierLib class', () => { it('sends the expected notification to "Errbit"', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omfg(message, { name: 'foo' }) const { error, session } = airbrakeFake.notify.args[0][0] @@ -104,6 +110,7 @@ describe('RequestNotifierLib class', () => { describe('when a message, some data and an error is to be logged', () => { it('logs a correctly formatted "error" level entry', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omfg(message, { name: 'foo' }, testError) const logPacketArgs = pinoFake.error.args[0] @@ -117,6 +124,7 @@ describe('RequestNotifierLib class', () => { it('sends the expected notification to "Errbit"', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omfg(message, { name: 'foo' }, testError) const { error, session } = airbrakeFake.notify.args[0][0] @@ -130,6 +138,7 @@ describe('RequestNotifierLib class', () => { describe('when a message, no data but an error is to be logged', () => { it('logs a correctly formatted "error" level entry', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omfg(message, null, testError) const logPacketArgs = pinoFake.error.args[0] @@ -142,6 +151,7 @@ describe('RequestNotifierLib class', () => { it('sends the expected notification to "Errbit"', () => { const testNotifier = new RequestNotifierLib(id, pinoFake, airbrakeFake) + testNotifier.omfg(message, null, testError) const { error, session } = airbrakeFake.notify.args[0][0] diff --git a/test/services/bill-runs/annual/process-billing-period.service.test.js b/test/services/bill-runs/annual/process-billing-period.service.test.js index 01ae75ec06..91bbf05e27 100644 --- a/test/services/bill-runs/annual/process-billing-period.service.test.js +++ b/test/services/bill-runs/annual/process-billing-period.service.test.js @@ -87,6 +87,7 @@ describe('Annual Process billing period service', () => { // that was revoked at the start of May. The engine should calculate 0 billable days and therefore not attempt // to create a bill licence for this record. const unbillableChargeVersion = _testChargeVersion(billingAccount.id) + unbillableChargeVersion.licence.id = 'c3726e99-935e-4a36-ab2f-eef8bda9293a' unbillableChargeVersion.licence.revokedDate = new Date(billingPeriod.startDate.getFullYear(), 4, 1) unbillableChargeVersion.chargeReferences[0].chargeElements[0].abstractionPeriodStartDay = 1 diff --git a/test/services/bill-runs/calculate-authorised-and-billable-days.service.test.js b/test/services/bill-runs/calculate-authorised-and-billable-days.service.test.js index d53994dbfc..51c7f429b3 100644 --- a/test/services/bill-runs/calculate-authorised-and-billable-days.service.test.js +++ b/test/services/bill-runs/calculate-authorised-and-billable-days.service.test.js @@ -48,6 +48,7 @@ describe('Calculate Authorised and Billable days service', () => { abstractionPeriodEndDay: 31, abstractionPeriodEndMonth: 12 }) + chargeReference.chargeElements = [chargeElement] }) @@ -109,6 +110,7 @@ describe('Calculate Authorised and Billable days service', () => { abstractionPeriodEndDay: 30, abstractionPeriodEndMonth: 6 }) + chargeReference.chargeElements = [chargeElement] }) @@ -170,6 +172,7 @@ describe('Calculate Authorised and Billable days service', () => { abstractionPeriodEndDay: 31, abstractionPeriodEndMonth: 3 }) + chargeReference.chargeElements = [chargeElement] }) @@ -256,6 +259,7 @@ describe('Calculate Authorised and Billable days service', () => { abstractionPeriodEndDay: 31, abstractionPeriodEndMonth: 3 }) + chargeReference.chargeElements = [firstChargeElement, secondChargeElement] }) @@ -330,6 +334,7 @@ describe('Calculate Authorised and Billable days service', () => { abstractionPeriodEndDay: 31, abstractionPeriodEndMonth: 11 }) + chargeReference.chargeElements = [firstChargeElement, secondChargeElement] }) @@ -357,6 +362,7 @@ describe('Calculate Authorised and Billable days service', () => { abstractionPeriodEndDay: 1, abstractionPeriodEndMonth: 1 }) + chargeReference.chargeElements = [firstChargeElement, secondChargeElement] }) @@ -384,6 +390,7 @@ describe('Calculate Authorised and Billable days service', () => { abstractionPeriodEndDay: 31, abstractionPeriodEndMonth: 3 }) + chargeReference.chargeElements = [firstChargeElement, secondChargeElement] }) diff --git a/test/services/bill-runs/consolidate-date-ranges.service.test.js b/test/services/bill-runs/consolidate-date-ranges.service.test.js index e74a4ea361..9c278b6120 100644 --- a/test/services/bill-runs/consolidate-date-ranges.service.test.js +++ b/test/services/bill-runs/consolidate-date-ranges.service.test.js @@ -8,7 +8,7 @@ const { describe, it } = exports.lab = Lab.script() const { expect } = Code // Thing under test -const ConsolidateDateRangesService = require('../../../app/services/bill-runs/consolidate-date-ranges.service') +const ConsolidateDateRangesService = require('../../../app/services/bill-runs/consolidate-date-ranges.service.js') describe('ConsolidateDateRanges service', () => { describe('when the provided ranges are non-overlapping', () => { diff --git a/test/services/bill-runs/determine-minimum-charge.service.test.js b/test/services/bill-runs/determine-minimum-charge.service.test.js index fb0c8d3781..d6fcd561b0 100644 --- a/test/services/bill-runs/determine-minimum-charge.service.test.js +++ b/test/services/bill-runs/determine-minimum-charge.service.test.js @@ -30,6 +30,7 @@ describe('Determine Minimum Charge service', () => { describe('and the charge version change reason triggers a minimum charge', () => { beforeEach(async () => { const changeReason = await ChangeReasonHelper.add({ triggersMinimumCharge: true }) + chargeVersion = await ChargeVersionHelper.add({ startDate: new Date('2023-04-01'), changeReasonId: changeReason.changeReasonId @@ -48,6 +49,7 @@ describe('Determine Minimum Charge service', () => { describe('and the charge version change reason does not trigger a minimum charge', () => { beforeEach(async () => { const changeReason = await ChangeReasonHelper.add({ triggersMinimumCharge: false }) + chargeVersion = await ChargeVersionHelper.add({ startDate: new Date('2022-05-01'), changeReasonId: changeReason.changeReasonId @@ -67,6 +69,7 @@ describe('Determine Minimum Charge service', () => { describe('where the charge version start date is not the same as the charge period', () => { beforeEach(async () => { const changeReason = await ChangeReasonHelper.add({ triggersMinimumCharge: true }) + chargeVersion = await ChargeVersionHelper.add({ startDate: new Date('2022-03-01'), changeReasonId: changeReason.changeReasonId diff --git a/test/services/bill-runs/generate-transactions.service.test.js b/test/services/bill-runs/generate-transactions.service.test.js index 17c54525da..c3806e2e0f 100644 --- a/test/services/bill-runs/generate-transactions.service.test.js +++ b/test/services/bill-runs/generate-transactions.service.test.js @@ -42,6 +42,7 @@ describe('Generate Transactions service', () => { const { id: chargeCategoryId } = chargeCategory const baseChargeReference = await ChargeReferenceHelper.add({ chargeCategoryId }) + chargeElement = await ChargeElementHelper.add({ chargeReferenceId: baseChargeReference.id }) chargeReference = await baseChargeReference.$query() .withGraphFetched('chargeCategory') diff --git a/test/services/bill-runs/reissue/fetch-bills-to-be-reissued.service.test.js b/test/services/bill-runs/reissue/fetch-bills-to-be-reissued.service.test.js index 81072cdd8d..b492c67281 100644 --- a/test/services/bill-runs/reissue/fetch-bills-to-be-reissued.service.test.js +++ b/test/services/bill-runs/reissue/fetch-bills-to-be-reissued.service.test.js @@ -29,6 +29,7 @@ describe('Fetch Bills To Be Reissued service', () => { billRun = await BillRunHelper.add() bill = await BillHelper.add({ billRunId: billRun.id }) const { id: billLicenceId } = await BillLicenceHelper.add({ billId: bill.id }) + await TransactionHelper.add({ billLicenceId }) }) @@ -92,6 +93,7 @@ describe('Fetch Bills To Be Reissued service', () => { const { id: alcsBillLicenceId } = await BillLicenceHelper.add({ billId: alcsBill.id }) + await TransactionHelper.add({ billLicenceId: alcsBillLicenceId }) }) diff --git a/test/services/bill-runs/reissue/reissue-bill.service.test.js b/test/services/bill-runs/reissue/reissue-bill.service.test.js index 5de8f99e99..ad2271de30 100644 --- a/test/services/bill-runs/reissue/reissue-bill.service.test.js +++ b/test/services/bill-runs/reissue/reissue-bill.service.test.js @@ -194,6 +194,7 @@ describe('Reissue Bill service', () => { it("to the existing value if it's populated", async () => { const originalBillId = generateUUID() + await sourceBill.$query().patch({ originalBillId }) await ReissueBillService.go(sourceBill, reissueBillRun) diff --git a/test/services/bill-runs/setup/exists.service.test.js b/test/services/bill-runs/setup/exists.service.test.js index 879f59f500..50e95d22bb 100644 --- a/test/services/bill-runs/setup/exists.service.test.js +++ b/test/services/bill-runs/setup/exists.service.test.js @@ -28,6 +28,7 @@ describe('Bill Runs Setup Exists service', () => { await DatabaseSupport.clean() const { endDate } = determineCurrentFinancialYear() + currentFinancialEndYear = endDate.getFullYear() }) diff --git a/test/services/bill-runs/start-bill-run-process.service.test.js b/test/services/bill-runs/start-bill-run-process.service.test.js index 51e6f3453c..a6bcb04da2 100644 --- a/test/services/bill-runs/start-bill-run-process.service.test.js +++ b/test/services/bill-runs/start-bill-run-process.service.test.js @@ -56,6 +56,7 @@ describe('Start Bill Run Process service', () => { ...billRun, batchType } + Sinon.stub(InitiateBillRunService, 'go').resolves(annualBillRun) Sinon.stub(AnnualProcessBillRunService, 'go') @@ -98,6 +99,7 @@ describe('Start Bill Run Process service', () => { ...billRun, batchType } + Sinon.stub(InitiateBillRunService, 'go').resolves(supplementaryBillRun) Sinon.stub(SupplementaryProcessBillRunService, 'go') @@ -140,6 +142,7 @@ describe('Start Bill Run Process service', () => { ...billRun, batchType } + Sinon.stub(InitiateBillRunService, 'go').resolves(twoPartTariffBillRun) Sinon.stub(TwoPartTariffProcessBillRunService, 'go') diff --git a/test/services/bill-runs/submit-cancel-bill-run.service.test.js b/test/services/bill-runs/submit-cancel-bill-run.service.test.js index f1a09645e2..73fab70c9c 100644 --- a/test/services/bill-runs/submit-cancel-bill-run.service.test.js +++ b/test/services/bill-runs/submit-cancel-bill-run.service.test.js @@ -72,11 +72,13 @@ describe('Submit Cancel Bill Run service', () => { const { id: reviewChargeVersionId } = await ReviewChargeVersionHelper.add({ reviewLicenceId }) const { id: reviewChargeReferenceId } = await ReviewChargeReferenceHelper.add({ reviewChargeVersionId }) const { id: reviewChargeElementId } = await ReviewChargeElementHelper.add({ reviewChargeReferenceId }) + await ReviewChargeElementReturnHelper.add({ reviewChargeElementId, reviewReturnId }) await BillRunChargeVersionYearHelper.add({ billRunId }) await BillRunVolumeHelper.add({ billRunId }) const { id: billId } = await BillHelper.add({ billRunId }) const { id: billLicenceId } = await BillLicenceHelper.add({ billId }) + await TransactionHelper.add({ billLicenceId }) chargingModuleDeleteBillRunRequestStub.resolves() diff --git a/test/services/bill-runs/submit-send-bill-run.service.test.js b/test/services/bill-runs/submit-send-bill-run.service.test.js index ada6344081..2324ec8d1f 100644 --- a/test/services/bill-runs/submit-send-bill-run.service.test.js +++ b/test/services/bill-runs/submit-send-bill-run.service.test.js @@ -106,9 +106,11 @@ describe('Submit Send Bill Run service', () => { await setTimeout(delay) const refreshedFirstBill = await firstBill.$query() + expect(refreshedFirstBill.invoiceNumber).to.equal('WAI1000429') const refreshedSecondBill = await secondBill.$query() + expect(refreshedSecondBill.invoiceNumber).to.equal('WAI1000428') }) diff --git a/test/services/bill-runs/supplementary/fetch-previous-transactions.service.test.js b/test/services/bill-runs/supplementary/fetch-previous-transactions.service.test.js index a61fcc2f7f..6f717b88b1 100644 --- a/test/services/bill-runs/supplementary/fetch-previous-transactions.service.test.js +++ b/test/services/bill-runs/supplementary/fetch-previous-transactions.service.test.js @@ -45,6 +45,7 @@ describe('Fetch Previous Transactions service', () => { describe('for the same licence and billing account', () => { beforeEach(async () => { const billLicenceId = await _createBillRunAndBillAndBillLicence(billRunSetupValues) + await TransactionHelper.add({ billLicenceId, chargeCategoryCode }) }) diff --git a/test/services/bill-runs/supplementary/pre-generate-billing-data.service.test.js b/test/services/bill-runs/supplementary/pre-generate-billing-data.service.test.js index 69d96bddec..6070088371 100644 --- a/test/services/bill-runs/supplementary/pre-generate-billing-data.service.test.js +++ b/test/services/bill-runs/supplementary/pre-generate-billing-data.service.test.js @@ -60,6 +60,7 @@ describe('Pre-generate billing data service', () => { const { bills: result } = await PreGenerateBillingDataService.go(chargeVersions, billRunId, billingPeriod) const keys = Object.keys(result) + expect(keys).to.have.length(2) }) @@ -82,6 +83,7 @@ describe('Pre-generate billing data service', () => { const matchingBillingAccount = billingAccounts.find((billingAccount) => { return key === billingAccount.id }) + expect(value.accountNumber).to.equal(matchingBillingAccount.accountNumber) }) }) @@ -96,6 +98,7 @@ describe('Pre-generate billing data service', () => { ) const keys = Object.entries(result) + expect(keys).to.have.length(3) }) @@ -125,6 +128,7 @@ describe('Pre-generate billing data service', () => { const matchingLicence = licences.find((licence) => { return key === `${value.billId}-${licence.id}` }) + expect(value.licenceRef).to.equal(matchingLicence.licenceRef) }) }) diff --git a/test/services/bill-runs/supplementary/unflag-billed-licences.service.test.js b/test/services/bill-runs/supplementary/unflag-billed-licences.service.test.js index c745664878..d2efd95890 100644 --- a/test/services/bill-runs/supplementary/unflag-billed-licences.service.test.js +++ b/test/services/bill-runs/supplementary/unflag-billed-licences.service.test.js @@ -107,6 +107,7 @@ describe('Unflag Billed Licences service', () => { } const { id: billId } = await BillHelper.add({ billRunId: billRun.id }) + await BillLicenceHelper.add({ billId, licenceId: licenceInBillRunAndWorkflow.id }) await BillLicenceHelper.add({ billId, licenceId: licenceInBillRunAndFlaggedAfterBillRunCreated.id }) await BillLicenceHelper.add({ billId, licenceId: licenceInBillRun.id }) diff --git a/test/services/bill-runs/supplementary/unflag-unbilled-licences.service.test.js b/test/services/bill-runs/supplementary/unflag-unbilled-licences.service.test.js index 52f38ec998..03a370e03e 100644 --- a/test/services/bill-runs/supplementary/unflag-unbilled-licences.service.test.js +++ b/test/services/bill-runs/supplementary/unflag-unbilled-licences.service.test.js @@ -95,6 +95,7 @@ describe('Unflag unbilled licences service', () => { describe('which were billed', () => { beforeEach(async () => { const { id: billId } = await BillHelper.add({ billRunId: billRun.id }) + await BillLicenceHelper.add({ billId, licenceId: licenceBilledInBillRun.id }) }) diff --git a/test/services/bill-runs/two-part-tariff/calculate-charge.service.test.js b/test/services/bill-runs/two-part-tariff/calculate-charge.service.test.js index b0c6c84ac4..4bc56a2abf 100644 --- a/test/services/bill-runs/two-part-tariff/calculate-charge.service.test.js +++ b/test/services/bill-runs/two-part-tariff/calculate-charge.service.test.js @@ -34,9 +34,11 @@ describe('Calculate Charge service', () => { await DatabaseSupport.clean() const testLicence = await LicenceHelper.add({ waterUndertaker: true }) + licenceId = testLicence.id const testChargeCategory = await ChargeCategoryHelper.add() + chargeCategoryReference = testChargeCategory.reference const { id: chargeReferenceId } = await ChargeReferenceHelper.add({ @@ -53,6 +55,7 @@ describe('Calculate Charge service', () => { reviewChargeVersionId, chargeReferenceId }) + reviewChargeReferenceId = testReviewChargeReference.id await ReviewChargeElementHelper.add({ reviewChargeReferenceId, amendedAllocated: 25 }) diff --git a/test/services/bill-runs/two-part-tariff/persist-allocated-licence-to-results.service.test.js b/test/services/bill-runs/two-part-tariff/persist-allocated-licence-to-results.service.test.js index 4f14e4c236..e099355797 100644 --- a/test/services/bill-runs/two-part-tariff/persist-allocated-licence-to-results.service.test.js +++ b/test/services/bill-runs/two-part-tariff/persist-allocated-licence-to-results.service.test.js @@ -85,6 +85,7 @@ describe('Persist Allocated Licence to Results service', () => { // Check the charge reference persisted correctly // NOTE: As the aggregate is null on the charge reference the service returns 1 const { reviewChargeReferences } = reviewChargeVersions[0] + expect(reviewChargeReferences).to.have.length(1) expect(reviewChargeReferences[0].reviewChargeVersionId).to.equal(result[0].reviewChargeVersions[0].id) expect(reviewChargeReferences[0].chargeReferenceId).to.equal(testChargeVersions[0].chargeReferences[0].id) diff --git a/test/services/bill-runs/two-part-tariff/prepare-return-logs.service.test.js b/test/services/bill-runs/two-part-tariff/prepare-return-logs.service.test.js index 5ac32587a9..0695f8c1e7 100644 --- a/test/services/bill-runs/two-part-tariff/prepare-return-logs.service.test.js +++ b/test/services/bill-runs/two-part-tariff/prepare-return-logs.service.test.js @@ -96,6 +96,7 @@ describe('Prepare Return Logs Service', () => { describe('that have submission lines outside the abstraction period', () => { beforeEach(async () => { const returnLog = _testReturnLog() + returnLog.returnSubmissions[0].returnSubmissionLines[0].startDate = new Date('2023-04-05') Sinon.stub(FetchReturnLogsForLicenceService, 'go').resolves([returnLog]) @@ -111,6 +112,7 @@ describe('Prepare Return Logs Service', () => { describe('that is a nil return', () => { beforeEach(async () => { const returnLog = _testReturnLog() + returnLog.returnSubmissions[0].nilReturn = true Sinon.stub(FetchReturnLogsForLicenceService, 'go').resolves([returnLog]) diff --git a/test/services/bill-runs/two-part-tariff/remove-review-data.service.test.js b/test/services/bill-runs/two-part-tariff/remove-review-data.service.test.js index 802a7b6275..8dc21c12b0 100644 --- a/test/services/bill-runs/two-part-tariff/remove-review-data.service.test.js +++ b/test/services/bill-runs/two-part-tariff/remove-review-data.service.test.js @@ -43,14 +43,19 @@ describe('Remove Review Data service', () => { beforeEach(async () => { const { id: reviewLicenceId } = await ReviewLicenceHelper.add({ billRunId, licenceId }) const reviewReturn = await ReviewReturnHelper.add({ reviewLicenceId }) + reviewReturnId = reviewReturn.id const reviewChargeVersion = await ReviewChargeVersionHelper.add({ reviewLicenceId }) + reviewChargeVersionId = reviewChargeVersion.id const reviewChargeReference = await ReviewChargeReferenceHelper.add({ reviewChargeVersionId }) + reviewChargeReferenceId = reviewChargeReference.id const reviewChargeElement = await ReviewChargeElementHelper.add({ reviewChargeReferenceId }) + reviewChargeElementId = reviewChargeElement.id const reviewChargeElementReturn = await ReviewChargeElementReturnHelper.add({ reviewChargeElementId }) + reviewChargeElementReturnId = reviewChargeElementReturn.id }) diff --git a/test/services/bill-runs/two-part-tariff/submit-amended-adjustment-factor.service.test.js b/test/services/bill-runs/two-part-tariff/submit-amended-adjustment-factor.service.test.js index 86781a4445..d6959cdc64 100644 --- a/test/services/bill-runs/two-part-tariff/submit-amended-adjustment-factor.service.test.js +++ b/test/services/bill-runs/two-part-tariff/submit-amended-adjustment-factor.service.test.js @@ -134,7 +134,8 @@ describe('Submit Amended Adjustment Factor Service', () => { }) it('returns the page data for the view', async () => { - const result = await SubmitAmendedAdjustmentFactorService.go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) + const result = await SubmitAmendedAdjustmentFactorService + .go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) expect(result).to.equal({ activeNavBar: 'search', @@ -156,7 +157,8 @@ describe('Submit Amended Adjustment Factor Service', () => { }) it('returns the page data with an error for the aggregate factor input element', async () => { - const result = await SubmitAmendedAdjustmentFactorService.go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) + const result = await SubmitAmendedAdjustmentFactorService + .go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) expect(result.error).to.equal({ aggregateFactorElement: { text: 'Enter a aggregate factor' }, @@ -173,7 +175,8 @@ describe('Submit Amended Adjustment Factor Service', () => { }) it('returns the page data for the view', async () => { - const result = await SubmitAmendedAdjustmentFactorService.go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) + const result = await SubmitAmendedAdjustmentFactorService + .go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) expect(result).to.equal({ activeNavBar: 'search', @@ -195,7 +198,8 @@ describe('Submit Amended Adjustment Factor Service', () => { }) it('returns the page data with an error for the charge factor input element', async () => { - const result = await SubmitAmendedAdjustmentFactorService.go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) + const result = await SubmitAmendedAdjustmentFactorService + .go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) expect(result.error).to.equal({ aggregateFactorElement: null, @@ -210,7 +214,8 @@ describe('Submit Amended Adjustment Factor Service', () => { }) it('returns the page data for the view', async () => { - const result = await SubmitAmendedAdjustmentFactorService.go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) + const result = await SubmitAmendedAdjustmentFactorService + .go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) expect(result).to.equal({ activeNavBar: 'search', @@ -232,7 +237,8 @@ describe('Submit Amended Adjustment Factor Service', () => { }) it('returns the page data with an error for the aggregate and charge factor input element', async () => { - const result = await SubmitAmendedAdjustmentFactorService.go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) + const result = await SubmitAmendedAdjustmentFactorService + .go(billRunId, licenceId, reviewChargeReference.id, payload, yarStub) expect(result.error).to.equal({ aggregateFactorElement: { text: 'Enter a aggregate factor' }, diff --git a/test/services/bill-runs/view-bill-run.service.test.js b/test/services/bill-runs/view-bill-run.service.test.js index eba74aaa67..353150d0de 100644 --- a/test/services/bill-runs/view-bill-run.service.test.js +++ b/test/services/bill-runs/view-bill-run.service.test.js @@ -238,6 +238,7 @@ function _multipleGroupBillRun () { function _singleGroupBillRun () { const billSummaries = _billSummariesData() + delete billSummaries[1] return { diff --git a/test/services/billing-accounts/change-address.service.test.js b/test/services/billing-accounts/change-address.service.test.js index ce8f82c0ce..c13b6d9f06 100644 --- a/test/services/billing-accounts/change-address.service.test.js +++ b/test/services/billing-accounts/change-address.service.test.js @@ -98,6 +98,7 @@ describe('Change address service', () => { beforeEach(async () => { const { uprn } = address + existingAddress = await AddressHelper.add({ uprn }) }) @@ -202,6 +203,7 @@ describe('Change address service', () => { beforeEach(async () => { const { companyNumber } = agentCompany + existingCompany = await CompanyHelper.add({ companyNumber }) }) diff --git a/test/services/fetch-billing-account.service.test.js b/test/services/fetch-billing-account.service.test.js index bf91175bf4..30fc2b51cc 100644 --- a/test/services/fetch-billing-account.service.test.js +++ b/test/services/fetch-billing-account.service.test.js @@ -82,6 +82,7 @@ describe('Fetch Billing Account service', () => { beforeEach(async () => { const { id: billingAccountId } = testBillingAccount + linkedAgentCompany = await CompanyHelper.add() await BillingAccountAddressHelper.add({ billingAccountId, companyId: linkedAgentCompany.id }) @@ -106,6 +107,7 @@ describe('Fetch Billing Account service', () => { beforeEach(async () => { const { id: billingAccountId } = testBillingAccount + linkedContact = await ContactHelper.add() await BillingAccountAddressHelper.add({ billingAccountId, contactId: linkedContact.id }) diff --git a/test/services/health/info.service.test.js b/test/services/health/info.service.test.js index 80a5eeaeb0..b557c765a4 100644 --- a/test/services/health/info.service.test.js +++ b/test/services/health/info.service.test.js @@ -120,6 +120,7 @@ describe('Info service', () => { return execStub }) } + InfoService = Proxyquire('../../../app/services/health/info.service', { util: utilStub }) }) @@ -180,6 +181,7 @@ describe('Info service', () => { return execStub }) } + InfoService = Proxyquire('../../../app/services/health/info.service', { util: utilStub }) }) @@ -235,6 +237,7 @@ describe('Info service', () => { return execStub }) } + InfoService = Proxyquire('../../../app/services/health/info.service', { util: utilStub }) }) @@ -266,6 +269,7 @@ describe('Info service', () => { return execStub }) } + InfoService = Proxyquire('../../../app/services/health/info.service', { util: utilStub }) }) @@ -307,6 +311,7 @@ describe('Info service', () => { return execStub }) } + InfoService = Proxyquire('../../../app/services/health/info.service', { util: utilStub }) }) @@ -368,6 +373,7 @@ describe('Info service', () => { return execStub }) } + InfoService = Proxyquire('../../../app/services/health/info.service', { util: utilStub }) redisStub.returns({ ping: Sinon.stub().resolves(), disconnect: Sinon.stub().resolves() }) diff --git a/test/services/jobs/export/delete-files.service.test.js b/test/services/jobs/export/delete-files.service.test.js index e0c27ded28..afcf8aa755 100644 --- a/test/services/jobs/export/delete-files.service.test.js +++ b/test/services/jobs/export/delete-files.service.test.js @@ -45,6 +45,7 @@ describe('Delete Files service', () => { await DeleteFilesService.go(folderNameWithPath) const folderExists = fs.existsSync(folderNameWithPath) + expect(folderExists).to.be.false() }) @@ -52,6 +53,7 @@ describe('Delete Files service', () => { await DeleteFilesService.go(folderNameWithPath) const fileExists = fs.existsSync(filenameWithPath) + expect(fileExists).to.be.false() }) }) @@ -69,6 +71,7 @@ describe('Delete Files service', () => { await DeleteFilesService.go(filenameWithPath) const fileExists = fs.existsSync(filenameWithPath) + expect(fileExists).to.be.false() }) }) @@ -84,6 +87,7 @@ describe('Delete Files service', () => { describe('When no file name is given', () => { it('throws an error', async () => { const noFile = false + await DeleteFilesService.go(noFile) expect(notifierStub.omfg.calledWith(('Delete file service errored'))).to.be.true() diff --git a/test/services/jobs/export/fetch-table-names.service.test.js b/test/services/jobs/export/fetch-table-names.service.test.js index e287a54f12..4ef9e8dcee 100644 --- a/test/services/jobs/export/fetch-table-names.service.test.js +++ b/test/services/jobs/export/fetch-table-names.service.test.js @@ -8,7 +8,7 @@ const { describe, it } = exports.lab = Lab.script() const { expect } = Code // Thing under test -const FetchTableNamesService = require('../../../../app/services/jobs/export/fetch-table-names.service') +const FetchTableNamesService = require('../../../../app/services/jobs/export/fetch-table-names.service.js') describe('Fetch table names', () => { describe('when given a schema name', () => { diff --git a/test/services/jobs/export/send-to-s3-bucket.service.test.js b/test/services/jobs/export/send-to-s3-bucket.service.test.js index 07595c702c..c1c7a24343 100644 --- a/test/services/jobs/export/send-to-s3-bucket.service.test.js +++ b/test/services/jobs/export/send-to-s3-bucket.service.test.js @@ -37,6 +37,7 @@ describe('Send to S3 bucket service', () => { // Get the first call and test that it was called with PutObjectCommand const calledCommand = s3Stub.getCall(0).firstArg + expect(calledCommand).to.be.an.instanceof(PutObjectCommand) }) }) diff --git a/test/services/jobs/export/write-table-to-file.service.test.js b/test/services/jobs/export/write-table-to-file.service.test.js index 6f3456a23d..f2edc70cec 100644 --- a/test/services/jobs/export/write-table-to-file.service.test.js +++ b/test/services/jobs/export/write-table-to-file.service.test.js @@ -78,6 +78,7 @@ describe('Write table to file service', () => { const fileName = 'billing_charge_categories.csv' const __dirname = '/tmp/water' + filePath = path.join(__dirname, fileName) }) 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 f495a77164..5706f2560e 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 @@ -97,6 +97,7 @@ describe('Fetch Licence Updates service', () => { licenceId: licence.id, licenceRef: licence.licenceRef, scheme: 'alcs' }) const billRun = await BillRunHelper.add({ scheme: 'alcs' }) + await BillRunChargeVersionYearHelper.add({ billRunId: billRun.id, chargeVersionId: chargeVersion.id }) }) @@ -123,6 +124,7 @@ describe('Fetch Licence Updates service', () => { function _threeMonthsAgo () { const today = new Date() + today.setMonth(today.getMonth() - 3) return today.toISOString() diff --git a/test/services/plugins/filter-routes.service.test.js b/test/services/plugins/filter-routes.service.test.js index 898f6dc48f..2f26953b8a 100644 --- a/test/services/plugins/filter-routes.service.test.js +++ b/test/services/plugins/filter-routes.service.test.js @@ -33,6 +33,7 @@ describe('Filter routes service', () => { describe('when the environment is production', () => { it('returns the routes filtered', () => { const filteredRoutes = Hoek.clone(routes) + filteredRoutes.pop() const result = FilterRoutesService.go(routes, 'prd') diff --git a/test/services/plugins/payload-cleaning.service.test.js b/test/services/plugins/payload-cleaning.service.test.js index 4a555230b5..70e83cb238 100644 --- a/test/services/plugins/payload-cleaning.service.test.js +++ b/test/services/plugins/payload-cleaning.service.test.js @@ -33,6 +33,7 @@ describe('Payload cleaning service', () => { } const cleanedObject = PayloadCleaningService.go(dirtyObject) + expect(cleanedObject.details.firstName).to.equal('Bert') expect(cleanedObject.details.lastName).to.equal('Ernie') @@ -207,6 +208,7 @@ describe('Payload cleaning service', () => { } const cleanedObject = PayloadCleaningService.go(dirtyObject) + expect(cleanedObject.codes).to.equal(['ABD1', 'C2']) }) diff --git a/test/services/return-requirements/frequency-collected.service.test.js b/test/services/return-requirements/frequency-collected.service.test.js index cbad757248..c9059c5ad9 100644 --- a/test/services/return-requirements/frequency-collected.service.test.js +++ b/test/services/return-requirements/frequency-collected.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 diff --git a/test/services/return-requirements/frequency-reported.service.test.js b/test/services/return-requirements/frequency-reported.service.test.js index 042d6f9505..5912e6dd97 100644 --- a/test/services/return-requirements/frequency-reported.service.test.js +++ b/test/services/return-requirements/frequency-reported.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 diff --git a/test/services/return-requirements/purpose.service.test.js b/test/services/return-requirements/purpose.service.test.js index 35c4c93d83..2134d1eba6 100644 --- a/test/services/return-requirements/purpose.service.test.js +++ b/test/services/return-requirements/purpose.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') // Things we need to stub diff --git a/test/validators/return-requirements/note.validator.test.js b/test/validators/return-requirements/note.validator.test.js index dde3b9912e..a277b87dcf 100644 --- a/test/validators/return-requirements/note.validator.test.js +++ b/test/validators/return-requirements/note.validator.test.js @@ -47,6 +47,7 @@ describe('Note validator', () => { Lorem ipsum dolor sit amet consectetur adipiscing elit Lorem ipsum dolor sit amet consectetur adipiscing elit` }) + expect(result.value).to.exist() expect(result.error).to.exist() expect(result.error.details[0].message).to.equal('Enter no more than 500 characters') diff --git a/test/validators/return-requirements/site-description.validator.test.js b/test/validators/return-requirements/site-description.validator.test.js index c56e8d409b..1d58f3c1f1 100644 --- a/test/validators/return-requirements/site-description.validator.test.js +++ b/test/validators/return-requirements/site-description.validator.test.js @@ -8,7 +8,7 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Thing under test -const SiteDescriptionValidator = require('../../../app/validators/return-requirements/site-description.validator') +const SiteDescriptionValidator = require('../../../app/validators/return-requirements/site-description.validator.js') describe('Site Description validator', () => { let payload