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

Standardise how model helpers generate dates #409

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions test/support/helpers/returns/return.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
7 changes: 6 additions & 1 deletion test/support/helpers/water/change-reason.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ 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. 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 {
Expand Down
4 changes: 2 additions & 2 deletions test/support/helpers/water/charge-purpose.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 7 additions & 2 deletions test/support/helpers/water/charge-version-workflow.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -41,7 +41,12 @@ function defaults (data = {}) {
licenceId: '1acfbded-9cd4-4933-8e98-04cd9e92d884',
status: 'to_setup',
data: { chargeVersion: null },
createdAt: new Date()
// 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. 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()
}

return {
Expand Down