Extract shared import logic into lib/card-import, discover missing sets via Scryfall/Pokémon TCG APIs, and expose GET /api/cron/sync-catalog protected by CRON_SECRET (max 3 sets/run, paced imports). Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
filterMissingMtgSets,
|
|
filterMissingPokemonSets,
|
|
} from '../../lib/card-import/discover.js';
|
|
|
|
describe('filterMissingMtgSets', () => {
|
|
const now = new Date('2026-05-27T12:00:00.000Z');
|
|
|
|
it('returns released paper sets missing from the catalog', () => {
|
|
const known = new Set(['lea']);
|
|
const missing = filterMissingMtgSets(
|
|
[
|
|
{ code: 'lea', name: 'Alpha', released_at: '1993-08-05', set_type: 'core', digital: false },
|
|
{ code: 'fin', name: 'Final Fantasy', released_at: '2026-05-01', set_type: 'expansion', digital: false },
|
|
{ code: 'tlea', name: 'Alpha Tokens', released_at: '1993-08-05', set_type: 'token', digital: false },
|
|
{ code: 'mh3', name: 'Modern Horizons 3', released_at: '2027-01-01', set_type: 'expansion', digital: false },
|
|
],
|
|
known,
|
|
now
|
|
);
|
|
|
|
expect(missing).toEqual([
|
|
{
|
|
code: 'fin',
|
|
name: 'Final Fantasy',
|
|
releasedAt: '2026-05-01',
|
|
},
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('filterMissingPokemonSets', () => {
|
|
it('returns sets whose ids are not in the catalog', () => {
|
|
const known = new Set(['sv1']);
|
|
const missing = filterMissingPokemonSets(
|
|
[
|
|
{ id: 'sv1', name: 'Scarlet & Violet', releaseDate: '2023-03-31' },
|
|
{ id: 'sv2', name: 'Paldea Evolved', releaseDate: '2023-06-09' },
|
|
],
|
|
known
|
|
);
|
|
|
|
expect(missing).toEqual([
|
|
{
|
|
id: 'sv2',
|
|
name: 'Paldea Evolved',
|
|
releasedAt: '2023-06-09',
|
|
},
|
|
]);
|
|
});
|
|
});
|