deckhearth/test/lib/card-import-reconcile-submissions.test.js
Randall Stillwell 470d373849 Normalize collector numbers in catalog match and harden scanner adds.
Share card-number normalization across reconcile and identify paths, retry set/name matches when OCR uses leading-zero collector numbers, and extend in-flight locks to all scanner destination actions with disabled Mark Owned feedback.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-28 14:22:06 -05:00

80 lines
2 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import {
pickCatalogCardForPayload,
submissionPayloadMatchesSet,
} from '../../lib/card-import/reconcile-submissions.js';
describe('submissionPayloadMatchesSet', () => {
it('matches by set code or set name for the imported game', () => {
const imported = { game: 'pokemon', setCode: 'sv10', setName: 'Perfect Order' };
expect(
submissionPayloadMatchesSet(
{ name: 'Seel', setCode: 'sv10', game: 'Pokemon' },
imported
)
).toBe(true);
expect(
submissionPayloadMatchesSet(
{ name: 'Seel', set: 'Perfect Order', game: 'pokemon' },
imported
)
).toBe(true);
expect(
submissionPayloadMatchesSet(
{ name: 'Seel', setCode: 'sv9', game: 'Pokemon' },
imported
)
).toBe(false);
expect(
submissionPayloadMatchesSet({ name: 'Bolt', setCode: 'fin', game: 'MTG' }, {
game: 'pokemon',
setCode: 'sv10',
setName: 'Perfect Order',
})
).toBe(false);
});
});
describe('pickCatalogCardForPayload', () => {
const catalogRows = [
{ id: 1, card_number: '015/208' },
{ id: 2, card_number: '016/208' },
];
it('matches a specific printing when the collector number aligns', () => {
expect(
pickCatalogCardForPayload(catalogRows, {
name: 'Seel',
cardNumber: '15/208',
})
).toBe(1);
});
it('returns null when the collector number is ambiguous or missing among siblings', () => {
expect(
pickCatalogCardForPayload(catalogRows, {
name: 'Seel',
cardNumber: '99/208',
})
).toBeNull();
expect(
pickCatalogCardForPayload(catalogRows, {
name: 'Seel',
})
).toBeNull();
});
it('matches name-only payloads when exactly one catalog row exists', () => {
expect(
pickCatalogCardForPayload([{ id: 42, card_number: '1/100' }], {
name: 'Pikachu',
})
).toBe(42);
});
});