-
Notifications
You must be signed in to change notification settings - Fork 0
Category Update API Endpoint #8
Copy link
Copy link
Open
Description
Description
Develop an endpoint to handle requests to update an existing category. If the category is updated successfully, it will be returned to the client with a 200 OK status. If an error occurs, an appropriate error status will be returned.
Acceptance Criteria
- The endpoint allows updating an existing category with the fields: name and description.
- The endpoint validates the input data and returns appropriate error messages for invalid data or missing required fields.
- Returns a
200 OKstatus code and the updated category data when the category is updated successfully.
Requirements
- Implement API endpoint for updating an existing category.
- Validate the input data, including length and format checks for name and description.
- Handle conflicts if updating a category to a name that already exists and return a
409 Conflictstatus code. - Handle not found errors if the category to be updated does not exist and return a
404 Not Foundstatus code. - Handle unexpected errors and return the appropriate status code.
Expected Outcome
- Users should be able to send a request to update an existing category.
- Users should receive appropriate status codes and responses based on the outcome of the request.
Endpoints
[PATCH] /api/v1/categories/{id}
-
Description: Updates an existing category.
-
Request Body (JSON):
{ "name": "Updated Technology", "description": "Updated description for technology posts." } -
Success Response:
-
Status:
200 OK -
Body:
{ "id": 1, "name": "Updated Technology", "description": "Updated description for technology posts.", "created_at": "2024-07-18T00:00:00Z", "updated_at": "2024-07-18T01:00:00Z" }
-
-
Error Response:
-
Status:
500 Internal Server Error -
Body:
{ "error": "Internal server error." }
-
-
Conflict Response:
-
Status:
409 Conflict -
Body:
{ "detail": "A category with this name already exists." }
-
-
Not Found Response:
-
Status:
404 Not Found -
Body:
{ "detail": "Category not found." }
-
-
Validation Error Response:
-
Status:
422 Unprocessable Entity -
Body:
{ "detail": "Invalid data message." }
-
Testing
Test Scenarios
-
Successful Update of Category
- Ensure that the endpoint successfully updates an existing category.
- Verify that the response includes the updated category data and a
200 OKstatus code.
-
Conflict Error
- Simulate a request to update a category to a name that already exists.
- Verify that the endpoint returns a
409 Conflictstatus code and an appropriate error message.
-
Not Found Error
- Simulate a request to update a non-existent category.
- Verify that the endpoint returns a
404 Not Foundstatus code and an appropriate error message.
-
Internal Server Error
- Simulate an internal server error to raise an exception.
- Verify that the endpoint returns a
500 Internal Server Errorstatus code and an appropriate error message.
-
Invalid Data
- Send requests with invalid data (e.g., missing required fields, incorrect data types).
- Verify that the endpoint returns a
422 Unprocessable Entitystatus code and an appropriate error message.
-
Boundary Testing for Fields
- Test the maximum length constraints for the name and description fields.
- Ensure that the endpoint handles the boundary conditions correctly and returns appropriate error messages for exceeding the length limits.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels