We’ll start testing our endpoints using postman. This is very important, especially when creating your applications using Test Driven Development(TDD) principles.

If you haven’t done previous steps, I would recommend going over previous steps, since you are testing the backend.

We’ll start going over how we are gonna test our endpoints. The updated version of postman has chai built in. Which is testing library that makes testing easier due to it’s similarities to the english language. We won’t be doing anything to complex.

Here is the chai documentation. You should reference heavily when testing with postman.

First create a postman_collection folder outside your src folder. Then cd into it and create a ecommerceApp.postman_testing.json within that directory.

Now copy the collection from this url and paste it to your ecommerceApp.postman_testing.json file.


Make, all the properties within double quotes after you paste it to make it valid json.

Now go to postman and click the import on the top left to import the collection. Then import the file.

Now we have the collection uploaded.

Now we will just do some basic testing on the get endpoints. We will first do our ‘/api/users’.

We will access our response via the pm.response.json() since the type is json, and assign it to variable called response.

Now to start testing, use the pm.test which will take a note as first argument describing the test, then a callback initiating the test.

We will create a test for our status code, and we are also gonna purposely fail one test for each endpoint.

Now we have tested first endpoint, now run your tests. In your tests tab you should 1/2 test should past.

Now lets test the /api/products that will get all the products. We will test if the products returned is an array, and it returns a status code of 200. Then check if the response is also a object to make it purposely fail.

First set response to the pm.response.json(). Then start performing your first test by checking if the status code is 200.

Now check if the response is an array, then make it purposely fail, by checking if it’s a object.

Now run your tests, and in your tests tab it should be 2/3

One more test for our get endpoints. We will test getting a specific product using it’s id.

We will assign the response to pm.response.json(). Then will do the same tests except we will have our passing test be checking if it’s a object. Since it is returning a object, and our failing test will be checking if it’s an array.

Test it, and the tests tab should have 2/3 pass.

Great, we have our get endpoints tested on. Now will just need to test all of the create, update, delete endpoints.

Here is my Github for reference.

Next step we will finish our testing and finally start doing front-end work.

Happy Coding!