Skip to content

Sneha/feature/auth#33

Closed
snehagopalappa wants to merge 7 commits into
masterfrom
sneha/feature/auth
Closed

Sneha/feature/auth#33
snehagopalappa wants to merge 7 commits into
masterfrom
sneha/feature/auth

Conversation

@snehagopalappa
Copy link
Copy Markdown
Collaborator

@snehagopalappa snehagopalappa commented Apr 20, 2026

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

image image image image image image image

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

@sandaliSS
Copy link
Copy Markdown
Collaborator

@snehagopalappa this needs unit and integration tests.

@nikhil-3210
Copy link
Copy Markdown
Collaborator

@snehagopalappa, Please update your branch with master branch

@snehagopalappa
Copy link
Copy Markdown
Collaborator Author

@snehagopalappa this needs unit and integration tests.

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.

@nikhil-3210 nikhil-3210 requested a review from AKV2703 May 13, 2026 10:00
@sandaliSS
Copy link
Copy Markdown
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.

@snehagopalappa
Copy link
Copy Markdown
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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants