Files
vyndr/tests/unit/oddsNormalizerOutrights.test.js
builtbykev f0752b804b Wave 2A: offseason data feeds — news wire + quota-disciplined futures
FREE ESPN news wire + championship-winner futures for the never-dark
offseason hub. Both graceful/empty, never fabricate a market value.

- newsService (mirrors injuryService): per-sport ESPN /news FEEDS, pure
  parseNews → { sport, items:[{id,headline,description,published,type,
  athlete?{name,key},team?,href}] }; athlete/team from categories[] only
  (absent when not present). Cache 15m, injectable, offline-tested.
- oddsNormalizer.normalizeOutrights: NEW branch — outrights outcomes are
  {name,price} with no point, so normalizeProps drops them; keeps them with
  best-price-across-allowed-books per selection. + americanToDecimal.
- oddsService.FUTURES_KEYS: separate map (mlb/nba/wnba championship winner),
  OUT of the daily SPORT_KEYS/snapshot budget.
- futuresService: getFutures(sport,deps) → { sport, updated_at, markets:
  [{key,title,selections:[{name,price,prevPrice?,move?}]}] }. One outrights
  call per 12h TTL (quota-disciplined), FUTURES_ENABLED gate. Price-move
  (shortening/drifting/flat) mirrors computeLineDeltas SHAPE on odds not
  line; prev prices persisted inside the futures:{sport} value (no new key).
  linkNewsToMoves pure causal-tie helper.
- Routes /api/news/:sport + /api/futures/:sport (registered) + Next proxies.
- Tests: newsService, futuresService, oddsNormalizerOutrights (fail→pass,
  no network). Full suite green.

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

92 lines
3.3 KiB
JavaScript

'use strict';
const { normalizeOutrights, normalizeProps, americanToDecimal } = require('../../src/utils/oddsNormalizer');
const outrightEvents = [
{
id: 'evt-ws',
sport_key: 'baseball_mlb_world_series_winner',
sport_title: 'MLB World Series Winner',
commence_time: '2026-10-20T00:00:00Z',
bookmakers: [
{
key: 'draftkings',
title: 'DraftKings',
markets: [
{
key: 'outrights',
outcomes: [
{ name: 'Los Angeles Dodgers', price: 350 },
{ name: 'New York Yankees', price: 450 },
],
},
],
},
{
key: 'fanduel',
title: 'FanDuel',
markets: [
{
key: 'outrights',
outcomes: [
{ name: 'Los Angeles Dodgers', price: 400 }, // better payout than DK's 350
{ name: 'New York Yankees', price: 420 },
],
},
],
},
{
key: 'bovada', // NOT allowed → skipped
markets: [{ key: 'outrights', outcomes: [{ name: 'Los Angeles Dodgers', price: 9999 }] }],
},
],
},
];
describe('normalizeOutrights', () => {
test('normalizes outright outcomes (name+price, no point) into markets', () => {
const markets = normalizeOutrights(outrightEvents);
expect(markets).toHaveLength(1);
const m = markets[0];
expect(m.key).toBe('baseball_mlb_world_series_winner');
expect(m.title).toBe('MLB World Series Winner');
expect(m.selections).toHaveLength(2);
});
test('picks the BEST (highest decimal payout) price per selection across allowed books', () => {
const [m] = normalizeOutrights(outrightEvents);
const dodgers = m.selections.find((s) => s.name === 'Los Angeles Dodgers');
// FanDuel +400 beats DraftKings +350; Bovada is not an allowed book.
expect(dodgers.price).toBe(400);
expect(dodgers.book).toBe('fanduel');
const yankees = m.selections.find((s) => s.name === 'New York Yankees');
// DraftKings +450 beats FanDuel +420.
expect(yankees.price).toBe(450);
expect(yankees.book).toBe('draftkings');
});
test('normalizeProps would DROP these outright outcomes (no point) — the reason a new branch exists', () => {
// Feed the SAME events through the player-prop normalizer: outrights have
// no `point` and no Over/Under, so normalizeProps yields nothing.
const props = normalizeProps(outrightEvents);
expect(props).toEqual([]);
// ...while normalizeOutrights keeps them.
expect(normalizeOutrights(outrightEvents)[0].selections.length).toBeGreaterThan(0);
});
test('never fabricates: empty / malformed input → empty array', () => {
expect(normalizeOutrights([])).toEqual([]);
expect(normalizeOutrights(null)).toEqual([]);
expect(normalizeOutrights([{ sport_key: 'x', bookmakers: [] }])).toEqual([]);
expect(normalizeOutrights([{ sport_key: 'x', bookmakers: [{ key: 'draftkings', markets: [{ key: 'outrights', outcomes: [{ name: 'A', price: null }] }] }] }])).toEqual([]);
});
test('americanToDecimal: +150→2.5, -200→1.5, junk→null', () => {
expect(americanToDecimal(150)).toBeCloseTo(2.5, 5);
expect(americanToDecimal(-200)).toBeCloseTo(1.5, 5);
expect(americanToDecimal(0)).toBeNull();
expect(americanToDecimal(null)).toBeNull();
expect(americanToDecimal('150')).toBeNull();
});
});