Problem Statement
The Analytics application has zero tests despite containing complex business logic — LTV calculation, engagement scoring, anomaly detection, chart rendering, bookmarks, date range management, and user segment builder.
Evidence
- No test files exist in analytics/
- analytics/package.json has no test framework dependency
- analytics CI only runs lint — no test step
Impact
Analytics data accuracy cannot be verified. Regressions in calculations (LTV, engagement scores) go undetected. Complex chart rendering has no automated verification.
Proposed Solution
- Install Vitest
- Write tests for:
- LTV calculation: calcLTV, calcRetentionLTV, cohortLTV
- Engagement scoring: calcEngagementScores with edge cases (empty, single, all same values)
- Anomaly detection: detectAnomalies with known patterns
- useElapsed hook: elapsed time formatting
- useDebounce hook: debounce behavior
- Utilities: regression calculation, data generation
Technical Requirements
- Must use Vitest (consistent with frontend test approach)
- No DOM testing needed for pure computation functions
- Chart components can be tested visually or with snapshot tests
Acceptance Criteria
- calcLTV returns correct LTV for given ARPU and churn rate
- calcRetentionLTV returns cumulative LTV array
- cohortLTV returns array adjusted for cohort aging
- calcEngagementScores returns sorted scored items with breakdown
- Edge cases: empty array, single item, all same values handled gracefully
- useElapsed returns correct formatted strings
- useDebounce debounces value changes
- npm run test passes with >80% coverage on utility functions
File Inventory
analytics/lib/ltv-calc.ts
analytics/lib/engagement-score.ts
analytics/lib/anomaly-detection.ts
analytics/hooks/useElapsed.ts
analytics/hooks/useDebounce.ts
analytics/lib/utils.ts
Dependencies
None.
Testing Strategy
Vanilla unit tests for pure functions. Hook tests using @testing-library/react-hooks or renderHook.
Security Considerations
Ensures financial calculations (LTV) are accurate. Prevents data integrity issues in analytics reporting.
Definition of Done
Problem Statement
The Analytics application has zero tests despite containing complex business logic — LTV calculation, engagement scoring, anomaly detection, chart rendering, bookmarks, date range management, and user segment builder.
Evidence
Impact
Analytics data accuracy cannot be verified. Regressions in calculations (LTV, engagement scores) go undetected. Complex chart rendering has no automated verification.
Proposed Solution
Technical Requirements
Acceptance Criteria
File Inventory
analytics/lib/ltv-calc.tsanalytics/lib/engagement-score.tsanalytics/lib/anomaly-detection.tsanalytics/hooks/useElapsed.tsanalytics/hooks/useDebounce.tsanalytics/lib/utils.tsDependencies
None.
Testing Strategy
Vanilla unit tests for pure functions. Hook tests using @testing-library/react-hooks or renderHook.
Security Considerations
Ensures financial calculations (LTV) are accurate. Prevents data integrity issues in analytics reporting.
Definition of Done