Category: Database, Data

This is a 3 part series for unit testing the controller, service, and repository layers in a typical REST architecture.

Part 1 — Unit Testing the Controller | Git branch can be found here.

We don't need to test any of the error conditions as this is the TypeOrm implementation and its will returns its own error.

Yep as expected: First we need to update the SpaceShipModule to add the entity and providers: And we also need to setup the DB for the project — given that we have done this already in the test, we can use that for the sake of the demo. Update the app module: Now we can start up the app and call the endpoint using Postman to call it: And we get a response of SpaceShip: We can also test the ID by sending an incorrect spaceShipId and see the expected response: This concludes the 3 part series for unit testing the API layers.

Related Articles