Skip to Content
Courses

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

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

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

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

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


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 updated on