deckhearth/test/lib/pricing/card-price.test.js

27 lines
1 KiB
JavaScript
Raw Normal View History

import { describe, expect, it } from 'vitest';
import { isPriceStale, resolveUnitPrice, PRICE_STALE_HOURS } from '../../../lib/pricing/card-price.js';
describe('card-price', () => {
it('uses current_price for nonfoil MTG rows', () => {
expect(resolveUnitPrice({ currentPrice: 1.5, marketPrice: 10, isFoil: false })).toBe(1.5);
});
it('uses market_price for foil MTG rows', () => {
expect(resolveUnitPrice({ currentPrice: 1.5, marketPrice: 10, isFoil: true })).toBe(10);
});
it('falls back when primary column is null', () => {
expect(resolveUnitPrice({ currentPrice: null, marketPrice: 3, isFoil: false })).toBe(3);
expect(resolveUnitPrice({ currentPrice: 2, marketPrice: null, isFoil: true })).toBe(2);
});
it('detects stale prices', () => {
const fresh = new Date(Date.now() - 60 * 60 * 1000);
const stale = new Date(Date.now() - (PRICE_STALE_HOURS + 1) * 60 * 60 * 1000);
expect(isPriceStale(fresh)).toBe(false);
expect(isPriceStale(stale)).toBe(true);
expect(isPriceStale(null)).toBe(true);
});
});