deckhearth/test/lib/scanner-session.test.js
Randall Stillwell 6b70fd9bd1 refactor(scanner): extract session and route API libs (page Brief 1)
Move scanner session persistence, queue merge helpers, and destination
routing fetch calls into lib/scanner-session.js and lib/scanner-route-api.js.
Load collections/decks on mount (were defined but never invoked).
Remove unused mana-symbol imports and dead select-all helpers.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 16:07:33 -05:00

61 lines
1.7 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import {
DEFAULT_SCANNER_DESTINATION,
destinationActionKey,
mergeScannedCardEntry,
} from '../../lib/scanner-session.js';
describe('destinationActionKey', () => {
it('maps owned destination to owned action key', () => {
expect(destinationActionKey(DEFAULT_SCANNER_DESTINATION)).toBe('owned');
});
it('returns pending when destination is missing', () => {
expect(destinationActionKey(null)).toBe('pending');
});
});
describe('mergeScannedCardEntry', () => {
const scanDefaults = { condition: 'NM', isFoil: false };
it('creates a new queue entry with scan defaults', () => {
const { cardEntry, scannedCards, merged } = mergeScannedCardEntry([], {
name: 'Pikachu',
set: 'Base',
databaseId: 1,
}, scanDefaults);
expect(merged).toBe(false);
expect(scannedCards).toHaveLength(1);
expect(cardEntry).toMatchObject({
name: 'Pikachu',
set: 'Base',
quantity: 1,
condition: 'NM',
isFoil: false,
processed: false,
});
expect(cardEntry.id).toBeTruthy();
});
it('increments quantity for an unprocessed duplicate name+set', () => {
const existing = {
id: 99,
name: 'Bolt',
set: 'Alpha',
quantity: 2,
processed: false,
};
const { cardEntry, scannedCards, merged } = mergeScannedCardEntry(
[existing],
{ name: 'Bolt', set: 'Alpha', databaseId: 1, scanImageUrl: 'https://blob/new.jpg' },
scanDefaults
);
expect(merged).toBe(true);
expect(scannedCards).toHaveLength(1);
expect(cardEntry.quantity).toBe(3);
expect(cardEntry.scanImageUrl).toBe('https://blob/new.jpg');
});
});