-
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
Improve model tests #71
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cruikshanks
added
the
housekeeping
Refactoring, tidying up or other work which supports the project
label
Dec 22, 2022
Cruikshanks
added a commit
that referenced
this pull request
Dec 22, 2022
> This is in support of [Improve model tests](#71) Currently, our test helpers create records using Knew directly. This is a result of the initial helpers being added before we implemented [Objection.js](https://vincit.github.io/objection.js/). We want to expand some of our tests plus there is an argument to be consistent in how we interact with the tables in our DB. So, this change updates the helpers to do things via Objection and fixes any tests we break as a result.
Cruikshanks
added a commit
that referenced
this pull request
Dec 22, 2022
> This is in support of [Improve model tests](#71) Currently, our test helpers create records using Knex directly. This is a result of the initial helpers being added before we implemented [Objection.js](https://vincit.github.io/objection.js/). We want to expand some of our tests plus there is an argument to be consistent in how we interact with the tables in our DB. So, this change updates the helpers to do things via Objection and fixes any tests we break. ** Notes - We switch to immediately returning the result on the basis the calling method will `await` the result. This removes the need to declare the method `async`. - We update the services to use the correct case - We update the helpers to be consistent with their module.exports
Cruikshanks
force-pushed
the
improve-model-tests
branch
from
December 22, 2022 16:44
f56e0bd
to
3bf6061
Compare
In a [previous change](#70) we had to fix our Objection implementation because we realised - our way of handling multiple schemas (using `tableName`) was [invalid](Vincit/objection.js#85 (comment)) - we were using the wrong case (snake vs camel) in most places. Under the hood Knex was fine, but once we leant into Objection relationships `withGraphFetched()` was bringing back nothing What this highlighted was our existing model tests weren't really doing anything. Sure, a query can get generated but till you run them and confirm a result you can't be sure they are working as expected. So, this change updates our model relationship tests to insert some data and confirm we get expected results back.
As a `HasManyRelation` the relationship name should be plural not singular.
Just going to make it easier to be consistent across the model tests tp call it something generic.
Cruikshanks
force-pushed
the
improve-model-tests
branch
from
December 23, 2022 11:44
4565ba7
to
e73b329
Compare
Jozzey
approved these changes
Dec 23, 2022
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In a previous change we had to fix our Objection implementation because we realised
tableName
) was invalidwithGraphFetched()
was bringing back nothingWhat this highlighted was our existing model tests weren't really doing anything. Sure, a query can get generated but till you run them and confirm a result you can't be sure they are working as expected.
So, this change updates our model relationship tests to insert some data and confirm we get the expected results back.