import { describe, expect, it } from 'vitest';

import {
  cardNumbersEquivalent,
  findPrintingByCollectorNumber,
  normalizeCardNumber,
} from '../../lib/card-number-utils.js';

describe('normalizeCardNumber', () => {
  it('treats leading-zero numerators as equivalent', () => {
    expect(normalizeCardNumber('015/208')).toBe('15/208');
    expect(normalizeCardNumber('15/208')).toBe('15/208');
    expect(normalizeCardNumber('18/88')).toBe('18/88');
  });
});

describe('cardNumbersEquivalent', () => {
  it('matches normalized collector numbers', () => {
    expect(cardNumbersEquivalent('015/208', '15/208')).toBe(true);
    expect(cardNumbersEquivalent('18/88', '015/208')).toBe(false);
  });
});

describe('findPrintingByCollectorNumber', () => {
  it('returns the sole matching printing', () => {
    const match = findPrintingByCollectorNumber(
      [
        { id: 1, card_number: '18/88' },
        { id: 2, card_number: '19/88' },
      ],
      '018/88'
    );
    expect(match?.id).toBe(1);
  });
});
