/**
 * EU-LP Chip Reading Tests
 */

import { describe, it, expect, vi } from 'vitest';
import { readEULPChip, performBAC, performEAC, readDataGroup } from './chip-reading';

describe('EU-LP Chip Reading', () => {
  describe('readEULPChip', () => {
    it('should read chip data with MRZ key', async () => {
      const options = {
        accessKeys: {
          mrzKey: 'test-mrz-key',
        },
      };

      const result = await readEULPChip(options);

      expect(result.mrzInfo).toBeDefined();
      expect(result.faceImageHash).toBeDefined();
      expect(result.certificateChain).toBeDefined();
      expect(result.securityObjectHash).toBeDefined();
    });

    it('should read chip data without MRZ key', async () => {
      const result = await readEULPChip();

      expect(result.mrzInfo).toBeDefined();
      expect(result.faceImageHash).toBeDefined();
    });

    it('should throw error if simulateError is true', async () => {
      const options = {
        simulateError: true,
      };

      await expect(readEULPChip(options)).rejects.toThrow(
        'Simulated chip reading error'
      );
    });
  });

  describe('performBAC', () => {
    it('should perform Basic Access Control', async () => {
      const mrzKey = 'test-mrz-key';

      const result = await performBAC(mrzKey);

      expect(result).toBe(true);
    });
  });

  describe('performEAC', () => {
    it('should perform Extended Access Control', async () => {
      const eacKey = 'test-eac-key';

      const result = await performEAC(eacKey);

      expect(result).toBe(true);
    });
  });

  describe('readDataGroup', () => {
    it('should read data group', async () => {
      const dgNumber = 1;

      const result = await readDataGroup(dgNumber);

      expect(result).toBeInstanceOf(Buffer);
    });
  });
});

