-
Notifications
You must be signed in to change notification settings - Fork 1
Sprint2
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.
- 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.
-
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.
-
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
- Login Page Unit Tests
-
Unit Tests:
- api_test
- Should return
200 OKfor the/v1/healthroute to confirm the application is running correctly. - Should allow user registration via the
/v1/auth/signuproute and return201 Created. - Should start the application and ensure the
/v1/healthendpoint is reachable.
- Should return
- health_test
- Should return
200 OKfor the/healthendpoint to confirm the service is running. - Should return the response body
"OK"to indicate a successful health check.
- Should return
- json_test
- Should return
200 OKand a valid JSON response when callingwriteJSON. - Should return
400 Bad Requestwith an error message when callingwriteJSONError. - 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 OKwith properly formatted JSON data when callingjsonResponse.
- Should return
- 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
SwaggerInfois initialized correctly. - Should verify that
SwaggerInfo.Titleis set to"Sportify". - Should confirm
SwaggerInfo.BasePathis"/v1". - Should validate that
SwaggerInfo.Descriptionmatches 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").
- Should ensure
- 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
UsersandProfilestores. - 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
withTxencounters a transaction start failure.
- Should initialize storage with
- 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.
- api_test
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#/
- 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.
-
- 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.
-
- 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.
-
- 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.
-
- 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.
-
Here's our Github Repository for Sportify - Sportify Repo
Here's our Github Project Board - Sportify Project Board
The current document can be found in our Github Wiki Page