Skip to content

Add Unit Tests for Domain Layer #6

@peter7775

Description

@peter7775

Add Unit Tests for Domain Layer

Description

Test coverage in the domain layer to ensure business logic reliability.

Testing Requirements

Domain Entities

  • Test entity creation and validation
  • Test entity methods and business rules
  • Edge cases and error conditions

Domain Models

  • Test transformation rules parsing
  • Test configuration validation
  • Test data mapping logic

Domain Aggregates

  • Test aggregate root behavior
  • Test business rule enforcement
  • Test domain events

Value Objects

  • Test immutability
  • Test validation rules
  • Test equality and comparison

Files Needing Tests

Priority 1: Core Entities and Models

internal/domain/
├── entities/
│   ├── base_entity.go (needs tests)
│   ├── graph.go (needs tests)
│   ├── node.go (needs tests)
│   └── relation.go (needs tests)
└── models/
    ├── config.go (needs tests)
    ├── database_config.go (needs tests)
    ├── database_schema.go (needs tests)
    ├── graph.go (needs tests)
    └── search.go (needs tests)

Priority 2: Aggregates and Services

internal/domain/
├── aggregates/
│   ├── graph/graph_aggregate.go (needs tests)
│   ├── serialization/id_generator.go (needs tests)
│   ├── serialization/serialization.go (needs tests)
│   └── transform/transform_rule_aggregate.go (needs tests)
└── services/
    └── graph_service.go (needs tests)

Priority 3: Value Objects and Events

internal/domain/
├── valueobjects/
│   ├── search_criteria.go (needs tests)
│   ├── transform_config.go (needs tests)
│   ├── visualization_criteria.go (needs tests)
│   └── transform/
│       ├── direction.go (needs tests)
│       ├── rule_parameters.go (needs tests)
│       └── rule_type.go (needs tests)
└── events/
    ├── domain_event.go (needs tests)
    └── node_events.go (needs tests)

Acceptance Criteria

  • Create test files for all domain entities (Priority 1)
  • Create test files for all domain models (Priority 1)
  • Create test files for domain aggregates (Priority 2)
  • Create test files for domain services (Priority 2)
  • Create test files for value objects (Priority 3)
  • Create test files for domain events (Priority 3)
  • Test all public methods and functions
  • Include edge cases and error scenarios
  • Achieve minimum 80% test coverage for domain layer
  • All tests pass in CI pipeline
  • Add table-driven tests where appropriate
  • Follow DDD testing patterns (test behavior, not implementation)

Technical Requirements

  • Use testify framework (already included in project)
  • Follow existing test patterns from other layers
  • Use mocks for external dependencies
  • Write descriptive test names following Go conventions
  • Test files should be named *_test.go in same package
  • Use test doubles for repositories and external services
  • Focus on testing business rules and domain logic

Commands for Development

# Run domain layer tests specifically
go test ./internal/domain/...

# Run with coverage
go test -cover ./internal/domain/...

# Run specific entity tests
go test ./internal/domain/entities/...
go test ./internal/domain/models/...

# Generate coverage report
make test

Dependencies

  • No external dependencies required
  • Can be developed incrementally
  • Should be completed before adding integration tests

Definition of Done

  • All domain layer files have corresponding test files
  • Test coverage reports show >80% for domain package
  • All tests pass locally and in CI
  • Code review completed

Metadata

Metadata

Assignees

Labels

backendBackend/server related workcode-qualityCode quality improvements and best practicesgood-first-issueGood for newcomers - easy to understand and implementtestingTesting related work - unit tests, integration tests, etc.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions