Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

chore for better test environment #74

Merged
merged 19 commits into from
Oct 31, 2020
Merged

chore for better test environment #74

merged 19 commits into from
Oct 31, 2020

Conversation

mithi
Copy link
Owner

@mithi mithi commented Oct 30, 2020

It is better to have two separate test environments (two test databases),
one for testing resolvers (which is closer to an integration test), and the other for testing everything else.

When testing graphql resolvers, seeding the database should only be done once as this is a slow operation.
Currently, using globalSetup and globalTeardown with jest doesn't work for setting up the typeorm database.
The tests are not able to find the connection.
See:
#73
typeorm/typeorm#5308
jestjs/jest#10178

It is also not efficient to remove all of the entries for this database in order to start with a clean slate for
testing the models and testing the seeding operations. So what we do here is we have two test databases.

  1. a prepopulated frozen test database (called test_db) to be used by the graphql resolvers
  2. an empty database (called empty_test_db) which we can safely mutate (like inserting and deleting operation) to test seeding functions, among others

So this pull request updates all the scripts and other files for the current tests to work

I have also refactored some of the test scripts to be more readable and also added
a simple test for testing the abilityById graphql query..

@mithi mithi changed the title Tests/abilities tests chore for better test environment Oct 31, 2020
@mithi mithi linked an issue Oct 31, 2020 that may be closed by this pull request
@mithi mithi merged commit cf9f177 into main Oct 31, 2020
@mithi mithi deleted the tests/abilities-tests branch October 31, 2020 08:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to use global setup for setting up typeorm database and seeding it?
1 participant