-
Notifications
You must be signed in to change notification settings - Fork 1
Sprint2
Hamsini Sivalenka edited this page Mar 3, 2025
·
4 revisions
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.
-
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 login functionality.
- Unit Tests: Implemented tests for React components and API calls.
-
Authentication Tests:
- Ensured proper JWT generation and validation.
- Tested login/signup error handling.
-
Profile API Tests:
- Verified POST, GET, and PUT operations for profile management.
- Ensured unauthorized requests fail correctly.
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.
-