Overview
Restructure the monolithic 49,836-line test file into modular test suites that mirror the service architecture. This will improve maintainability, enable parallel test execution, and support different testing environments.
Objectives
- Organize tests by service modules
- Create shared test utilities and fixtures
- Implement integration tests against real Grocy instances
- Reduce test execution time by 50% through parallelization
Definition of Done
Test Structure
test/
├── unit/
│ ├── services/
│ │ ├── stock.service.test.ts
│ │ ├── user.service.test.ts
│ │ └── recipe.service.test.ts
│ └── utils/
├── integration/
│ ├── stock.integration.test.ts
│ └── docker-compose.yml
├── e2e/
│ ├── shopping-workflow.e2e.test.ts
│ └── inventory-management.e2e.test.ts
├── fixtures/
│ ├── products.json
│ └── stock.json
└── helpers/
├── mock-factory.ts
└── test-utils.ts
Mock Factory Pattern
export class MockFactory {
static createProduct(overrides?: Partial<Product>): Product {
return {
id: faker.number.int(),
name: faker.commerce.productName(),
location_id: 1,
qu_id_stock: 1,
...overrides
};
}
static createStockEntry(overrides?: Partial<StockEntry>): StockEntry {
// Implementation
}
}
Test Environment Configuration
// test/config/unit.config.js
export default {
testEnvironment: 'node',
testMatch: ['**/unit/**/*.test.ts'],
setupFiles: ['./test/setup/unit.ts']
};
// test/config/integration.config.js
export default {
testEnvironment: 'node',
testMatch: ['**/integration/**/*.test.ts'],
globalSetup: './test/setup/docker.ts',
testTimeout: 30000
};
Docker Setup for Integration Tests
version: '3.8'
services:
grocy:
image: grocy/grocy:latest
ports:
- "9283:80"
environment:
- GROCY_MODE=demo
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 5s
timeout: 3s
retries: 5
Related Issues
Depends on:
Code Lift
High - This requires careful migration of existing tests, creation of new test infrastructure, and setting up Docker-based integration testing. Estimated 20-30 hours.
Overview
Restructure the monolithic 49,836-line test file into modular test suites that mirror the service architecture. This will improve maintainability, enable parallel test execution, and support different testing environments.
Objectives
Definition of Done
Test Structure
Mock Factory Pattern
Test Environment Configuration
Docker Setup for Integration Tests
Related Issues
Depends on:
Code Lift
High - This requires careful migration of existing tests, creation of new test infrastructure, and setting up Docker-based integration testing. Estimated 20-30 hours.