"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const aggregateOutcomes_1 = require("./aggregateOutcomes"); /** Builds N couples that completed day_30 with the given connection delta. */ function couplesWithConnectionDelta(n, connectionDelta) { return Array.from({ length: n }, () => ({ deltas: { day_30: { connection: connectionDelta, communication: 0, intimacy: 0, happiness: 0 } }, })); } describe('aggregate', () => { it('suppresses a window below the minimum cohort', () => { const stats = (0, aggregateOutcomes_1.aggregate)(couplesWithConnectionDelta(aggregateOutcomes_1.MIN_COHORT - 1, 3)); expect(stats.windows.day_30.suppressed).toBe(true); expect(stats.windows.day_30.feltCloserPct).toBeUndefined(); expect(stats.windows.day_30.cohort).toBe(aggregateOutcomes_1.MIN_COHORT - 1); }); it('reports percentages once the cohort meets the minimum', () => { // 60 couples: 45 improved connection, 15 did not. const improved = couplesWithConnectionDelta(45, 2); const flat = couplesWithConnectionDelta(15, 0); const stats = (0, aggregateOutcomes_1.aggregate)([...improved, ...flat]); expect(stats.windows.day_30.suppressed).toBe(false); expect(stats.windows.day_30.cohort).toBe(60); expect(stats.windows.day_30.feltCloserPct).toBe(75); // 45/60 }); it('counts only couples eligible for each window', () => { // day_60 has zero couples → suppressed; day_30 has enough. const stats = (0, aggregateOutcomes_1.aggregate)(couplesWithConnectionDelta(aggregateOutcomes_1.MIN_COHORT, 1)); expect(stats.windows.day_30.suppressed).toBe(false); expect(stats.windows.day_60.suppressed).toBe(true); expect(stats.windows.day_60.cohort).toBe(0); }); it('computes improved percentages per metric', () => { var _a, _b, _c, _d; const couples = Array.from({ length: aggregateOutcomes_1.MIN_COHORT }, (_, i) => ({ deltas: { day_30: { connection: 1, communication: i < aggregateOutcomes_1.MIN_COHORT / 2 ? 1 : 0, // exactly half improved intimacy: 0, happiness: -1, }, }, })); const stats = (0, aggregateOutcomes_1.aggregate)(couples); expect((_a = stats.windows.day_30.improvedPctByMetric) === null || _a === void 0 ? void 0 : _a.connection).toBe(100); expect((_b = stats.windows.day_30.improvedPctByMetric) === null || _b === void 0 ? void 0 : _b.communication).toBe(50); expect((_c = stats.windows.day_30.improvedPctByMetric) === null || _c === void 0 ? void 0 : _c.intimacy).toBe(0); expect((_d = stats.windows.day_30.improvedPctByMetric) === null || _d === void 0 ? void 0 : _d.happiness).toBe(0); }); it('emits no couple-identifying data — only counts and percentages', () => { const stats = (0, aggregateOutcomes_1.aggregate)(couplesWithConnectionDelta(aggregateOutcomes_1.MIN_COHORT, 2)); const json = JSON.stringify(stats); expect(json).not.toMatch(/couple|uid|userId|score/i); }); }); describe('extractCoupleOutcome', () => { it('pulls only the follow-up deltas, ignoring day_0 and stray docs', () => { const out = (0, aggregateOutcomes_1.extractCoupleOutcome)([ { id: 'day_0', data: { baseline: { connection: 5 } } }, { id: 'day_30', data: { delta: { connection: 2, communication: 1 } } }, { id: 'random', data: { delta: { connection: 9 } } }, ]); expect(out.deltas.day_0).toBeUndefined(); expect(out.deltas.day_30).toEqual({ connection: 2, communication: 1 }); expect(out.deltas.random).toBeUndefined(); }); }); //# sourceMappingURL=aggregateOutcomes.test.js.map