32 lines
947 B
JavaScript
32 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);
|
||
|
|
});
|
||
|
|
});
|