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

Improve model tests #71

Merged
merged 14 commits into from
Dec 23, 2022
Merged

Improve model tests #71

merged 14 commits into from
Dec 23, 2022

Conversation

Cruikshanks
Copy link
Member

In a previous change we had to fix our Objection implementation because we realised

  • our way of handling multiple schemas (using tableName) was invalid
  • 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 the expected results back.

@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label Dec 22, 2022
@Cruikshanks Cruikshanks self-assigned this 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
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 Cruikshanks marked this pull request as ready for review December 23, 2022 12:45
@Cruikshanks Cruikshanks requested a review from Jozzey December 23, 2022 12:45
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

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

@Cruikshanks Cruikshanks merged commit 031bc77 into main Dec 23, 2022
@Cruikshanks Cruikshanks deleted the improve-model-tests branch December 23, 2022 14:02
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.

2 participants