deckhearth/test/lib/pricing/price-history.test.js
Randall Stillwell d0468015eb
Some checks failed
CI / Lint (pull_request) Has been cancelled
CI / Schema map up to date (pull_request) Has been cancelled
CI / Forbidden patterns (9 checks) (pull_request) Has been cancelled
CI / Migrations apply (node-pg-migrate) (pull_request) Has been cancelled
Visual diff / Should run? (pull_request) Has been cancelled
CI / Unit tests (vitest) (pull_request) Has been cancelled
Convoy metrics gate / Require role-event telemetry on convoy PRs (pull_request) Has been cancelled
PR Health rollup / Aggregate gate status (pull_request) Has been cancelled
Preview smoke / Should run? (pull_request) Has been cancelled
Preview smoke / Playwright smoke (pull_request) Has been cancelled
Visual diff / Screenshot diff (pull_request) Has been cancelled
feat(pricing): convoy for online prices and local stores
Add pricing schema, free API integrations (MTG bulk, TCGdex, Foolio),
valuation and sort-by-price, card detail pricing UI, and nearby store
discovery via home zip and OSM geo clients.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-08 22:47:46 -05:00

31 lines
947 B
JavaScript

import { describe, expect, it, vi, beforeEach } from 'vitest';
vi.mock('../../../lib/sql.js', () => ({
sql: vi.fn(async () => ({ rows: [], rowCount: 0 })),
}));
import { sql } from '../../../lib/sql.js';
import { recordPriceSnapshots } from '../../../lib/pricing/price-history.js';
describe('price-history', () => {
beforeEach(() => {
vi.mocked(sql).mockClear();
});
it('skips invalid rows', async () => {
const written = await recordPriceSnapshots([
{ cardId: 1, source: 'scryfall', amount: null },
{ cardId: null, source: 'scryfall', amount: 1 },
]);
expect(written).toBe(0);
expect(sql).not.toHaveBeenCalled();
});
it('upserts valid snapshot rows', async () => {
const written = await recordPriceSnapshots([
{ cardId: 42, source: 'scryfall', amount: 1.25, priceType: 'market', currency: 'USD' },
]);
expect(written).toBe(1);
expect(sql).toHaveBeenCalledTimes(1);
});
});