Files
vyndr/tests/unit/slateAdapterStrips.test.js
T
builtbykev 7969a4971a Session 44: Make it visible — VYNDR archetype names, grade intel, schedule fix, landing page (2061 tests)
Frontend + wiring only. Wires existing backend into the pages users see.

- VYNDR Original archetype rename (41) across archetypeService.js + lib/
  archetypes.js + ArchetypeBadge, each keeping legacyName (resolves stale data).
  Judge -> BOMBER. Old POWER PULL slot -> WHIFF strikeout-artist pitcher.
- BACKEND_HANDOFF.md: canonical frontend<->backend data contract.
- Grade card intel: scan/page.tsx now forwards the engine's intel fields
  (season_avg/form/usage/matchup_grade/archetype/...) into mapScanToGradeResult
  -> STAT CONTEXT + VYNDR INTELLIGENCE sections populate. The chain already
  preserved them (tierGating + /api/scan spread); the page was dropping them.
- Schedule freshness: slateAdapter.isRelevantGame drops completed games >24h
  old; Slate.filteredGames applies it. (TTL already 60s.)
- Landing: Features.tsx rewritten to user-facing copy (no Point-biserial/Zone
  14/ABS/Phi-coefficient).
- Depth chart Next proxies added (/api/stats/lineup|depth|cascade) - were 404.
- GameCard swap DEFERRED (Kev): legacy on-demand card stays as a bridge until
  the snapshot pipeline populates the grades cache; vyndr/GameCard swaps in then.

Backend 2045 -> 2061 tests (+16), 167 suites. Web build clean (exit 0).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 20:15:38 -04:00

74 lines
3.0 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('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}');
});
});