How can we test our shopping features?
It is important to make sure that our purchase-related features are working properly in our system. Here we guide you on how to test those features using Postman. Before you start testing, remember that it is crucial to restart your service to apply all the changes made. This ensures that the server is operational and receiving requests properly. We will examine three essential methods exposed through our API: get all purchases, retrieve purchases per customer, and save a new purchase.
How to get all purchases?
We'll start by testing the functionality to fetch all registered purchases. Using Postman, you can upload the corresponding request. The key is to send the GET
request through the API, which will allow you to receive a response with the purchase history. This gives you an overview of all transactions associated with the customers:
GET /api/purchases/all
- Open Postman.
- Select or create a new
GET
request.
- Enter the URL corresponding to get all purchases.
- Click "Send".
- Review the response containing a list of purchases associated with the customers.
How to verify specific purchases by customer?
The next test involves retrieving specific purchases associated with a particular customer. We should enter the ID of the customer in question into the request to retrieve only the purchases made by that person:
GET /api/purchases/client/:clientId.
- In Postman, select the option to create or edit a
GET
request.
- Enter the URL that allows you to retrieve purchases by customer, replacing
:clientId
with the actual customer ID.
- Click "Send".
- Examine the results to verify that only the purchases of the indicated customer are displayed.
How to save a new purchase?
Finally, we will test our system's ability to store new purchases. This request requires the use of the POST
method, entering the details of the purchase within the body of the message. It is important to include details such as the type of payment and the date of the purchase:
POST /api/purchases/new{ " paymentMethod": "card", " year": 2020, " clientId": "1234567"}
- In Postman, select a new
POST
request.
- Enter the URL to save a new purchase.
- Add the body of the request with the necessary details.
- Click "Send" and verify that the purchase has been saved correctly.
- You can confirm its saving by reusing the
GET
request to get shopping lists, confirming that the new transaction is visible.
This process ensures that the shopping services are operational and reliable. Also, remember to use the JSON file provided to import the requests into your Postman environment. This way, you can be sure that you are replicating the process and testing the requests efficiently. In a future class, we will cover the documentation of our API with Swagger, let's keep learning!
Want to see more contributions, questions and answers from the community?