# Test Coverage Analysis & Gap Report

## 1. Executive Summary
We have compared the existing E2E and Integration tests against the core concepts defined in [`docs/concept/`](docs/concept) and the testing principles in [`docs/TESTING_LAYERS.md`](docs/TESTING_LAYERS.md). 

While the functional coverage is high, there are critical gaps in **Integration Testing** specifically regarding external boundaries (iRacing API) and specific infrastructure-heavy business logic (Rating Engine).

## 2. Concept vs. Test Mapping

| Concept Area | E2E Coverage | Integration Coverage | Status |
|--------------|--------------|----------------------|--------|
| **League Management** | [`leagues/`](tests/e2e/leagues) | [`leagues/`](tests/integration/leagues) | ✅ Covered |
| **Season/Schedule** | [`leagues/league-schedule.spec.ts`](tests/e2e/leagues/league-schedule.spec.ts) | [`leagues/schedule/`](tests/integration/leagues/schedule) | ✅ Covered |
| **Results Import** | [`races/race-results.spec.ts`](tests/e2e/races/race-results.spec.ts) | [`races/results/`](tests/integration/races/results) | ⚠️ Missing iRacing API Integration |
| **Complaints/Penalties** | [`leagues/league-stewarding.spec.ts`](tests/e2e/leagues/league-stewarding.spec.ts) | [`races/stewarding/`](tests/integration/races/stewarding) | ✅ Covered |
| **Team Competition** | [`teams/`](tests/e2e/teams) | [`teams/`](tests/integration/teams) | ✅ Covered |
| **Driver Profile/Stats** | [`drivers/`](tests/e2e/drivers) | [`drivers/profile/`](tests/integration/drivers/profile) | ✅ Covered |
| **Rating System** | None | None | ❌ Missing |
| **Social/Messaging** | None | None | ❌ Missing |

## 3. Identified Gaps in Integration Tests

According to [`docs/TESTING_LAYERS.md`](docs/TESTING_LAYERS.md), integration tests should protect **environmental correctness** (DB, external APIs, Auth).

### 🚨 Critical Gaps (Infrastructure/Boundaries)
1. **iRacing API Integration**: 
   - *Concept*: [`docs/concept/ADMINS.md`](docs/concept/ADMINS.md:83) (Automatic Results Import).
   - *Gap*: We have tests for *displaying* results, but no integration tests verifying the actual handshake and parsing logic with the iRacing API boundary.
2. **Rating Engine Persistence**:
   - *Concept*: [`docs/concept/RATING.md`](docs/concept/RATING.md) (GridPilot Rating).
   - *Gap*: The rating system involves complex calculations that must be persisted correctly. We lack integration tests for the `RatingService` interacting with the DB.
3. **Auth/Identity Provider**:
   - *Concept*: [`docs/concept/CONCEPT.md`](docs/concept/CONCEPT.md:172) (Safety, Security & Trust).
   - *Gap*: No integration tests for the Auth boundary (e.g., JWT validation, session persistence).

### 🛠 Functional Gaps (Business Logic Integration)
1. **Social/Messaging**:
   - *Concept*: [`docs/concept/SOCIAL.md`](docs/concept/SOCIAL.md) (Messaging, Notifications).
   - *Gap*: No integration tests for message persistence or notification delivery (queues).
2. **Constructors-Style Scoring**:
   - *Concept*: [`docs/concept/RACING.md`](docs/concept/RACING.md:47) (Constructors-Style Points).
   - *Gap*: While we have `StandingsCalculation.test.ts`, we need specific integration tests for complex multi-driver team scoring scenarios against the DB.

## 4. Proposed Action Plan

1. **Implement iRacing API Contract/Integration Tests**: Verify the parsing of iRacing result payloads.
2. **Add Rating Persistence Tests**: Ensure `GridPilot Rating` updates correctly in the DB after race results are processed.
3. **Add Social/Notification Integration**: Test the persistence of messages and the triggering of notifications.
4. **Auth Integration**: Verify the system-level Auth flow as per the "Trust" requirement.

---
*Uncle Bob's Note: Remember, the closer a test is to the code, the more of them you should have. But for the system to be robust, the boundaries must be ironclad.*
