-
Notifications
You must be signed in to change notification settings - Fork 0
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
Make test data helpers more 'unique' #452
Conversation
https://eaflood.atlassian.net/browse/WATER-4144 We've been investigating changing our unit test framework recently (see [Investigate switching to jest](#430) and [water-abstraction-ava](https://github.com/DEFRA/water-abstraction-ava)). A key issue we'll have if we switch is that most other frameworks run tests asynchronously. This means our pattern of clean-setup-assert won't work. At best we can clean before any tests run but then the test data we setup must not clash. To achieve that we need to make the test data the helpers generate as unique as possible, which means moving away from hard coded values. We're still playing with frameworks but there is nothing stopping us making this change now ahead of a decision. So, this change covers making the helpers generate more unique and fixing any tests that breaks.
Where a helper is hard coding a UUID for a field is going to be easy to make unique; we just call our `GeneralLib.generateUUID()` function. But many helpers also need to generate references, licence number being a good example. If we are going to make these unique we're going to need a means to generate random numbers. Often they need to be within a certain range, for example, 100 to 999 because the number must be a certain number of digits long. So, we're adding a new `randomInteger()` function which can handle this requirement. Doing so forced us to make a decision as to where to put it. We decided to create a `GeneralHelper` module that can be used going forward for any shared functionality in the helpers.
The tests relied on known uprn and company numbers. They needed to be tweaked to work with generated numbers which meant the tests needed to access the same reference generators as the helpers.
fea9cf3
to
01b5be8
Compare
test/services/billing/supplementary/fetch-previous-transactions.service.test.js
Dismissed
Show dismissed
Hide dismissed
test/services/billing/supplementary/fetch-previous-transactions.service.test.js
Dismissed
Show dismissed
Hide dismissed
This is bigger than I'd like it to be. But it made sense to do all the helpers at the same time, especially as the changes are generally consistent across them. Happy to walk/talk through anything if anyone has questions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few things I noticed, but looks good :D
test/services/billing/supplementary/fetch-previous-transactions.service.test.js
Outdated
Show resolved
Hide resolved
test/services/billing/supplementary/fetch-previous-transactions.service.test.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/services/billing/supplementary/fetch-previous-transactions.service.test.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
https://eaflood.atlassian.net/browse/WATER-4144
We've been investigating changing our unit test framework recently (see Investigate switching to jest and water-abstraction-ava).
A key issue we'll have if we switch is that most other frameworks run tests asynchronously. This means our pattern of clean-setup-assert won't work. At best we can clean before any tests run but then the test data we set up must not clash.
To achieve that we need to make the test data the helpers generate as unique as possible, which means moving away from hard-coded values.
We're still playing with frameworks but there is nothing stopping us from making this change now ahead of a decision.
So, this change covers making the helpers generate more unique and fixing any tests that break.
Notes
Where a helper is hard-coding a UUID for a field is going to be easy to make it unique; we just call our
GeneralLib.generateUUID()
function.But many helpers also need to generate references, licence numbers being a good example. If we are going to make these unique we're going to need a means to generate random numbers. Often they need to be within a certain range, for example, 100 to 999 because the number must be a certain number of digits long.
So, we're adding a new
randomInteger()
function which can handle this requirement. Doing so forced us to make a decision as to where to put it. We decided to create aGeneralHelper
module that can be used going forward for any shared functionality in the helpers.