Files
vyndr/tests/unit/slateAdapterStrips.test.js
T
builtbykev d09a06c054 Session 55: Self-learning loop + real-time layer (2274 tests)
Product overhaul core — the two transformative, differentiated systems:

Self-learning loop (Phase 2): outcomeService settles locked snapshot grades
against real MLB Stats API results → hit/miss/push, rolling accuracy by grade
tier (30d window). Idempotent, injectable, unit-tested. New GET /api/accuracy +
/api/ledger/accuracy + internal settle triggers + cron hook. AccuracyBadge
(dashboard/scan/landing) is honest — "LEARNING" below MIN_SAMPLE, never a fake
number. Settled HIT/MISS chips overlay the live slate.

Real-time layer (Phase 1): Slate silent 60s auto-refresh (no flash, no wipe on
transient blips) + "SIGNAL LIVE · UPDATED Xs ago" freshness strip; Ticker LIVE
badge that flashes on fresh events.

Landing (Phase 3): TopSignals shows tonight's real top-3 A-rated grades + live
accuracy — the product shown, not described.

Founder pricing: FOUNDER_CODE_EXPIRY default 2026-06-30 → 2026-12-31 (had
lapsed, disabling every founder code + the ClaimMeter pitch). That expiry — not
a tier change — was the real cause of the 4 stripe test failures.

Backend 2255 (4 failing) → 2274 (all green; +19 new, +4 fixed). Web build exit 0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-10 15:39:13 -04:00

98 lines
4.2 KiB
JavaScript

// Session 43 — slate adapter: player-grouped strips + MLB pitchers + BookChip.
const fs = require('fs');
const path = require('path');
const WEB = path.join(__dirname, '..', '..', 'web', 'src');
const adapter = require('../../web/src/lib/slateAdapter');
describe('groupPropsByPlayer', () => {
it('groups props so each player appears once (name not repeated)', () => {
const out = adapter.groupPropsByPlayer([
{ player: 'Austin Riley', team: 'ATL', stat: 'Hits', line: 1.5, side: 'Over', grade: 'A' },
{ player: 'Austin Riley', team: 'ATL', stat: 'Total Bases', line: 1.5, side: 'Over', grade: 'B+' },
{ player: 'Bryce Harper', team: 'PHI', stat: 'TB', line: 1.5, side: 'Over', grade: 'A' },
]);
expect(out).toHaveLength(2);
expect(out[0].player).toBe('Austin Riley');
expect(out[0].props).toHaveLength(2);
expect(out[0].props[0].side).toBe('O');
expect(out[1].player).toBe('Bryce Harper');
});
it('attaches an archetype when a lookup is provided', () => {
const out = adapter.groupPropsByPlayer(
[{ player: 'Riley', stat: 'Hits', line: 1.5, side: 'Over', grade: 'A' }],
() => ({ primary: 'BOMBER' }),
);
expect(out[0].archetype).toEqual({ primary: 'BOMBER' });
});
it('returns [] for empty / non-array input', () => {
expect(adapter.groupPropsByPlayer(null)).toEqual([]);
expect(adapter.groupPropsByPlayer([])).toEqual([]);
});
});
describe('buildPlayerStripsFromProps — settled outcome passthrough (Session 55)', () => {
it('attaches the settled outcome from the snapshot grade onto the prop', () => {
const props = [{ player: 'Aaron Judge', stat_type: 'hits', line: 1.5 }];
const gradeIndex = adapter.indexGrades([
{ player: 'Aaron Judge', stat_type: 'hits', line: 1.5, direction: 'over', grade: 'A',
gradedAt: { line: 1.5, timestamp: '2026-07-10T02:00:00Z' },
outcome: { result: 'hit', actual: 2 } },
]);
const strips = adapter.buildPlayerStripsFromProps(props, gradeIndex, {});
expect(strips[0].props[0].outcome).toEqual({ result: 'hit', actual: 2 });
expect(strips[0].props[0].grade).toBe('A');
});
it('leaves outcome null when the grade has not settled', () => {
const props = [{ player: 'Aaron Judge', stat_type: 'hits', line: 1.5 }];
const gradeIndex = adapter.indexGrades([
{ player: 'Aaron Judge', stat_type: 'hits', line: 1.5, direction: 'over', grade: 'A',
gradedAt: { line: 1.5, timestamp: '2026-07-10T02:00:00Z' } },
]);
const strips = adapter.buildPlayerStripsFromProps(props, gradeIndex, {});
expect(strips[0].props[0].outcome).toBeNull();
});
});
describe('mapPitchers', () => {
it('maps MLB probable pitchers to the GameCard shape', () => {
const p = adapter.mapPitchers({
sport: 'mlb',
away: { probablePitcher: { name: 'Spencer Strider' } },
home: { probablePitcher: { name: 'Zack Wheeler' } },
awayPitcherERA: 3.21, homePitcherERA: 2.89,
});
expect(p.away.name).toBe('Spencer Strider');
expect(p.away.era).toBe('3.21');
expect(p.home.name).toBe('Zack Wheeler');
});
it('returns undefined for non-MLB or no probables', () => {
expect(adapter.mapPitchers({ sport: 'nba' })).toBeUndefined();
expect(adapter.mapPitchers({ sport: 'mlb' })).toBeUndefined();
});
});
describe('mapScheduleToGameCards includes the new fields', () => {
it('builds playerStrips + pitchers on each card', () => {
const cards = adapter.mapScheduleToGameCards(
[{ id: 'ATL-PHI', sport: 'mlb', awayTeam: { abbreviation: 'ATL', name: 'Braves' }, homeTeam: { abbreviation: 'PHI', name: 'Phillies' }, away: { probablePitcher: { name: 'Strider' } }, home: { probablePitcher: { name: 'Wheeler' } } }],
{},
[],
[{ player: 'Austin Riley', team: 'ATL', stat: 'Hits', line: 1.5, grade: 'A', side: 'Over' }],
);
expect(cards[0].playerStrips[0].player).toBe('Austin Riley');
expect(cards[0].pitchers.away.name).toBe('Strider');
});
});
describe('legacy GameCard uses BookChip (brand colors)', () => {
it('renders book chips instead of plain grey text', () => {
const src = fs.readFileSync(path.join(WEB, 'components', 'GameCard.tsx'), 'utf8');
expect(src).toContain('BookChip');
expect(src).toContain('book={r.book}');
});
});