Skip to content

Conversation

Copy link

Copilot AI commented Sep 5, 2025

This PR introduces a comprehensive testing prompt system that enables consistent test generation across all architectural layers of the MAD-AI project while ensuring compliance with Clean Architecture and Domain-Driven Design principles.

Problem Solved

The project needed a structured approach to generate tests that:

  • Respect the architectural boundaries between layers (Domain, Application, Infrastructure, Presentation, Core)
  • Follow layer-specific testing strategies as defined in the project documentation
  • Ensure compliance with Clean Architecture dependency flows
  • Maintain consistent quality and coverage standards across the codebase

Solution

🧪 Test Generation Prompt (test-generation-prompt.md)

A comprehensive prompt that provides layer-specific testing strategies:

Domain Layer - Pure unit tests focusing on business logic:

// Tests business rules without external dependencies
it('should allow role change when user has permission', () => {
  const user = new User({ role: Role.MANAGER, permissions: [Permission.MANAGE_ROLES] });
  const result = user.changeRole(Role.ADMIN);
  expect(result.isSuccess).toBe(true);
  expect(user.getDomainEvents()).toContain(UserRoleChangedEvent);
});

Application Layer - Orchestration tests with mocked dependencies:

// Tests use case coordination with proper mocking
it('should create user successfully when valid command provided', async () => {
  mockUserRepository.findByEmail.and.returnValue(of(null));
  mockRoleRepository.findById.and.returnValue(of(validRole));
  
  const result = await useCase.execute(command);
  expect(result.isSuccess).toBe(true);
  expect(mockEventBus.publish).toHaveBeenCalled();
});

Infrastructure Layer - Integration tests with HTTP mocking:

// Tests API integration with HttpClientTestingModule
it('should fetch user and transform to domain entity', async () => {
  const req = httpMock.expectOne('/api/users/1/');
  req.flush(mockUserDTO);
  
  const user = await repository.findById(1);
  expect(user.email).toBe('test@example.com');
});

📖 Usage Guide (test-prompt-usage-guide.md)

Practical implementation guide with:

  • Step-by-step instructions for each layer
  • Quality validation checklists
  • Common anti-patterns and warning signals
  • Real-world examples and troubleshooting tips

Key Features

Architectural Compliance: Validates dependency flows and layer responsibilities
Coverage Standards: Defines specific coverage targets per layer (Domain: 95-100%, Application: 85-95%)
Quality Assurance: Includes validation checklists and anti-pattern detection
Immediate Usability: Ready-to-use templates and examples for all file types

Usage Example

# For a Domain entity
"Generate tests for src/app/domain/entities/user.entity.ts following Domain Layer rules:
- Pure unit tests (no mocks)
- Validate business rules and invariants
- Test domain events emission
- Coverage target: 95-100%"

# For an Application use case  
"Generate tests for src/app/application/use-cases/create-user.usecase.ts following Application Layer rules:
- Mock all dependencies
- Test orchestration flow
- Validate error handling
- Coverage target: 85-95%"

This prompt system ensures that every test generated maintains the architectural integrity of the MAD-AI project while providing comprehensive coverage of functionality across all layers.

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@dev-sandoval dev-sandoval marked this pull request as ready for review September 5, 2025 03:24
@dev-sandoval dev-sandoval merged commit 7ed460b into refactor-auth Sep 5, 2025
1 check passed
Copilot AI changed the title [WIP] Generación de un Prompt para Pruebas por Capa Create comprehensive test generation prompt for MAD-AI Clean Architecture layers Sep 5, 2025
Copilot AI requested a review from dev-sandoval September 5, 2025 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants