Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first example reference model test (Regions) (#14)
Now that we've imported and updated all our models, it is time to start adding some example tests to further research node-test as an alternative to Lab. In database terms, all models are accessed and used via Objection.js. However, for testing, we split them into two camps: reference models and transaction models. Reference models are things we don't expect to create within the service as part of daily use. They are records that would be seeded, such as regions. Transaction models are things we expect to be created, such as bill runs or licences. When it comes to testing we seed the tables that back the reference models, hence their helpers generally have a `select()` method. Transaction models, when needed, will be created during the testing. Their helpers generally have an `add()` method. When we first tried this test, node-test wouldn't quit. It wouldn't even move to the next spec after `region.model.test.js`. This is a problem we first faced when pulling this project together. Time away has clearly helped because we were able to diagnose the cause as the database connection we create blocks node test from exiting (see [test_runner: allow to force exit after all tests finished](nodejs/node#49925) for a deeper dive into the issue which gave us our a-ha! moment). This does mean we'll need to add an `after()` block to any spec that results in a DB connection being made, but that should be simple enough. Completing this example has also highlighted that we'll probably want to extend `assert` in some way, to avoid 'messy duplication' in our tests. But for now, here is our first working model node-test!
- Loading branch information