# Test Coverage Audit - Quick Reference Guide

**Generated:** April 10, 2026  
**Repository:** GoodGo Platform AI Monorepo  
**Modules Audited:** Listings, Auth, Search

---

## 📊 Coverage Overview

| Module | Source Files | Test Files | Coverage | Status |
|--------|:----:|:----:|:---:|:---:|
| **Listings** | 42 | 13 | **31%** | ⚠️ Low |
| **Auth** | 56 | 21 | **38%** | ⚠️ Low |
| **Search** | 22 | 10 | **45%** | ⚠️ Low |
| **TOTAL** | **120** | **44** | **37%** | ⚠️ Low |

---

## 🔴 CRITICAL - Must Test First (11 files)

### AUTH Module - Security Critical (4 files)
```
1. presentation/guards/jwt-auth.guard.ts
   └─ Why: Token validation security
   └─ Test: Valid tokens, expired, invalid signatures

2. presentation/guards/roles.guard.ts
   └─ Why: Authorization enforcement
   └─ Test: Admin access, user access, denied access

3. infrastructure/repositories/prisma-user.repository.ts
   └─ Why: Primary user data access
   └─ Test: CRUD operations, user lookup queries

4. infrastructure/strategies/jwt.strategy.ts
   └─ Why: JWT authentication
   └─ Test: Token validation, user extraction
```

### LISTINGS Module - Business Logic Critical (4 files)
```
5. infrastructure/services/prisma-duplicate-detector.ts
   └─ Why: Core duplicate detection
   └─ Test: Database queries, similarity logic

6. infrastructure/services/prisma-price-validator.ts
   └─ Why: Price validation logic
   └─ Test: Price ranges, validation rules

7. infrastructure/repositories/prisma-listing.repository.ts
   └─ Why: Primary listing data access
   └─ Test: CRUD operations, complex queries

8. domain/services/moderation.service.ts
   └─ Why: Moderation business rules
   └─ Test: Approval/rejection logic, scoring
```

### SEARCH Module - Integration Critical (2 files)
```
9. infrastructure/services/typesense-client.service.ts
   └─ Why: Search engine integration
   └─ Test: Client init, connection, errors

10. infrastructure/services/postgres-search.repository.ts
    └─ Why: Fallback search implementation
    └─ Test: Query building, fallback logic
```

---

## 📋 Complete Listings Module Files

### ✅ Already Tested (13 files)

**Application Layer (8):**
- ✓ create-listing.handler.spec.ts
- ✓ get-listing.handler.spec.ts
- ✓ get-pending-moderation.handler.spec.ts
- ✓ moderate-listing.handler.spec.ts
- ✓ price-validator.spec.ts
- ✓ search-listings.handler.spec.ts
- ✓ update-listing-status.handler.spec.ts
- ✓ upload-media.handler.spec.ts

**Domain Layer (5):**
- ✓ duplicate-detector.spec.ts
- ✓ listing-events.spec.ts
- ✓ listing.entity.spec.ts
- ✓ property.entity.spec.ts
- ✓ value-objects.spec.ts

### ❌ Missing Tests (29 files)

**Domain Layer (10):**
- ✗ domain/services/moderation.service.ts [TIER 1]
- ✗ domain/repositories/listing.repository.ts (interface)
- ✗ domain/repositories/property.repository.ts (interface)
- ✗ domain/repositories/listing-read.dto.ts
- ✗ domain/events/listing-approved.event.ts
- ✗ domain/events/listing-sold.event.ts
- ✗ domain/events/listing-status-changed.event.ts
- ✗ domain/entities/* (already has tests - consolidate if needed)
- ✗ domain/value-objects/* (already has tests - consolidate if needed)
- ✗ domain/services/duplicate-detector.ts (has handler test, needs unit test)

**Application Layer (0 - All Covered):**
All handlers and commands are tested.

**Infrastructure Layer (6):**
- ✗ infrastructure/services/prisma-duplicate-detector.ts [TIER 1]
- ✗ infrastructure/services/prisma-price-validator.ts [TIER 1]
- ✗ infrastructure/services/media-storage.service.ts
- ✗ infrastructure/repositories/prisma-listing.repository.ts [TIER 1]
- ✗ infrastructure/repositories/prisma-property.repository.ts
- ✗ infrastructure/repositories/listing-read.queries.ts

**Presentation Layer (13):**
- ✗ listings.module.ts
- ✗ presentation/controllers/listings.controller.ts
- ✗ presentation/dto/create-listing.dto.ts
- ✗ presentation/dto/moderate-listing.dto.ts
- ✗ presentation/dto/search-listings.dto.ts
- ✗ presentation/dto/update-listing-status.dto.ts

---

## 📋 Complete Auth Module Files

### ✅ Already Tested (21 files)

**Application Layer (12):**
- ✓ cancel-user-deletion.handler.spec.ts
- ✓ export-user-data.handler.spec.ts
- ✓ force-delete-user.handler.spec.ts
- ✓ get-agent-by-user-id.handler.spec.ts
- ✓ get-profile.handler.spec.ts
- ✓ login-user.handler.spec.ts
- ✓ process-scheduled-deletions.handler.spec.ts
- ✓ refresh-token.handler.spec.ts
- ✓ register-user.handler.spec.ts
- ✓ request-user-deletion.handler.spec.ts
- ✓ verify-kyc.handler.spec.ts

**Infrastructure Layer (4):**
- ✓ google-oauth.strategy.spec.ts
- ✓ oauth.service.spec.ts
- ✓ token.service.spec.ts
- ✓ zalo-oauth.strategy.spec.ts

**Domain Layer (5):**
- ✓ auth-events.spec.ts
- ✓ email.vo.spec.ts
- ✓ hashed-password.vo.spec.ts
- ✓ phone.vo.spec.ts
- ✓ user.entity.spec.ts

**Integration (1):**
- ✓ auth.integration.spec.ts

### ❌ Missing Tests (35 files)

**Infrastructure Layer (6):**
- ✗ infrastructure/strategies/jwt.strategy.ts [TIER 1]
- ✗ infrastructure/strategies/local.strategy.ts
- ✗ infrastructure/repositories/prisma-user.repository.ts [TIER 1]
- ✗ infrastructure/repositories/prisma-refresh-token.repository.ts

**Presentation Layer (14):**
- ✗ presentation/guards/jwt-auth.guard.ts [TIER 1 - CRITICAL]
- ✗ presentation/guards/roles.guard.ts [TIER 1 - CRITICAL]
- ✗ presentation/guards/local-auth.guard.ts
- ✗ presentation/guards/google-oauth.guard.ts
- ✗ presentation/decorators/current-user.decorator.ts
- ✗ presentation/decorators/roles.decorator.ts
- ✗ presentation/controllers/auth.controller.ts
- ✗ presentation/controllers/oauth.controller.ts
- ✗ presentation/controllers/user-data.controller.ts
- ✗ presentation/dto/login.dto.ts
- ✗ presentation/dto/register.dto.ts
- ✗ presentation/dto/refresh-token.dto.ts
- ✗ presentation/dto/verify-kyc.dto.ts
- ✗ presentation/dto/force-delete-user.dto.ts
- ✗ presentation/dto/request-deletion.dto.ts

**Other (15):**
- ✗ auth.module.ts

---

## 📋 Complete Search Module Files

### ✅ Already Tested (10 files)

**Application Layer (4):**
- ✓ geo-search.handler.spec.ts
- ✓ reindex-all.handler.spec.ts
- ✓ search-properties.handler.spec.ts
- ✓ sync-listing.handler.spec.ts

**Infrastructure Layer (4):**
- ✓ listing-approved.handler.spec.ts
- ✓ listing-indexer.service.spec.ts
- ✓ resilient-search.repository.spec.ts
- ✓ typesense-search.repository.spec.ts

**Domain Layer (1):**
- ✓ search-domain.spec.ts

**Presentation Layer (1):**
- ✓ search.controller.spec.ts

### ❌ Missing Tests (12 files)

**Infrastructure Layer (3):**
- ✗ infrastructure/services/typesense-client.service.ts [TIER 1]
- ✗ infrastructure/services/postgres-search.repository.ts [TIER 1]
- ✗ infrastructure/event-handlers/listing-status-changed.handler.ts

**Presentation Layer (2):**
- ✗ presentation/dto/geo-search.dto.ts
- ✗ presentation/dto/search-properties.dto.ts

**Other (1):**
- ✗ search.module.ts

---

## 🎯 Implementation Roadmap

### Week 1 - Critical Security & Business Logic (11 files)
**Time: ~20-25 hours**

- [ ] **AUTH** - jwt-auth.guard.spec.ts (3h)
- [ ] **AUTH** - roles.guard.spec.ts (3h)
- [ ] **AUTH** - prisma-user.repository.spec.ts (3h)
- [ ] **AUTH** - jwt.strategy.spec.ts (3h)
- [ ] **LISTINGS** - prisma-duplicate-detector.spec.ts (2.5h)
- [ ] **LISTINGS** - prisma-price-validator.spec.ts (2.5h)
- [ ] **LISTINGS** - prisma-listing.repository.spec.ts (3h)
- [ ] **LISTINGS** - moderation.service.spec.ts (2.5h)
- [ ] **SEARCH** - typesense-client.service.spec.ts (2.5h)
- [ ] **SEARCH** - postgres-search.repository.spec.ts (2.5h)

### Week 2-3 - High Priority Infrastructure (9 files)
**Time: ~15-18 hours**

- [ ] **AUTH** - local.strategy.spec.ts (2.5h)
- [ ] **AUTH** - prisma-refresh-token.repository.spec.ts (2.5h)
- [ ] **AUTH** - local-auth.guard.spec.ts (2.5h)
- [ ] **AUTH** - google-oauth.guard.spec.ts (2.5h)
- [ ] **LISTINGS** - prisma-property.repository.spec.ts (2.5h)
- [ ] **LISTINGS** - listing-read.queries.spec.ts (2.5h)
- [ ] **LISTINGS** - media-storage.service.spec.ts (2h)
- [ ] **SEARCH** - listing-status-changed.handler.spec.ts (2h)

### Week 4 - Medium Priority (Controllers, Decorators)
**Time: ~12-15 hours**

- [ ] **AUTH** - auth.controller.spec.ts (2.5h)
- [ ] **AUTH** - oauth.controller.spec.ts (2.5h)
- [ ] **AUTH** - user-data.controller.spec.ts (2h)
- [ ] **AUTH** - current-user.decorator.spec.ts (1.5h)
- [ ] **AUTH** - roles.decorator.spec.ts (1.5h)
- [ ] **LISTINGS** - listings.controller.spec.ts (2.5h)
- [ ] **SEARCH** - Nothing here (controller already tested)

### Week 5+ - DTOs, Module Configuration, E2E Tests
**Time: ~10+ hours**

- [ ] All DTO validation tests (3-4 files per module)
- [ ] Module configuration tests
- [ ] End-to-end integration tests
- [ ] Full user flow tests

---

## 🧪 Test Type Guidelines

### Unit Tests (50 minutes per file avg)
**For:** Services, repositories, value objects, entities
```typescript
// Test structure
describe('ServiceName', () => {
  let service: ServiceName;
  let mockDependency: Mock;
  
  beforeEach(() => {
    mockDependency = mock();
    service = new ServiceName(mockDependency);
  });
  
  it('should handle success case', () => {});
  it('should handle error case', () => {});
});
```

### Integration Tests (60 minutes per file avg)
**For:** Repositories, event handlers, strategies
```typescript
// Test structure - usually with database/real service
describe('RepositoryName', () => {
  let repository: RepositoryName;
  let prisma: PrismaClient; // or real client
  
  beforeEach(async () => {
    await setupTestDatabase();
    repository = new RepositoryName(prisma);
  });
  
  afterEach(async () => {
    await cleanupTestDatabase();
  });
});
```

### Guard/Decorator Tests (30 minutes per file avg)
**For:** Guards, decorators, middleware
```typescript
// Test structure
describe('GuardName', () => {
  let guard: GuardName;
  let mockExecutionContext: Mock;
  
  it('should allow authorized requests', () => {});
  it('should deny unauthorized requests', () => {});
});
```

### Controller Tests (40 minutes per file avg)
**For:** REST controllers
```typescript
// Test structure
describe('ControllerName', () => {
  let controller: ControllerName;
  let mockService: Mock;
  
  it('should handle POST request', () => {});
  it('should return 400 for invalid input', () => {});
});
```

### DTO Tests (20 minutes per file avg)
**For:** Data validation objects
```typescript
// Test structure - focus on validation
describe('DtoName', () => {
  it('should validate correct data', () => {});
  it('should reject invalid email', () => {});
  it('should reject short password', () => {});
});
```

---

## 📊 Coverage by Architectural Layer

### Domain Layer
| Category | Listings | Auth | Search | Total | Coverage |
|----------|:---:|:---:|:---:|:---:|:---:|
| Entities | 3/3 ✓ | 1/1 ✓ | - | 4/4 | **100%** |
| Value Objects | 3/3 ✓ | 3/3 ✓ | 2/2 ✓ | 8/8 | **100%** |
| Services | 2/3 | - | - | 2/3 | **67%** |
| Repositories | 0/3 | 0/2 | 0/1 | 0/6 | **0%** |
| Events | 1/4 | 1/4 | - | 2/8 | **25%** |
| **Total Domain** | **9/16** | **5/10** | **2/3** | **16/29** | **55%** |

### Application Layer
| Category | Listings | Auth | Search | Total | Coverage |
|----------|:---:|:---:|:---:|:---:|:---:|
| Handlers | 8/8 ✓ | 12/12 ✓ | 8/8 ✓ | 28/28 | **100%** |
| Commands | - | - | - | - | **100%** |
| Queries | - | - | - | - | **100%** |
| **Total App** | **8/8** | **12/12** | **8/8** | **28/28** | **100%** |

### Infrastructure Layer
| Category | Listings | Auth | Search | Total | Coverage |
|----------|:---:|:---:|:---:|:---:|:---:|
| Repositories | 0/3 | 0/2 | 0/2 | 0/7 | **0%** |
| Services | 1/3 | 2/2 ✓ | 3/5 | 6/10 | **60%** |
| Strategies | - | 2/4 | - | 2/4 | **50%** |
| Event Handlers | - | - | 1/2 | 1/2 | **50%** |
| **Total Infra** | **1/6** | **4/8** | **4/9** | **9/23** | **39%** |

### Presentation Layer
| Category | Listings | Auth | Search | Total | Coverage |
|----------|:---:|:---:|:---:|:---:|:---:|
| Controllers | 0/1 | 0/3 | 1/1 ✓ | 1/5 | **20%** |
| Guards | - | 0/4 | - | 0/4 | **0%** |
| Decorators | - | 0/2 | - | 0/2 | **0%** |
| DTOs | 0/4 | 0/6 | 0/2 | 0/12 | **0%** |
| **Total Presentation** | **0/5** | **0/15** | **1/3** | **1/23** | **4%** |

### Summary
| Layer | Files | Tested | Coverage |
|-------|:---:|:---:|:---:|
| **Domain** | 29 | 16 | 55% |
| **Application** | 28 | 28 | 100% ✓ |
| **Infrastructure** | 23 | 9 | 39% |
| **Presentation** | 23 | 1 | 4% |
| **TOTAL** | **103** | **54** | **52%** |

---

## 📝 Notes

- Coverage percentages exclude index.ts barrel files
- Commands/Queries are tested via their handlers
- Abstract repository interfaces are not tested (only implementations)
- Integration tests marked separately from unit tests
- Estimated times assume Vitest/Jest experience

