/**
 * EU-LP MRZ Parsing Tests
 */

import { describe, it, expect } from 'vitest';
import { parseMRZ } from './mrz-parser';

describe('parseMRZ', () => {
  it('should parse valid EU-LP MRZ', () => {
    const mrzLines = [
      'P<EULPTEST<<JOHN<DOE<<<<<<<<<<<<<<<<<<<<<<<<<',
      '1234567890EULP7001019M2501018<<<<<<<<<<<<<<0',
    ];

    const result = parseMRZ(mrzLines);

    expect(result.documentType).toBe('P');
    expect(result.issuingCountry).toBe('EUL');
    expect(result.surname).toBe('TEST');
    expect(result.givenNames).toBe('JOHN DOE');
    expect(result.documentNumber).toBe('123456789');
    expect(result.nationality).toBe('EUL');
    expect(result.dateOfBirth).toBe('700101');
    expect(result.sex).toBe('M');
    expect(result.expirationDate).toBe('250101');
  });

  it('should throw error for invalid MRZ format', () => {
    const invalidMRZ = ['INVALID'];

    expect(() => parseMRZ(invalidMRZ)).toThrow('MRZ must have exactly 2 lines');
  });

  it('should throw error for invalid line length', () => {
    const invalidMRZ = ['SHORT', 'LINE'];

    expect(() => parseMRZ(invalidMRZ)).toThrow('Each MRZ line must be 44 characters');
  });
});

