|
| 1 | +# Test Coverage Gaps — Critical Priorities |
| 2 | + |
| 3 | +**Created:** 2026-03-24 |
| 4 | +**Context:** Audit revealed strong OAuth tracker coverage but critical gaps in credential-based auth (Libre/CGM), data transformers, and integration testing. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Gap 1: LibreLoginForm — ZERO unit tests (HIGH PRIORITY) |
| 9 | + |
| 10 | +**File:** `mobile/src/components/FitnessTracker/LibreLoginForm.tsx` (429 lines) |
| 11 | +**Risk:** Only credential-based auth in the app. Completely different path from OAuth trackers. No coverage at all. |
| 12 | + |
| 13 | +### What needs testing: |
| 14 | +- **Rendering:** Form renders email, password, region picker, submit button |
| 15 | +- **Validation:** Empty email, empty password, invalid email format |
| 16 | +- **Region selection:** All 9 regions (US, EU, EU2, DE, FR, JP, AP, AU, CA) render and are selectable |
| 17 | +- **Submission flow:** Calls `libre-auth` edge function with correct payload (email, password, region) |
| 18 | +- **Auth header:** JWT token included in request |
| 19 | +- **Success path:** Calls `onSuccess` callback, invalidates `connectedDevices` query |
| 20 | +- **Error handling:** Invalid credentials error, network error, regional endpoint errors |
| 21 | +- **Loading state:** Shows spinner during auth, disables submit button |
| 22 | +- **Cancel:** `onCancel` callback fires, form resets |
| 23 | +- **Keyboard behavior:** `KeyboardAvoidingView` wraps form correctly |
| 24 | + |
| 25 | +### Test file to create: |
| 26 | +`mobile/src/components/FitnessTracker/__tests__/LibreLoginForm.test.tsx` |
| 27 | + |
| 28 | +### Estimated tests: ~20-25 |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Gap 2: Libre/CGM data transformers — no tests (HIGH PRIORITY) |
| 33 | + |
| 34 | +**Risk:** Fitbit, Whoop, and Oura each have 3-4 transformer test files (~50+ tests). Libre has zero. CGM data flows through untested transformation code. |
| 35 | + |
| 36 | +### What needs testing: |
| 37 | +- Glucose reading transformation (raw API → `glucose_data` table schema) |
| 38 | +- Timestamp handling (display_time vs glucose_timestamp, timezone offsets) |
| 39 | +- Value validation (physiologically plausible glucose range filtering) |
| 40 | +- Alarm data transformation |
| 41 | +- Null/missing field handling |
| 42 | +- Duplicate reading deduplication |
| 43 | + |
| 44 | +### Files to investigate: |
| 45 | +- Check `supabase/functions/sync-libre/` for transformer code |
| 46 | +- Mirror the test patterns from `mobile/src/utils/fitnessTrackers/__tests__/` (Whoop/Oura/Fitbit transformers) |
| 47 | + |
| 48 | +### Estimated tests: ~15-20 |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## Gap 3: Onboarding + device connection E2E (MEDIUM PRIORITY) |
| 53 | + |
| 54 | +**Risk:** Current onboarding tests mock all tracker hooks. No test verifies the full flow: render screen → tap device → OAuth redirect → sync → connected state updates UI. |
| 55 | + |
| 56 | +### What needs testing: |
| 57 | +- **Screen 2 with connected device:** Mock `useConnectedTrackers` to return a connected device → verify "Connected" badge renders, "Sync" button hidden |
| 58 | +- **Screen 2 OAuth trigger:** Press device card → verify `authenticate()` called with correct provider ID |
| 59 | +- **Screen 2 Libre flow:** Press Libre card → verify LibreLoginForm renders → cancel returns to device list |
| 60 | +- **Screen 2 sync status:** After successful auth, verify "Scanning History..." badge appears |
| 61 | +- **Screen 1 → 2 → 3 navigation:** Full forward/back navigation chain |
| 62 | + |
| 63 | +### Test file to create: |
| 64 | +`mobile/src/app/(onboarding)/__tests__/onboarding-integration.test.tsx` |
| 65 | + |
| 66 | +### Estimated tests: ~10-15 |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Gap 4: Onboarding edge cases (LOW PRIORITY) |
| 71 | + |
| 72 | +**Risk:** Minor — happy paths are covered but some edge cases aren't. |
| 73 | + |
| 74 | +### What needs testing: |
| 75 | +- **Invalid date combos:** Feb 30, Apr 31, etc. (currently only validates age range) |
| 76 | +- **Profile save failure:** `updateProfile` throws → user should still advance (non-blocking) |
| 77 | +- **Re-entry:** User kills app mid-onboarding, reopens → should resume at correct step |
| 78 | +- **completeOnboarding failure:** AsyncStorage write fails → graceful degradation |
| 79 | +- **Double-tap prevention:** Pressing "Next" rapidly doesn't navigate twice |
| 80 | + |
| 81 | +### Estimated tests: ~8-10 |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## Implementation Order |
| 86 | + |
| 87 | +1. **LibreLoginForm tests** — highest risk, zero coverage on a production auth flow |
| 88 | +2. **Onboarding integration tests** — validates the new screens work with real(ish) tracker hooks |
| 89 | +3. **Libre data transformers** — depends on server-side code structure, may be server-side tests |
| 90 | +4. **Onboarding edge cases** — lowest risk, nice-to-have hardening |
| 91 | + |
| 92 | +## Total estimated new tests: ~55-70 |
0 commit comments