From eba2c6ced048c7f77ebb9eb879c7c948dcccbe68 Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 5 Sep 2023 15:35:25 +0100 Subject: [PATCH 1/5] Standardise how model helpers generate dates We have spotted some inconsistency in how our model test helpers are adding dates. Some are using just text for the date as other are creating actual dates using `new Date()`. This PR will ensure that all helpers are using the `new Date()` method to populate thier dates. From 1b72655ae0e6d6b05e8b9cf009cb7bb074ac0a3c Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 5 Sep 2023 16:06:33 +0100 Subject: [PATCH 2/5] Standardise model helper date creation --- .../helpers/crm-v2/invoice-account-address.helper.js | 2 +- test/support/helpers/returns/return.helper.js | 8 ++++---- test/support/helpers/water/change-reason.helper.js | 8 +++++++- test/support/helpers/water/charge-purpose.helper.js | 4 ++-- .../helpers/water/charge-version-workflow.helper.js | 8 +++++++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/test/support/helpers/crm-v2/invoice-account-address.helper.js b/test/support/helpers/crm-v2/invoice-account-address.helper.js index 9595347997..9a9e43515b 100644 --- a/test/support/helpers/crm-v2/invoice-account-address.helper.js +++ b/test/support/helpers/crm-v2/invoice-account-address.helper.js @@ -39,7 +39,7 @@ function defaults (data = {}) { const defaults = { invoiceAccountId: 'b16efa32-9271-4333-aecf-b9358ba42892', addressId: '9570acde-752e-456a-a895-7b46a3c923a3', - startDate: new Date(2023, 9, 18) + startDate: new Date('2023-08-18') } return { diff --git a/test/support/helpers/returns/return.helper.js b/test/support/helpers/returns/return.helper.js index 807eed9b67..84978d8436 100644 --- a/test/support/helpers/returns/return.helper.js +++ b/test/support/helpers/returns/return.helper.js @@ -51,15 +51,15 @@ function defaults (data = {}) { regime: 'water', licenceType: 'abstraction', licenceRef: '9/99/99/99/9999', - startDate: '2022-04-01', - endDate: '2023-03-31', + startDate: new Date('2022-04-01'), + endDate: new Date('2023-03-31'), returnsFrequency: 'month', status: 'completed', source: 'NALD', metadata: {}, - receivedDate: '2023-04-12', + receivedDate: new Date('2023-04-12'), returnRequirement: '99999', - dueDate: '2023-04-28', + dueDate: new Date('2023-04-28'), returnCycleId: '2eb314fe-da45-4ae9-b418-7d89a8c49c51' } diff --git a/test/support/helpers/water/change-reason.helper.js b/test/support/helpers/water/change-reason.helper.js index 0a7ba11293..ed8011309a 100644 --- a/test/support/helpers/water/change-reason.helper.js +++ b/test/support/helpers/water/change-reason.helper.js @@ -41,7 +41,13 @@ function defaults (data = {}) { description: 'Strategic review of charges (SRoC)', type: 'new_chargeable_charge_version', isEnabledForNewChargeVersions: true, - createdAt: new Date('2022-02-23') + // INFO: The change_reasons 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 ('2022-02-23 09:19:39.953') and PostgreSQL can do the conversion + // https://stackoverflow.com/a/61912776/6117745 + createdAt: new Date('2022-02-23 09:19:39.953').toISOString() } return { diff --git a/test/support/helpers/water/charge-purpose.helper.js b/test/support/helpers/water/charge-purpose.helper.js index 53b1f2db47..9c3d783dd7 100644 --- a/test/support/helpers/water/charge-purpose.helper.js +++ b/test/support/helpers/water/charge-purpose.helper.js @@ -59,8 +59,8 @@ function defaults (data = {}) { loss: 'low', factorsOverridden: true, billableAnnualQuantity: 4.55, - timeLimitedStartDate: '2022-04-01', - timeLimitedEndDate: '2030-03-30', + timeLimitedStartDate: new Date('2022-04-01'), + timeLimitedEndDate: new Date('2030-03-30'), description: 'Trickle Irrigation - Direct', purposePrimaryId: '383ab43e-6d0b-4be0-b5d2-4226f333f1d7', purposeSecondaryId: '0e92d79a-f17f-4364-955f-443360ebddb2', diff --git a/test/support/helpers/water/charge-version-workflow.helper.js b/test/support/helpers/water/charge-version-workflow.helper.js index 385bc3032d..8905a594e2 100644 --- a/test/support/helpers/water/charge-version-workflow.helper.js +++ b/test/support/helpers/water/charge-version-workflow.helper.js @@ -41,7 +41,13 @@ function defaults (data = {}) { licenceId: '1acfbded-9cd4-4933-8e98-04cd9e92d884', status: 'to_setup', data: { chargeVersion: null }, - createdAt: new Date() + // INFO: The change_reasons 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 ('2022-02-23 09:19:39.953') and PostgreSQL can do the conversion + // https://stackoverflow.com/a/61912776/6117745 + createdAt: new Date('2022-02-23 09:19:39.953').toISOString() } return { From ab42b1bae0bd75857e36f16ff435044398f6a955 Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 5 Sep 2023 16:20:52 +0100 Subject: [PATCH 3/5] Fix typo --- test/support/helpers/water/charge-version-workflow.helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/support/helpers/water/charge-version-workflow.helper.js b/test/support/helpers/water/charge-version-workflow.helper.js index 8905a594e2..7f6056b610 100644 --- a/test/support/helpers/water/charge-version-workflow.helper.js +++ b/test/support/helpers/water/charge-version-workflow.helper.js @@ -41,7 +41,7 @@ function defaults (data = {}) { licenceId: '1acfbded-9cd4-4933-8e98-04cd9e92d884', status: 'to_setup', data: { chargeVersion: null }, - // INFO: The change_reasons table does not have a default for the date_created column. But it is set as + // INFO: The charge_version_workflows 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 From 45a488d759c26c7dfe430ed863b6e59c709e3d4a Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 5 Sep 2023 16:49:03 +0100 Subject: [PATCH 4/5] Update date to current date and time --- test/support/helpers/water/charge-version-workflow.helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/support/helpers/water/charge-version-workflow.helper.js b/test/support/helpers/water/charge-version-workflow.helper.js index 7f6056b610..7973fa2509 100644 --- a/test/support/helpers/water/charge-version-workflow.helper.js +++ b/test/support/helpers/water/charge-version-workflow.helper.js @@ -14,7 +14,7 @@ const ChargeVersionWorkflowModel = require('../../../../app/models/water/charge- * - `licenceId` - 1acfbded-9cd4-4933-8e98-04cd9e92d884 * - `status` - to_setup - Other possible values are: changes_requested & review * - `data` - { chargeVersion: null }, - * - `createdAt` - 2022-02-23 + * - `createdAt` - the current date and time * * @param {Object} [data] Any data you want to use instead of the defaults used here or in the database * @@ -47,7 +47,7 @@ function defaults (data = {}) { // epoch in milliseconds, whereas a PostgreSQL timestamp field can only hold the seconds since the epoch. Pass it // an ISO string though ('2022-02-23 09:19:39.953') and PostgreSQL can do the conversion // https://stackoverflow.com/a/61912776/6117745 - createdAt: new Date('2022-02-23 09:19:39.953').toISOString() + createdAt: new Date().toISOString() } return { From 2e9942c3a3eccd0ba3ef5a4bfa9a81040ff2dab3 Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Tue, 5 Sep 2023 16:53:00 +0100 Subject: [PATCH 5/5] Tidy up comments --- test/support/helpers/water/change-reason.helper.js | 11 +++++------ .../helpers/water/charge-version-workflow.helper.js | 9 ++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/test/support/helpers/water/change-reason.helper.js b/test/support/helpers/water/change-reason.helper.js index ed8011309a..1894eae624 100644 --- a/test/support/helpers/water/change-reason.helper.js +++ b/test/support/helpers/water/change-reason.helper.js @@ -41,12 +41,11 @@ function defaults (data = {}) { description: 'Strategic review of charges (SRoC)', type: 'new_chargeable_charge_version', isEnabledForNewChargeVersions: true, - // INFO: The change_reasons 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 ('2022-02-23 09:19:39.953') and PostgreSQL can do the conversion - // https://stackoverflow.com/a/61912776/6117745 + // INFO: The change_reasons 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. 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 ('2022-02-23 09:19:39.953') and PostgreSQL can do the + // conversion https://stackoverflow.com/a/61912776/6117745 createdAt: new Date('2022-02-23 09:19:39.953').toISOString() } diff --git a/test/support/helpers/water/charge-version-workflow.helper.js b/test/support/helpers/water/charge-version-workflow.helper.js index 7973fa2509..ff0358a6bb 100644 --- a/test/support/helpers/water/charge-version-workflow.helper.js +++ b/test/support/helpers/water/charge-version-workflow.helper.js @@ -42,11 +42,10 @@ function defaults (data = {}) { status: 'to_setup', data: { chargeVersion: null }, // INFO: The charge_version_workflows 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 ('2022-02-23 09:19:39.953') and PostgreSQL can do the conversion - // https://stackoverflow.com/a/61912776/6117745 + // 'not nullable'! So, we need to ensure we set it when creating a new record. 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 ('2022-02-23 09:19:39.953') and PostgreSQL can do the + // conversion https://stackoverflow.com/a/61912776/6117745 createdAt: new Date().toISOString() }