Skip to content

Testing Toggle Done Status Todo Endpoint

We now need to test if is_done value toggles from true to false and vice versa.

Since we deleted our only item from the database when we were testing deletion endpoint, we will have to create a new one in order to be able to test this functionality. You can repeat all the steps from section "Testing Add Todo Endpoint" and add a new item.But, since we already saved our "Add Todo Item" Request in Postman, we can use it.

You will just need to go to "Add Todo Item" tab in Postman and click "Send" button. That should basically again add a new todo item with title "Todo 1". Just like one we had before testing deletion.

The only value that will differ should be _id since MongoDB generates a new random id everytime we create an item.

After you successfully add it, you can go to MongoDB Atlas "Cluster0", access Collections and find a new item and get the _id so we can use it to test toggling endpoint.

MongoDB Atlas Is Done ID
MongoDB Atlas Is Done ID

We can see that our new item has id 61f358e91af28f1b4ad24bdd.

Also, you can notice that is_done value is set to false since we defined it in our endpoint for adding a new todo item. It makes sense since we want item to be marked as not done by default when it is initially added.


Now, we want to toggle is_done value from false to true.

We can to it using Postman and creating a new Request by clicking "+" button as we did for adding and deletion.

Since we are using PUT method, we will set our method for created request to PUT [1] and url to point to http://localhost:3001/todo/61f358e91af28f1b4ad24bdd [2].

You should replace id with the id of your todo item from the database.

Postman Done Request
Postman Done Request

If we hit "Send" button now, the request should go through and we should get successful response with status code 200. Also, since we made it to return our updated todo item in response, you will be able to see that is_done value is now set to true.

Postman Done Request Success
Postman Done Request Success

Also, we can make sure it updated by accessing our Collection inside MongoDB Atlas.

MongoDB Atlas Is Done
MongoDB Atlas Is Done

You can try and send this request from Postman multiple times and it should always toggle is_done value for an item with given id.


Now, we again want to save this Request in Postman so we can use it again if needed. You can repeat the same process as for "Add Todo Item" or "Delete Todo Item" requests. We will name it "Toggle Done Todo Item" and hit "Save" button.

Postman Save Done Request
Postman Save Done Request


Congrats! We are done with both client and server applications, but we need somehow to connect them to work together. Right? We will cover this in the next few chapters.


Last update: March 28, 2022