add tests
Some checks failed
Contract Testing / contract-tests (push) Failing after 6m7s
Contract Testing / contract-snapshot (push) Failing after 4m46s

This commit is contained in:
2026-01-22 11:52:42 +01:00
parent 40bc15ff61
commit fb1221701d
112 changed files with 30625 additions and 1059 deletions

View File

@@ -2,37 +2,155 @@
## Directory Structure
This directory contains test placeholder files for services in `apps/website/app/auth`.
This directory contains comprehensive test implementations for auth services located in `apps/website/lib/services/auth/`.
## Note
## Auth Services
There are **no service files** in `apps/website/app/auth`. The directory only contains:
- Page components (e.g., `login/page.tsx`, `signup/page.tsx`)
- Layout files (e.g., `layout.tsx`)
The auth services are located in:
- `apps/website/lib/services/auth/AuthService.ts` - Handles authentication operations (signup, login, logout, password reset)
- `apps/website/lib/services/auth/SessionService.ts` - Handles session management
- `apps/website/lib/services/auth/AuthPageService.ts` - Processes URL parameters for auth pages
## Actual Auth Services
## Test Files
The actual auth services are located in:
- `apps/website/lib/services/auth/AuthService.ts`
- `apps/website/lib/services/auth/SessionService.ts`
- `apps/website/lib/services/auth/AuthPageService.ts`
The following comprehensive test files have been implemented:
These services already have test implementations in:
- `apps/website/lib/services/auth/AuthService.test.ts`
- `apps/website/lib/services/auth/SessionService.test.ts`
### AuthService.test.ts
Tests for authentication operations:
- **Happy paths**: Successful signup, login, logout, forgot password, reset password, and session retrieval
- **Failure modes**:
- Validation errors (invalid email, weak password)
- Authentication errors (invalid credentials, account locked)
- Server errors (internal server errors, network errors)
- Rate limiting errors
- Token validation errors
- **Decision branches**:
- Different user data structures
- Different email formats
- Different token formats
- Different response formats
- Empty display names
- Special characters in display names
- **Aggregation logic**: Proper aggregation of API responses into SessionViewModel
## Test Coverage
### SessionService.test.ts
Tests for session management:
- **Happy paths**: Successful session retrieval, null session handling
- **Failure modes**:
- Server errors
- Network errors
- Authentication errors
- Timeout errors
- Unexpected error types
- **Decision branches**:
- Different user data structures
- Different email formats
- Different token formats
- Special characters in display names
- Empty user data
- Missing token
- **Aggregation logic**: Proper aggregation of session data into SessionViewModel
The existing tests cover:
- **Happy paths**: Successful signup, login, logout, and session retrieval
- **Failure modes**: Error handling when API calls fail
- **Retries**: Not applicable for these services (no retry logic)
- **Fallback logic**: Not applicable for these services
- **Aggregation logic**: Not applicable for these services
- **Decision branches**: Different outcomes based on API response (success vs failure)
### AuthPageService.test.ts
Tests for auth page parameter processing:
- **Happy paths**:
- Login page parameter processing
- Forgot password page parameter processing
- Reset password page parameter processing
- Signup page parameter processing
- **Failure modes**:
- Missing reset token validation
- Empty token validation
- Null token validation
- **Decision branches**:
- Different returnTo paths
- Different token formats
- Special characters in paths
- Null/undefined/empty returnTo values
- Different returnTo values and hasInsufficientPermissions combinations
- **Aggregation logic**: Proper aggregation of page parameters into DTOs
## Future Services
## Test Coverage Summary
If service files are added to `apps/website/app/auth` in the future, corresponding test placeholder files should be created here following the pattern:
- Service file: `apps/website/app/auth/services/SomeService.ts`
- Test file: `apps/website/tests/services/auth/SomeService.test.ts`
The comprehensive test suite covers:
### Happy Paths ✓
- Successful authentication operations (signup, login, logout)
- Successful password reset flow (forgot password, reset password)
- Successful session retrieval
- Successful page parameter processing
### Failure Modes ✓
- Validation errors (invalid email, weak password, missing token)
- Authentication errors (invalid credentials, account locked)
- Server errors (internal server errors)
- Network errors
- Rate limiting errors
- Timeout errors
- Unexpected error types
### Retries ✓
- Not applicable for these services (no retry logic implemented)
### Fallback Logic ✓
- Not applicable for these services (no fallback logic implemented)
### Aggregation Logic ✓
- Proper aggregation of API responses into SessionViewModel
- Proper aggregation of page parameters into DTOs
- Handling of empty/missing data
- Default value handling
### Decision Branches ✓
- Different user data structures
- Different email formats
- Different token formats
- Different returnTo paths
- Special characters in paths and display names
- Null/undefined/empty values
- Different response formats
- Different status values
## Running Tests
Run the auth service tests using vitest:
```bash
# Run all tests
npm run test
# Run only auth service tests
npm run test -- apps/website/tests/services/auth
# Run with coverage
npm run test -- --coverage
# Run in watch mode
npm run test -- --watch
```
## Test Structure
Each test file follows a consistent structure:
- **describe blocks**: Organized by service method
- **happy paths**: Successful operations
- **failure modes**: Error handling scenarios
- **decision branches**: Different input variations
- **aggregation logic**: Data aggregation and transformation
- **error handling**: Unexpected error scenarios
## Mocking Strategy
All tests use mocked API clients:
- `AuthApiClient` is mocked to simulate API responses
- Mocks are created using Vitest's `vi.fn()`
- Each test has isolated mocks via `beforeEach()`
- Mocks simulate both success and failure scenarios
## Dependencies
The tests use:
- Vitest for test framework
- TypeScript for type safety
- Mocked dependencies for isolation
- No external API calls (all mocked)