deckhearth/test/api/cards-pricing.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

72 lines
1.8 KiB
JavaScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('../../lib/pricing/pricing-service.js', () => ({
getCardPricing: vi.fn(),
}));
import { getCardPricing } from '../../lib/pricing/pricing-service.js';
import handler from '../../pages/api/cards/[id]/pricing.js';
function createRes() {
const res = {
statusCode: 200,
body: null,
status(code) {
res.statusCode = code;
return res;
},
json(data) {
res.body = data;
return res;
},
};
return res;
}
describe('GET /api/cards/[id]/pricing', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('returns 400 for invalid card id', async () => {
const req = { method: 'GET', query: { id: 'abc' } };
const res = createRes();
await handler(req, res);
expect(res.statusCode).toBe(400);
expect(getCardPricing).not.toHaveBeenCalled();
});
it('returns 404 when card is missing', async () => {
getCardPricing.mockResolvedValue(null);
const req = { method: 'GET', query: { id: '99' } };
const res = createRes();
await handler(req, res);
expect(res.statusCode).toBe(404);
});
it('returns pricing payload with staleness metadata', async () => {
getCardPricing.mockResolvedValue({
prices: { current: 1.25, market: 2.5, currency: 'USD' },
pricesUpdatedAt: '2026-01-01T00:00:00.000Z',
stale: true,
outbound: {
tcgplayer: 'https://tcgplayer.example',
ebay: 'https://ebay.example',
},
});
const req = { method: 'GET', query: { id: '42' } };
const res = createRes();
await handler(req, res);
expect(res.statusCode).toBe(200);
expect(res.body.stale).toBe(true);
expect(res.body.prices.current).toBe(1.25);
expect(res.body.outbound.tcgplayer).toContain('tcgplayer');
});
});