Sneha/feature/auth#33
Closed
snehagopalappa wants to merge 7 commits into
Closed
Conversation
Collaborator
|
@snehagopalappa this needs unit and integration tests. |
Collaborator
|
@snehagopalappa, Please update your branch with master branch |
Collaborator
Author
Unit and integration tests have been added. 4 unit tests covering the service layer and 6 integration tests covering all validation scenarios. Test environment setup files also included for the team. |
Collaborator
|
@snehagopalappa Could you please upate your branch with latest master version. Most of your test configurations should be redundant now, Please have a look. |
Collaborator
Author
|
Closing this pr. The validation, password hashing and duplicate check logic from this register endpoint has been integrated into POST /users in the user management module instead(pr #54). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updated Summary
Implemented the user registration API endpoint for the TreeO2 backend, with full test coverage, Swagger documentation, and test environment setup.
Changes
Registration API:
auth.types.ts: added RegisterRequestBody and RegisterResponse interfaces
auth.schemas.ts : added registerSchema with Zod validation
auth.repository.ts : added findUserByEmail(), findRoleByName(), createUser() methods
auth.service.ts : added register() with full business logic
auth.controller.ts : added register() method
auth.routes.ts : added POST /auth/register route
auth.docs.ts : added Swagger documentation for register endpoint
Test Coverage:
tests/unit/auth.test.ts : 4 unit tests for AuthService.register()
tests/integration/auth.test.ts : 6 integration tests for POST /auth/register
Test Environment Setup:
tests/setup.ts : configures environment variables for test runner
jest.config.js : updated to wire setup file and test tsconfig
tsconfig.test.json : TypeScript config for test files
.env.test.example : template for teammates to set up test environment
Validation Rules
name - min 1, max 100 characters
email - valid format, max 300 characters, unique
password - min 8, max 72 (bcrypt limit), must contain uppercase, number and special character
role - must be one of FARMER, INSPECTOR, MANAGER, ADMIN, DEVELOPER
Test Coverage
Valid registration → 201 success
Duplicate email → 409 DATA_002
Weak password → 400 VAL_001 with detailed errors
Invalid role → 400 VAL_001 with enum error
Password hash never exposed in response
Tested locally and through Docker and Swagger
Screenshots
Notes
Roles table must be seeded before registration works, DB lead has been notified to update seed.ts
requestId included in all error responses for traceability