Tests refactor

This commit is contained in:
Aerilyn Weber 2026-05-19 11:06:03 +09:00
parent 245520fb50
commit 99134d8556
165 changed files with 911 additions and 531 deletions

View file

@ -46,21 +46,24 @@ docker compose -f docker/docker-compose.yml up -d # Start all services
docker compose -f docker/docker-compose.yml down # Stop all services
```
## Implementation Workflow
## Implementation Workflow (TDD-First)
Every feature or phase implementation MUST start with a rigorous planning and design phase:
0. **Mandatory Planning (Grilling)**: Before starting any feature or bug fix, you MUST invoke the `grill-with-docs` skill.
- Run the skill using: `view_file` on `.agents/skills/grill-with-docs/SKILL.md` and follow its instructions.
- This session will stress-test your plan against the existing domain model, terminology, and documentation (`CONTEXT.md`, ADRs).
- Decisions must be crystallized and documentation (glossary/ADRs) updated before moving to implementation.
- Stress-test your plan against the existing domain model, terminology, and documentation (`CONTEXT.md`, ADRs, `docs/tdd-transition-plan.md`).
- Decisions must be crystallized and documentation updated before moving to implementation.
1. **Vertical Slice Implementation**: Follow this approach for the actual build:
2. **Database Layer**: Create the Mongoose schema and Repository in `packages/api`. All reads must use `.lean().exec()`.
3. **Service Layer**: Implement business logic in the Service class, using Awilix for constructor injection. Add unit tests.
4. **Route Layer**: Create the Fastify route plugin and register it. Add route tests (using `app.inject`).
5. **Web API Client**: Implement the frontend service in `packages/web/src/services/`. Add unit tests.
6. **Web UI**: Create the Next.js pages and components. Use Server Components by default. Add component tests (React Testing Library).
1. **Strict TDD Cycle**: All code changes must strictly follow the Red-Green-Refactor loop as detailed in [TDD Guide](docs/instructions/tdd.md). Do not write any production code before writing its failing test.
2. **Vertical Slice TDD Order**: Build each vertical slice following this exact test-first sequence:
- **Shared Layer**: Write validation schema tests first in `packages/shared/tests/` -> Implement schemas in `packages/shared/src/`.
- **Database Layer**: Write integration tests in `packages/api/tests/` using `mongodb-memory-server` -> Implement Mongoose schemas and Repository in `packages/api/src/`. All reads must use `.lean().exec()`.
- **Service Layer**: Write unit tests in `packages/api/tests/` using `createMockRepository` -> Implement business logic Service class in `packages/api/src/` with Awilix constructor injection.
- **Route Layer**: Write route tests in `packages/api/tests/` using `app.inject` -> Implement Fastify route plugin in `packages/api/src/`.
- **Web API Client**: Write service unit tests in `packages/web/tests/` using MSW mocking -> Implement the service client in `packages/web/src/`.
- **Web UI**: Write component tests in `packages/web/tests/` using React Testing Library -> Implement Next.js pages and components in `packages/web/src/`. Use Server Components by default.
**Verification Gate (Mandatory)**:
Before considering a task complete, run: