2.5 KiB
2.5 KiB
TASK-BE-014: Backend Testing & Documentation Strategy
Status: Draft Owner: TBD Priority: High Related:
specs/03-implementation/testing-strategy.mdspecs/03-implementation/backend-guidelines.md
🎯 Objective
Establish a robust safety net and comprehensive documentation for the Backend (NestJS). Goal: Quality First, Self-Documenting Code.
📋 Scope
1. Unit Testing (Target: 80% Coverage on Services)
Focus on Business Logic, not framework glue code.
-
[/] Unit Testing (Service Level):
DocumentNumberingService(Mock Redis/Redlock, Test Optimistic Lock).FileStorageService(Test Local Storage fs-extra).WorkflowEngineService(Test state transitions/Guard validation).AuthService(Critical: RBAC)
-
Feature Modules:
CorrespondenceService&CorrespondenceWorkflowServiceRfaService&RfaWorkflowServiceTransmittalService&CirculationService
2. Integration / E2E Testing (Target: Critical User Journeys)
Verify end-to-end flows using a Test Database (Dockerized MariaDB).
- Infrastructure:
- Ensure
docker-compose.test.ymlexists for isolated DB testing. - Setup Global Setup/Teardown for Jest E2E.
- Ensure
- Scenarios:
- Auth Flow: Login -> JWT -> RBAC Rejection.
- Document Lifecycle: Create -> Upload -> Submit -> Approve -> Complete.
- Search: Create Doc -> Wait -> Search (Elasticsearch Mock/Real).
3. Documentation
- [/] API Documentation (Swagger/OpenAPI):
- Ensure all DTOs have
@ApiProperty()(Verified in CreateCorrespondenceDto and others). - Ensure all Controllers have
@ApiOperation()and@ApiResponse()(Done for Auth & Correspondence). - Verify
http://localhost:3000/docscovers 100% of endpoints.
- Ensure all DTOs have
- [/] Code Documentation (Compodoc):
- Install
@compodoc/compodoc. - Configure
tsconfig.doc.json. - Add
npm run docscript. - Generate static HTML documentation.
- Install
🛠Implementation Details
Tools
- Unit/Integration:
jest,ts-jest,@nestjs/testing - E2E:
supertest - Docs:
@nestjs/swagger,@compodoc/compodoc
✅ Definition of Done
npm run testpasses (Unit Tests).npm run test:e2epasses (E2E Tests).npm run docgenerates valid HTML.- Swagger UI (
/docs) is complete and usable. - Testing Strategy Guide is updated if new patterns emerge.