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

Create seeder for charge_categories #1312

Merged
merged 19 commits into from
Sep 11, 2024
Merged

Create seeder for charge_categories #1312

merged 19 commits into from
Sep 11, 2024

Conversation

Jozzey
Copy link
Contributor

@Jozzey Jozzey commented Sep 5, 2024

Currently, with the way data is being inserted into charge_categories using the helper to create records during unit testing. We are getting intermittent failures when running the unit tests when the charge reference gets duplicated due to its lack of randomness.

We have therefore decided that since the data in charge_categories is reference data we shouldn't be creating new charge category records each time a unit test requires one. Instead, we should just be seeding the data once and then writing the unit tests to use this seeded data. The bulk of this work has been done for other tables in this PR #1230

This PR will create the functions required to seed the charge_categories and then fix any code affected by this change.

Currently with the way data is being inserted into `charge_categories` using the helper to create records during unit testing. We are getting intermittent failures when running the unit tests when the charge `reference` gets duplicated due to it's lack of randomness.

We have therefore decided that since the data in `charge_categories` is reference data we shouldn't really be creating a new charge category records each time a unit test requires one. Instead we should just be seeding the data once and then writing the unit tests to use this seeded data. The bulk of this work has been done for other tables in this PR #1230
@Jozzey Jozzey added the housekeeping Refactoring, tidying up or other work which supports the project label Sep 5, 2024
@Jozzey Jozzey self-assigned this Sep 5, 2024
Jozzey and others added 16 commits September 5, 2024 16:21
I pulled the first lot of seed data from my local DB then figured it would be better to get it from Pre-prod
The amount of data that is in the `charge_categories` table now that the data is seeded is causing this test to hang. Switching to the `regions` table that has less data in resolves the issue.
I initially removed `DatabaseSupport.clean()` from the test files that I updated. However this appeared to open a bit of a can of worms. Whilst the tests that I'd amended ran fine it was having an effect on other tests causing intermittent failures.

So I think it's best to leave removing the DB cleanup for another PR.
@Jozzey Jozzey marked this pull request as ready for review September 10, 2024 16:16
@Jozzey Jozzey merged commit 5c07d46 into main Sep 11, 2024
6 checks passed
@Jozzey Jozzey deleted the charge-categories-seeder branch September 11, 2024 09:59
Copy link
Contributor

@Beckyrose200 Beckyrose200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@@ -0,0 +1,33 @@
'use strict'

const { timestampForPostgres } = require('../../app/lib/general.lib.js')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, I think this needs to be below line 5

* - `maxVolume` - 5000,
* - `dateCreated` - Date.now()
* So, they are seeded automatically when tests are run. Tests that need to link to a record can use this method to
* select a specific entry, or have it it return one at random.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* select a specific entry, or have it it return one at random.
* select a specific entry, or have it return one at random.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants