import { describe, expect, it } from 'vitest';
import { parseLedger, getDefaultCurrency } from '../src/domain/core/ledger';

describe('getDefaultCurrency', () => {
  it('从 operating_currency option 读取默认币种', () => {
    const ledger = parseLedger([{
      path: 'main.bean',
      content: 'option "operating_currency" "USD"\n2026-01-01 open Assets:Bank USD\n',
    }]);
    expect(getDefaultCurrency(ledger)).toBe('USD');
  });

  it('无 operating_currency 时回退到 CNY', () => {
    const ledger = parseLedger([{
      path: 'main.bean',
      content: '2026-01-01 open Assets:Bank CNY\n',
    }]);
    expect(getDefaultCurrency(ledger)).toBe('CNY');
  });

  it('ledger 为 null 时回退到 CNY', () => {
    expect(getDefaultCurrency(null)).toBe('CNY');
  });

  it('多个 operating_currency 时取第一个', () => {
    const ledger = parseLedger([{
      path: 'main.bean',
      content: 'option "operating_currency" "USD"\noption "operating_currency" "CNY"\n2026-01-01 open Assets:Bank USD\n',
    }]);
    expect(getDefaultCurrency(ledger)).toBe('USD');
  });
});
