From 9e2306b868d207872d9f49d53872936ca5b93803 Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Thu, 5 Jan 2023 08:38:25 +0000 Subject: [PATCH] Fix broken tests --- .../create-billing-batch-event.presenter.test.js | 4 ++-- .../helpers/water/billing-charge-category.helper.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/presenters/supplementary-billing/create-billing-batch-event.presenter.test.js b/test/presenters/supplementary-billing/create-billing-batch-event.presenter.test.js index 224938cf2b..7b7a0416e4 100644 --- a/test/presenters/supplementary-billing/create-billing-batch-event.presenter.test.js +++ b/test/presenters/supplementary-billing/create-billing-batch-event.presenter.test.js @@ -44,8 +44,8 @@ describe('Create Billing Batch Event presenter', () => { expect(result.batch.isSummer).to.equal(billingBatch.isSummer) expect(result.batch.netTotal).to.equal(billingBatch.netTotal) - expect(result.batch.dateCreated).to.equal(billingBatch.createdAt) - expect(result.batch.dateUpdated).to.equal(billingBatch.updatedAt) + expect(result.batch.dateCreated).to.equal(billingBatch.dateCreated) + expect(result.batch.dateUpdated).to.equal(billingBatch.dateUpdated) expect(result.batch.invoiceCount).to.equal(billingBatch.invoiceCount) expect(result.batch.invoiceValue).to.equal(billingBatch.invoiceValue) expect(result.batch.creditNoteCount).to.equal(billingBatch.creditNoteCount) diff --git a/test/support/helpers/water/billing-charge-category.helper.js b/test/support/helpers/water/billing-charge-category.helper.js index 5e3089e2c6..dd8067b899 100644 --- a/test/support/helpers/water/billing-charge-category.helper.js +++ b/test/support/helpers/water/billing-charge-category.helper.js @@ -20,7 +20,8 @@ const BillingChargeCategoryModel = require('../../../../app/models/water/billing * - `modelTier` - tier 1 * - `isRestrictedSource` - true * - `minVolume` - 0 - * - `maxVolume` - 5000 + * - `maxVolume` - 5000, + * - `dateCreated` - Date.now() * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -53,7 +54,14 @@ function defaults (data = {}) { modelTier: 'tier 1', isRestrictedSource: true, minVolume: 0, - maxVolume: 5000 + maxVolume: 5000, + // INFO: The billing_charge_categories table does not have a default for the date_created column. But it is set as + // 'not nullable'! So, we need to ensure we set it when creating a new record, something we'll never actually need + // to do because it's a static table. Also, we can't use Date.now() because Javascript returns the time since the + // epoch in milliseconds, whereas a PostgreSQL timestamp field can only hold the seconds since the epoch. Pass it + // an ISO string though ('2023-01-05T08:37:05.575Z') and PostgreSQL can do the conversion + // https://stackoverflow.com/a/61912776/6117745 + dateCreated: new Date().toISOString() } return {