Skip to content

Implement Integration Tests for Core User and Mentor Workflows #72

@rishabh0510rishabh

Description

@rishabh0510rishabh

Problem Statement

As the Ment2Be backend logic expands, the risk of introducing regressions during refactoring or feature additions increases. Currently, there is no automated mechanism to verify that critical workflows—specifically User Authentication and Mentor Profile creation—function as expected. Relying on manual testing (e.g., via Postman) is time-consuming and prone to human error.

Current Behavior / Limitation

  • The project currently lacks an automated integration testing framework.
  • There are no scripts in package.json to execute a test suite.
  • API validation is manual, meaning bugs in the authentication or mentor onboarding flow might go unnoticed until deployment.

Expected Improvement

  • A testing environment using Jest and Supertest should be established.
  • Automated integration tests should verify that API endpoints return the correct HTTP status codes (200, 201, 400, 401) and data structures.
  • Running npm test should execute these tests and provide a pass/fail report.

Proposed Approach

  1. Dependencies: Install jest, supertest, and cross-env (if needed for environment variables) as dev dependencies.
  2. Configuration: Update package.json to include a test script (e.g., "test": "jest"). Ensure the tests run in a test environment (connecting to a test database or an in-memory database instance is recommended to avoid polluting development data).
  3. Auth Tests (server/tests/auth.test.js):
    • Test POST endpoint for User Signup (verify successful creation and duplicate user error).
    • Test POST endpoint for User Login (verify token receipt on success and 401 on bad credentials).
  4. Mentor Tests (server/tests/mentor.test.js):
    • Test endpoints related to creating or updating a Mentor profile.
    • Ensure proper authorization headers are mocked or passed during the test.

Verification Steps

To verify that the testing suite is implemented correctly, follow these steps:

  1. Clone the repository and switch to the contribution branch.
  2. Run npm install to ensure testing dependencies are present.
  3. Execute the test suite by running:
    npm test
  4. Success Condition:
    • The terminal should display a list of tests with Green checkmarks.
    • The output should show a summary (e.g., Tests: 5 passed, 5 total).
    • No actual production data should be modified during the test run.

label ECWoC26

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions