Files
vyndr/tests/unit/tickerDedup.test.js
T
builtbykev 66d52a9ce0 Item 1 — VERB LAW: one verb, READ (never SCAN), + a lint that enforces it
The product argued with itself: FAB/nav said "Scan", Free tier "5 scans",
ticker "MLB slate scanned" — while the Ledger says "MY READS". Swept every
user-visible surface to READ:
- BottomTabBar FAB + Nav link: 'Scan' → 'Read'
- Pricing free tier: '5 scans to try the model' → '5 reads …'
- StatStrip: 'Awaiting next scan' → 'Awaiting next read'
- Ticker badge + snapshotService event: tag 'SCAN' → 'READ',
  'slate scanned' → 'slate read' (readSportOf parses BOTH old and new so
  cached ticker items dedupe cleanly through the rollover)
- upgradePitch: 'You've scanned N parlays' / 'unlimited scans' → read/reads

Internal untouched (not user-visible): /api/scan routes, scan_count column,
scanning state, DemoScan/ScanIcon, scanlines CSS, the transitional SCAN
color-map key.

tests/unit/verbLaw.test.js is the enforcement: it fails on user-visible
scan/scanned/scans copy across web/src + src/services (skips comments). Suite
270/3254 green, web build exit 0.

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

48 lines
2.3 KiB
JavaScript

// Session 47 — Phase 3: ticker keeps only the latest SCAN per sport.
const svc = require('../../src/services/snapshotService');
function memCache(initial) {
const store = { 'ticker:items': initial || null };
return { store, cacheGet: async (k) => store[k] ?? null, cacheSet: async (k, v) => { store[k] = v; } };
}
describe('pushTickerItems — SCAN dedup', () => {
it('replaces a prior SCAN for the same sport (only one MLB SCAN)', async () => {
const cache = memCache([
{ tag: 'READ', sport: 'mlb', text: 'MLB slate read · 20 props graded' },
{ tag: 'MOVE', text: 'Judge o2.5 → o3.5 ▲+1' },
]);
await svc.pushTickerItems([{ tag: 'READ', sport: 'mlb', text: 'MLB slate read · 25 props graded' }], cache);
const items = cache.store['ticker:items'];
expect(items.filter((e) => e.tag === 'READ' && e.sport === 'mlb')).toHaveLength(1);
expect(items.find((e) => e.tag === 'READ').text).toContain('25 props');
});
it('preserves MOVE/GRADE events and other sports', async () => {
const cache = memCache([
{ tag: 'MOVE', text: 'move 1' },
{ tag: 'A+', text: 'BOMBER graded A+' },
{ tag: 'READ', sport: 'nba', text: 'NBA slate read · 10 props graded' },
]);
await svc.pushTickerItems([{ tag: 'READ', sport: 'mlb', text: 'MLB slate read · 25 props graded' }], cache);
const items = cache.store['ticker:items'];
expect(items.find((e) => e.tag === 'MOVE')).toBeTruthy();
expect(items.find((e) => e.tag === 'A+')).toBeTruthy();
expect(items.find((e) => e.tag === 'READ' && e.sport === 'nba')).toBeTruthy();
});
it('dedupes legacy SCAN items that lack a sport field (parse from text)', async () => {
const cache = memCache([{ tag: 'READ', text: 'MLB slate read · 20 props graded' }]);
await svc.pushTickerItems([{ tag: 'READ', sport: 'mlb', text: 'MLB slate read · 25 props graded' }], cache);
expect(cache.store['ticker:items'].filter((e) => e.tag === 'READ')).toHaveLength(1);
});
it('stays capped at 50 items', async () => {
const many = Array.from({ length: 60 }, (_, i) => ({ tag: 'MOVE', text: `m${i}` }));
const cache = memCache(many);
await svc.pushTickerItems([{ tag: 'READ', sport: 'mlb', text: 'read' }], cache);
expect(cache.store['ticker:items'].length).toBeLessThanOrEqual(50);
});
});