Middle
How would you test the "Add product to cart" endpoint? There is a limit: no more than 30 products can be added to the cart. Fields: productId - the id of the product to add quantity - optional, if not specified, the quantity will be 1 POST [link] Params Authorization Headers (8) Body none form-data x-www-form-urlencoded { "productId": 1, "quantity": 2 }
sobes.tech AI
Answer from AI
To test the "Add to Cart" endpoint with a maximum limit of 30 items, the following scenarios should be checked:
-
Adding an item with specified quantity
- Send a request with productId and quantity < 30, verify that the item is added with the correct quantity.
-
Adding an item without specifying quantity
- Send a request with only productId, verify that 1 item is added.
-
Adding an item with quantity = 0 or a negative number
- Check that the server returns an error (e.g., 400 Bad Request).
-
Adding an item with quantity > 30
- Verify that the server does not allow adding more than 30 items, and returns an error.
-
Adding an item when the cart already contains items
- Verify that the total number of items does not exceed 30.
-
Adding a non-existent productId
- Check that the server returns an error (e.g., 404 Not Found).
-
Checking boundary values
- Add 30 items in one request.
- Add multiple requests with a total of 30 items.
-
Checking request format
- Send a request with an incorrect body format, verify error handling.
Example curl request:
curl -X POST [link] \
-H "Content-Type: application/json" \
-d '{"productId":1,"quantity":2}'
Also, ensure that after a successful addition, the cart updates correctly.