benoit-bremaud / HappiHub

HappiHub - A platform for organizing and discovering cultural and artistic events. Join the community and explore events happening around you!
https://www.happihub.com
MIT License
1 stars 3 forks source link

feat: implement PATCH /comments/:id route to partially update a comme… #196

Closed benoit-bremaud closed 4 months ago

benoit-bremaud commented 4 months ago

feat: implement PATCH /comments/:id route to partially update a comment by ID

Summary

This pull request implements the PATCH /comments/:id route that allows authenticated users to partially update a specific comment by its ID. The route ensures that only the author of the comment or an admin can perform the update.

Changes Implemented

How to Test

  1. Partial Update as Author:

    • Send a PATCH request to http://localhost:5000/comments/:id with a valid comment ID where the author matches the authenticated user.
    • Ensure the comment is partially updated successfully.
  2. Partial Update as Admin:

    • Send a PATCH request to http://localhost:5000/comments/:id with a valid comment ID using an admin token.
    • Ensure the comment is partially updated successfully.
  3. Unauthorized Update Attempt:

    • Send a PATCH request to http://localhost:5000/comments/:id with a valid comment ID using a token from a different user (not the author and not an admin).
    • Ensure the response is 403 Forbidden.
  4. Comment Not Found:

    • Send a PATCH request to http://localhost:5000/comments/:id with a non-existent comment ID.
    • Ensure the response is 404 Not Found.

Example Request (Admin)

PATCH /comments/669b31e121af94e2afcdd82f HTTP/1.1
Host: localhost:5000
Authorization: Bearer <admin_token>
Content-Type: application/json

{
  "content": "Updated comment content",
  "status": "rejected"
}

Example Response

{
    "_id": "669b31e121af94e2afcdd82f",
    "content": "Updated comment content",
    "author": "669b2fba21af94e2afcdd828",
    "event": "669b314e21af94e2afcdd82d",
    "status": "rejected",
    "createdAt": "2024-07-20T03:41:21.577Z",
    "updatedAt": "2024-07-20T11:49:52.478Z",
    "__v": 0
}

Resolves #151