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
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>
78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('../../lib/sql.js', () => ({ sql: vi.fn() }));
|
|
vi.mock('../../lib/pricing/price-history.js', () => ({
|
|
getPriceHistoryPoints: vi.fn(),
|
|
}));
|
|
|
|
import { sql } from '../../lib/sql.js';
|
|
import { getPriceHistoryPoints } from '../../lib/pricing/price-history.js';
|
|
import handler from '../../pages/api/cards/[id]/price-history.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]/price-history', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
sql.mockResolvedValue({ rows: [{ id: 42 }] });
|
|
getPriceHistoryPoints.mockResolvedValue([
|
|
{ date: '2026-01-01', amount: 1.25, source: 'scryfall', priceType: 'market', currency: 'USD' },
|
|
]);
|
|
});
|
|
|
|
it('returns 400 for invalid card id', async () => {
|
|
const req = { method: 'GET', query: { id: 'nope' } };
|
|
const res = createRes();
|
|
|
|
await handler(req, res);
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
expect(sql).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('returns 400 when days is out of range', async () => {
|
|
const req = { method: 'GET', query: { id: '42', days: '999' } };
|
|
const res = createRes();
|
|
|
|
await handler(req, res);
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
expect(getPriceHistoryPoints).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('returns 404 when card does not exist', async () => {
|
|
sql.mockResolvedValue({ rows: [] });
|
|
const req = { method: 'GET', query: { id: '42', days: '30' } };
|
|
const res = createRes();
|
|
|
|
await handler(req, res);
|
|
|
|
expect(res.statusCode).toBe(404);
|
|
});
|
|
|
|
it('returns points for a valid request', async () => {
|
|
const req = { method: 'GET', query: { id: '42', days: '30' } };
|
|
const res = createRes();
|
|
|
|
await handler(req, res);
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
expect(getPriceHistoryPoints).toHaveBeenCalledWith(42, { days: 30 });
|
|
expect(res.body.points).toHaveLength(1);
|
|
expect(res.body.points[0].amount).toBe(1.25);
|
|
});
|
|
});
|