Files
vyndr/tests/integration/snapshotRoutes.test.js
T
builtbykev f8b120c0aa Session 45: Snapshot pipeline + GameCard swap + live ticker (2100 tests)
The on-demand "Read" grade model is RETIRED. A scheduled pipeline pre-grades the
slate, locks grades to the line, tracks movement; the dashboard shows them already
there. Orchestrates existing services — nothing rebuilt.

- snapshotService.runSnapshot(sport): getOdds → gradeAndCacheSlate → classify
  archetype per player → lock gradedAt → line deltas vs previous snapshot → write
  snapshot:{sport}:latest/previous + grades:{sport} → ticker events. Fully
  injectable, zero-network unit tests. runAllSnapshots = cron entrypoint.
- Internal trigger POST /api/internal/snapshot/:sport + /all (requireInternalAuth).
  In-process cron (SNAPSHOT_CRON=1, UTC 14,19,22,1,3) in server.js, no new dep.
- Public reads: GET /api/snapshot/:sport (cache-only) + GET /api/ticker (merges
  TICKER_MANUAL pins) + Next proxies.
- GameCard swap: live Slate renders vyndr/GameCard (legacy kept for types only),
  overlays locked grades onto game props → player name once + archetype badge +
  "Graded Xh ago at -115 · Current 2.5 · ▲ TOWARD +1.0". Ungraded → "Awaiting next
  scan", NO Read button. On-demand onGrade flow deleted.
- Ticker polls /api/ticker every 30s, graceful fallback to hardcoded items.
- NBA/WNBA: espnStatsAdapter free fallback (defensive parse → found:false on shape
  mismatch) wired into resolvePlayerStats after the offline Python service.

Env: PROPLINE_API_KEY_1/2/3, VYNDR_INTERNAL_KEY, SNAPSHOT_CRON=1, TICKER_MANUAL.
Backend 2061 -> 2100 tests (+39), 173 suites. Web build clean (exit 0).

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

97 lines
3.6 KiB
JavaScript

// Session 45 — internal snapshot endpoints (auth-gated) + the public ticker.
const express = require('express');
const request = require('supertest');
jest.mock('../../scripts/tank01-prefetch', () => ({ main: jest.fn() }));
jest.mock('../../src/services/quotaTracker', () => ({ getAllQuotaStatuses: jest.fn() }));
jest.mock('../../src/services/snapshotService', () => ({
runSnapshot: jest.fn(async (sport) => ({ sport, status: 'ok', gradeCount: 3 })),
runAllSnapshots: jest.fn(async () => [{ sport: 'mlb', status: 'ok' }, { sport: 'nba', status: 'skipped' }]),
}));
const snapshot = require('../../src/services/snapshotService');
beforeEach(() => {
jest.clearAllMocks();
process.env.VYNDR_INTERNAL_KEY = 'test-key-123';
});
function mountInternal() {
delete require.cache[require.resolve('../../src/routes/internal')];
const internalRoutes = require('../../src/routes/internal');
const app = express();
app.use(express.json());
app.use('/api/internal', internalRoutes);
return app;
}
describe('POST /api/internal/snapshot/:sport', () => {
it('rejects without the internal key (401)', async () => {
const res = await request(mountInternal()).post('/api/internal/snapshot/mlb').send({});
expect(res.status).toBe(401);
expect(snapshot.runSnapshot).not.toHaveBeenCalled();
});
it('runs a single-sport snapshot with the key', async () => {
const res = await request(mountInternal())
.post('/api/internal/snapshot/mlb')
.set('x-internal-key', 'test-key-123')
.send({});
expect(res.status).toBe(200);
expect(snapshot.runSnapshot).toHaveBeenCalledWith('mlb');
expect(res.body.summary.gradeCount).toBe(3);
});
it('routes /snapshot/all to runAllSnapshots (not captured as a sport)', async () => {
const res = await request(mountInternal())
.post('/api/internal/snapshot/all')
.set('x-internal-key', 'test-key-123')
.send({});
expect(res.status).toBe(200);
expect(snapshot.runAllSnapshots).toHaveBeenCalled();
expect(snapshot.runSnapshot).not.toHaveBeenCalled();
expect(res.body.results).toHaveLength(2);
});
});
describe('GET /api/ticker', () => {
const mockCache = { value: null };
jest.mock('../../src/utils/redis', () => ({
cacheGet: async () => mockCache.value,
cacheSet: async () => true,
getRedisClient: () => ({}),
isDegraded: () => false,
}));
function mountTicker() {
delete require.cache[require.resolve('../../src/routes/ticker')];
const tickerRoutes = require('../../src/routes/ticker');
const app = express();
app.use('/api/ticker', tickerRoutes);
return app;
}
it('returns snapshot items newest-first', async () => {
mockCache.value = [{ tag: 'SCAN', text: 'MLB slate scanned · 248 props graded' }, { tag: 'A+', text: 'BOMBER Judge graded A+' }];
delete process.env.TICKER_MANUAL;
const res = await request(mountTicker()).get('/api/ticker');
expect(res.status).toBe(200);
expect(res.body.items[0].tag).toBe('SCAN');
});
it('merges editorial pins from TICKER_MANUAL', async () => {
mockCache.value = [{ tag: 'SCAN', text: 'scanned' }];
process.env.TICKER_MANUAL = JSON.stringify([{ tag: 'ALERT', text: 'VYNDR 2.0 is live.' }]);
const res = await request(mountTicker()).get('/api/ticker');
expect(res.body.items.find((i) => i.tag === 'ALERT')).toBeTruthy();
delete process.env.TICKER_MANUAL;
});
it('returns [] gracefully on a cold cache', async () => {
mockCache.value = null;
delete process.env.TICKER_MANUAL;
const res = await request(mountTicker()).get('/api/ticker');
expect(res.body.items).toEqual([]);
});
});