hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
182 stars 105 forks source link

[FEAT] Implement API Endpoint for Sending Email Requests #253

Closed PcNerd9 closed 2 weeks ago

PcNerd9 commented 1 month ago

Description

Develop an endpoint to handle requests for sending emails using pre-defined templates. The emails should be placed in a database queue for sending to ensure the application remains responsive. The endpoint should handle variable substitution, replacing placeholders in the templates with actual data.

Acceptance Criteria

Data Validation

Authentication and Authorization

Performance and Security

Documentation

Testing Requirements

Dependencies and Impact

Requirements

Expected Outcome

Endpoints

[POST] /api/v1/send-email

status Code: 404 Not Found Body:

{
  "error": "Template not found."
}

Status Code: 405 Method Not Allowed Body:

{
  "error": "This method is not allowed."
}

Status Code: 400 Bad Request Body:

{
  "error": "An invalid request was sent."
}

Testing

Test Scenarios

  1. Successful Email Sending Request

    • Ensure that the endpoint accepts a request to send an email using a template.
    • Verify that the response indicates the request is being processed in the background.
    • Confirm that the status code is 202 Accepted.
  2. Template Not Found

    • Simulate a scenario where the specified email template ID does not exist.
    • Confirm that the response body contains an appropriate error message.
    • Confirm that the status code is 404 Not Found.
  3. Internal Server Error

    • Simulate an internal server error to raise an exception.
    • Verify that the endpoint returns a 500 Internal Server Error status code.
    • Confirm that the response body contains an appropriate error message.
  4. Invalid Method

    • Send a request using an invalid HTTP method (e.g., GET) to the endpoint.
    • Verify that the endpoint returns a 405 Method Not Allowed status code.
    • Confirm that the response body contains an appropriate error message.
  5. Bad Request

    • Send a request with invalid data (e.g., missing required fields) to the endpoint.
    • Verify that the endpoint returns a 400 Bad Request status code.
    • Confirm that the response body contains an appropriate error message.

LINKS

link to the issue that implement the sending of the email in the background using Celery and RabbitMq https://github.com/hngprojects/hng_boilerplate_nestjs/issues/254#issue-2418183784

markessien commented 1 month ago

Appears VERY duplicated

PcNerd9 commented 1 month ago

you commented on the previous issue created for this feature that the issue should be divided into two:

  1. The email is placed in a db queue for sending
  2. The email is retrieved from queue and dispatched. So that's issue was closed and i created two new issues to fit this requirements. One of the issues is this issue. I had gone through all the issues that's been created and accepted before creating this issue to avoid duplicate. In short, this issue is not a duplicate sir
highb33kay commented 1 month ago

Can you link both issues and I will review asap

PcNerd9 commented 1 month ago

https://github.com/hngprojects/hng_boilerplate_nestjs/issues/254#issue-2418183784

link to the issue that implement the sending of the email in the background using Celery and RabbitMq

highb33kay commented 1 month ago

I have seen both. Can you explain the difference because I dont see it? @PcNerd9

PcNerd9 commented 1 month ago

The simple explanation of the first issue:

Simple explanation of the second issue:

Below is the link of the original issue where mark commented on saying that i should split into two tickets. https://github.com/hngprojects/hng_boilerplate_nestjs/issues/242#issue-2417496562 Hope this answer your question sir @highb33kay