Skip to content

[TESTING] Restructure tests into modular suites #13

@democratize-technology-code-reviewer

Description

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 files organized by service (one test file per service)
  • Shared test utilities extracted (fixtures, mocks, helpers)
  • Mock factory pattern implemented for Grocy entities
  • Test environments configured (unit, integration, e2e)
  • Integration tests run against Docker Grocy instance
  • E2E tests cover critical user workflows
  • Test execution time reduced by 50% through parallelization
  • Test documentation explains testing strategy
  • CI/CD runs appropriate test suites per environment
  • No flaky tests (all tests pass consistently)

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions