Skip to content

Sprint2

Hamsini Sivalenka edited this page Mar 4, 2025 · 4 revisions

Sprint 2 Report - Sportify

Work Completed in Sprint 2

During Sprint 2, our backend team focused on enhancing authentication, implementing profile management, improving API documentation, and ensuring better test coverage. Our frontend team worked on integrating the backend with the frontend and implemented unit and Cypress tests.

1. Backend Enhancements

  • Implemented JWT-based authentication: Users receive a JWT token upon signup/login, which is required for accessing protected endpoints.
  • Profile Management APIs:
    • POST /profile: Creates a new user profile.
    • GET /profile: Fetches user profile with authentication.
    • PUT /profile: Allows updating user details securely.
  • API Documentation: We integrated Swagger UI to document all backend endpoints for better usability.
  • Unit Testing: Developed unit tests for authentication, profile management, and API responses.

2. Frontend Enhancements

  • Integration with Backend: The frontend now communicates with the backend over localhost:8080.
  • Login Process Demonstration: The login form sends credentials to the backend, receives a JWT token, and stores it for authenticated API requests.
  • Addition of "Find" page: now you can find and search for events the events going on around you.
  • Testing Implementation:
    • Cypress Test: A basic test that verifies UI elements and API interactions.
    • Unit Tests: Implemented unit tests with a 1:1 function-to-test ratio.

3. Unit Tests & Cypress Test

Frontend Tests

  • Cypress Test:

    • A simple Cypress test that verifies the application pages functionality.
    • Login Page Tests: should load the login page successfully, allow user to enter and click buttons, and navigate to different pages.
    • Register Component Tests: should render the Register page correctly, allow to type, disable register if incomplete and show validation errors, and navigate to different pages.
    • Profile Component Tests: should render the profile form correctly, allow user to select or deselect or enter text, open drop downs, and submit form.
    • Main Page Unit Tests: should render the navigation bar correctly and navigate to different pages correctly.
    • Forgot Password Page Unit Tests: should render the forgot password form correctly, allow user to enter and navigate.
  • Unit Tests: Implemented tests for React components and API calls. This one was done using both Jest and Cypress.

    • Login Page Unit Tests
      • should render the login form correctly
      • should allow user to enter email and password
      • should navigate to /home when login button is clicked
      • should navigate to /register when 'Click here' is clicked
      • should navigate to /forgotpass when 'forgot password' is clicked
    • Profile Page Unit Tests
      • should render the profile form correctly
      • should allow user to enter profile details
      • should allow user to select gender
      • should open and close sports dropdown
      • should allow user to select and deselect sports preferences
      • should navigate to /home when form is submitted
    • Register Page Unit Tests
      • should render the register form correctly
      • should allow user to enter email and validate input
      • should allow user to enter password and validate input
      • should validate confirm password field
      • should navigate to /Profile when Register button is clicked
    • Main Page Unit Tests
      • should render the main page correctly
      • should navigate to /Main when Home button is clicked
      • should navigate to /Login when Log In button is clicked
      • should navigate to /Register when Get Started button is clicked
      • should navigate to /Register when GET STARTED button in the body is clicked
    • Forgot Password Page Unit Tests
      • should render the forgot password form correctly
      • should allow user to enter email
      • should show alert when reset password is clicked
      • should navigate to /login when 'Cancel' is clicked

Backend Tests

  • Unit Tests:
    • api_test
      • Should return 200 OK for the /v1/health route to confirm the application is running correctly.
      • Should allow user registration via the /v1/auth/signup route and return 201 Created.
      • Should start the application and ensure the /v1/health endpoint is reachable.
    • health_test
      • Should return 200 OK for the /health endpoint to confirm the service is running.
      • Should return the response body "OK" to indicate a successful health check.
    • json_test
      • Should return 200 OK and a valid JSON response when calling writeJSON.
      • Should return 400 Bad Request with an error message when calling writeJSONError.
      • Should correctly parse a valid JSON request body using readJSON.
      • Should return an error for unknown fields in JSON when calling readJSON.
      • Should return an error for malformed JSON when calling readJSON.
      • Should return an error when JSON input exceeds the max byte limit in readJSON.
      • Should return 200 OK with properly formatted JSON data when calling jsonResponse.
    • main_test
      • Should load configuration correctly from environment variables.
      • Should initialize a mock database connection using sqlmock.
      • Should return an error when database initialization fails due to an empty address.
      • Should initialize the logger successfully.
      • Should initialize the storage layer with a mock database.
      • Should initialize the JWT authenticator with a valid secret and issuer.
      • Should successfully initialize the application with mock dependencies.
    • docs_test
      • Should ensure SwaggerInfo is initialized correctly.
      • Should verify that SwaggerInfo.Title is set to "Sportify".
      • Should confirm SwaggerInfo.BasePath is "/v1".
      • Should validate that SwaggerInfo.Description matches the expected API description.
      • Should check that the Swagger template is not empty.
      • Should confirm that the Swagger template contains the correct Swagger version ("swagger": "2.0").
    • jwt_test
      • Should initialize a new JWT authenticator with the correct secret, audience, and issuer.
      • Should generate a valid JWT token without errors.
      • Should validate a correctly signed JWT token and extract expected claims.
      • Should return an error when validating an invalid JWT token.
      • Should mark a token as invalid when using an incorrect secret.
    • db_test
      • Should return an error when initializing the database with an invalid connection string.
      • Should return an error when the idle time duration format is incorrect.
    • env_test
      • Should return the correct string value from the environment variable.
      • Should return the fallback string value when the environment variable is not set.
      • Should return the correct integer value from the environment variable.
      • Should return the fallback integer value when the environment variable is not set.
      • Should return the fallback integer value when the environment variable contains a non-integer value.
    • profile_test
      • Should successfully create a new profile entry in the database.
      • Should retrieve a profile by email with the expected data.
      • Should update an existing profile and return the updated timestamp.
    • storage_test
      • Should initialize storage with Users and Profile stores.
      • Should successfully commit a transaction when no errors occur in withTx.
      • Should rollback a transaction when an error occurs in withTx.
      • Should fail to start a transaction and return an error when withTx encounters a transaction start failure.
    • user_test
      • Should successfully create a new user in the database.
      • Should return an error when creating a user with a duplicate email.
      • Should retrieve a user by ID with the expected data.
      • Should return an error when retrieving a non-existent user by ID.
      • Should retrieve a user by email with the expected data.
      • Should return an error when retrieving a non-existent user by email.

4. API Documentation & Backend Endpoints

We used Swagger UI to document all backend API endpoints. To access the Swagger UI and test all API calls, start the backend server using the air command and visit:
http://localhost:8080/v1/swagger/index.html#/

Authentication APIs

POST /auth/signup

  • Description: Registers a user and returns a JWT token.
  • Required Body:
    {
      "email": "user@example.com",
      "password": "securepassword"
    }
  • Success Response (201):
    {
      "token": "JWT_TOKEN_HERE"
    }
  • Error Responses:
    • 400 Bad Request: Missing fields or invalid data.
    • 500 Internal Server Error: Server failure.

POST /auth/login

  • Description: Logs in a user and returns a JWT token.
  • Required Body:
    {
      "email": "user@example.com",
      "password": "securepassword"
    }
  • Success Response (200):
    {
      "token": "JWT_TOKEN_HERE"
    }
  • Error Responses:
    • 400 Bad Request: Missing fields or invalid format.
    • 401 Unauthorized: Invalid credentials.
    • 500 Internal Server Error: Server failure.

Profile Management APIs

POST /profile

  • Description: Creates a user profile.
  • Headers:
    Authorization: Bearer JWT_TOKEN_HERE
    
  • Required Body:
    {
      "email": "user@example.com",
      "first_name": "John",
      "last_name": "Doe",
      "age": 25,
      "gender": "Male",
      "sport_preference": ["Football", "Tennis"]
    }
  • Success Response (201):
    {
      "data": {
        "email": "user@example.com",
        "first_name": "John",
        "last_name": "Doe",
        "age": 25,
        "gender": "Male",
        "sport_preference": ["Football", "Tennis"]
      }
    }
  • Error Responses:
    • 400 Bad Request: Missing fields or invalid data.
    • 401 Unauthorized: Invalid or missing token.
    • 409 Conflict: Profile already exists.
    • 500 Internal Server Error: Server failure.

GET /profile

  • Description: Fetches the authenticated user's profile.
  • Headers:
    Authorization: Bearer JWT_TOKEN_HERE
    
  • Success Response (200):
    {
      "data": {
        "email": "user@example.com",
        "first_name": "John",
        "last_name": "Doe",
        "age": 25,
        "gender": "Male",
        "sport_preference": ["Football", "Tennis"]
      }
    }
  • Error Responses:
    • 401 Unauthorized: Invalid or missing token.
    • 500 Internal Server Error: Server failure.

PUT /profile

  • Description: Updates the authenticated user's profile.
  • Headers:
    Authorization: Bearer JWT_TOKEN_HERE
    
  • Required Body:
    {
      "first_name": "John",
      "last_name": "Doe",
      "age": 26,
      "gender": "Male",
      "sport_preference": ["Football", "Tennis"]
    }
  • Success Response (200):
    {
      "data": {
        "email": "user@example.com",
        "first_name": "John",
        "last_name": "Doe",
        "age": 26,
        "gender": "Male",
        "sport_preference": ["Football", "Tennis"]
      }
    }
  • Error Responses:
    • 400 Bad Request: Missing fields or invalid data.
    • 401 Unauthorized: Invalid or missing token.
    • 500 Internal Server Error: Server failure.

Github Repository Link

Here's our Github Repository for Sportify - Sportify Repo

Github Project

Here's our Github Project Board - Sportify Project Board

Docs

The current document can be found in our Github Wiki Page