2. API Endpoint Testing Guide - sahilshityalkar/Digitalcube-Task-Event-Management-API GitHub Wiki

2.1 Overview

After setting up the project, you can test the API endpoints using Postman. Below are the steps and details for each endpoint.

2.2 POST /events

Create a New Event

Postman Setup:

Without Banner Image:

  • URL: http://localhost:5000/api/events
  • Method: POST
  • Body:
    • Select raw and set the format to JSON.
    • Example: copy and paste
 {
  "name": "Tech Conference 2024",
  "description": "An event to showcase latest in technology.",
  "date": "2024-12-15",
  "location": "San Francisco, CA"
 }

With Banner Image:

  • Select: form-data.
  • Add fields:
    • Key: name (Type: Text), Value: "Tech Conference 2024"
    • Key: description (Type: Text), Value: "An event to showcase the latest in technology."
    • Key: date (Type: Text), Value: "2024-12-15"
    • Key: location (Type: Text), Value: "San Francisco, CA"
    • Key: image (Type: File), Value: Choose a file from your computer

Expected Output:

{
  "message": "Event created successfully",
  "event": {
    "_id": "event_id",
    "name": "Tech Conference 2024",
    "description": "An event to showcase the latest in technology.",
    "date": "2024-12-15T00:00:00.000Z",
    "location": "San Francisco, CA",
    "imageUrl": "path_to_image",
    "__v": 0
  }
}

demo postman image for create new event

2.3 GET /events

Retrieve a List of Events

Postman Setup:

  • URL: http://localhost:5000/api/events
  • Method: GET

Expected Output:

{
  "totalEvents": 2,
  "page": 1,
  "totalPages": 1,
  "events": [
    {
      "_id": "event_id",
      "name": "Tech Conference 2024",
      "description": "An event to showcase the latest in technology.",
      "date": "2024-12-15T00:00:00.000Z",
      "location": "San Francisco, CA"
    }
  ]
}

demo postman image for Retrieve a List of Events

2.4 GET /events/:id

Retrieve Event Details by ID

Postman Setup:

  • URL: http://localhost:5000/api/events/:id
    • Replace :id with the actual event ID, e.g., http://localhost:5000/api/events/64f0b97e2f9b3c2a4c123456
  • Method: GET

Expected Output:

{
  "_id": "64f0b97e2f9b3c2a4c123456",
  "name": "Tech Conference 2024",
  "description": "An event to showcase the latest in technology.",
  "date": "2024-12-15T00:00:00.000Z",
  "location": "San Francisco, CA"
}

demo postman image for Retrieve event by id

2.5 PUT /events/:id

Update Event Details by ID

Postman Setup:

  • URL: http://localhost:5000/api/events/:id
    • Replace :id with the actual event ID, e.g., http://localhost:5000/api/events/64f0b97e2f9b3c2a4c123456
  • Method: PUT
  • Body Type: JSON
  • Body:
    • Select raw and set the format to JSON.
    • Example: copy and paste
{
  "name": "Updated Tech Conference 2024",
  "description": "An updated event description showcasing the latest in technology.",
  "date": "2024-12-20T00:00:00.000Z",
  "location": "Los Angeles, CA"
}

Expected Output:

{
    "message": "Event updated successfully",
    "event": {
        "_id": "66d8b069f5183259510d824b",
        "name": "Updated Tech Conference 2024",
        "description": "An updated event description showcasing the latest in technology.",
        "date": "2024-12-20T00:00:00.000Z",
        "location": "Los Angeles, CA",
        "imageUrl": null,
        "__v": 0
    }
}

demo postman image for Update event details by id

2.6 DELETE /events/:id

Delete an Event by ID

Postman Setup:

  • URL: http://localhost:5000/api/events/:id
    • Replace :id with the actual event ID, e.g., http://localhost:5000/api/events/64f0b97e2f9b3c2a4c123456
  • Method: DELETE

Expected Output:

{
    "message": "Event deleted successfully",
    "event": {
        "_id": "66d8b069f5183259510d824b",
        "name": "Updated Tech Conference 2024",
        "description": "An updated event description showcasing the latest in technology.",
        "date": "2024-12-20T00:00:00.000Z",
        "location": "Los Angeles, CA",
        "imageUrl": null,
        "__v": 0
    }
}

demo postman image for Delete an event by id

2.7 POST /events/:id/register

Register a User for the Event

Postman Setup:

  • URL: http://localhost:5000/api/events/:id/register
    • Replace :id with the actual event ID, e.g., http://localhost:5000/api/events/64f0b97e2f9b3c2a4c123456
  • Method: POST
  • Body: (raw JSON)
    {
    "name": "sahil shityalkar",
    "email": "[email protected]"
    }
    

Expected Output:

{
    "message": "Registration successful, confirmation email sent.",
    "registration": {
        "eventId": "66d9377710024f04be43ec35",
        "name": "sahil shityalkar",
        "email": "[email protected]",
        "_id": "66d9378c10024f04be43ec39",
        "__v": 0
    },
    "emailInfo": {
        "accepted": [
            "[email protected]"
        ],
        "rejected": [],
        "ehlo": [
            "PIPELINING",
            "8BITMIME",
            "SMTPUTF8",
            "AUTH LOGIN PLAIN"
        ],
        "envelopeTime": 608,
        "messageTime": 512,
        "messageSize": 843,
        "response": "250 Accepted [STATUS=new MSGID=Ztk2uCTOWZ3oEIw9Ztk3icGk0kDvMaraAAAAAkUk4uZTBwS1gsWERBlPR4o]",
        "envelope": {
            "from": "[email protected]",
            "to": [
                "[email protected]"
            ]
        },
        "messageId": "<[email protected]>"
    }
}

demo postman image for Register a user for the event

Additional Step: Verify Confirmation Email

After successfully registering a user, you should check the Ethereal inbox to verify that the confirmation email was sent. Follow these steps:

  1. Go to Ethereal's login page: Ethereal Login

  2. Log in using the Ethereal email credentials that you set up in the .env file:

    • Email: <your_ethereal_user>
    • Password: <your_ethereal_password>
  3. Check the inbox: You should see an email with the subject: Registration Confirmation.

  4. Open the email: Confirm that it contains the event details and verifies successful registration.

demo confirmation email ethereal

Note: There are many SMTP services available, but for testing purposes, we are using Ethereal in this project.