The model tests are omitted here because they are essentially the same as in the impure section. In contrast to the tests on the impure service, we will now write unit tests for our routes.
This means that we will be able to test our routing logic without spinning up a database.
Test repository
To be able to test our routes, we will have to implement a TestRepository first, which we will use instead of the concrete implementation that is wired to a database.
Base class for unit tests
Testing Product fromDatabase
Testing a JSON codec
Testing decoding garbage input
Testing invalid input values
Testing valid input
Testing included fields
Decoding encoded JSON
More tests
Testing Translation fromUnsafe
Base class for unit tests
To avoid repeating the construction of our unit test classes, we will implement a base class for tests, which is quite simple.