import { CurrencyTaxCalculatorService, convertCurrency, calculateInternationalTax, } from '../../../src/modules/team/service/currency-tax'; import { TaxCalculationResult } from '../../../src/comm/types/omni'; describe('Point 57 (P1): 跨国多币种汇率换算与国际发票税制计算', () => { let service: CurrencyTaxCalculatorService; beforeEach(() => { service = new CurrencyTaxCalculatorService(); }); describe('1. convertCurrency (多币种汇率精准换算)', () => { it('美元 USD 换算为阿联酋迪拉姆 AED (固定汇率 ~3.6725)', () => { // 100 USD -> 367.25 AED const aed = convertCurrency(100, 'USD', 'AED'); expect(aed).toBe(367.25); }); it('欧元 EUR 换算为美元 USD', () => { // 100 EUR -> 108 USD (基于 1.08 基准汇率) const usd = convertCurrency(100, 'EUR', 'USD'); expect(usd).toBe(108); }); it('同币种换算应保持原数值', () => { expect(convertCurrency(500, 'USD', 'USD')).toBe(500); expect(convertCurrency(800, 'AED', 'AED')).toBe(800); }); it('不支持的币种应抛出明确异常保护', () => { expect(() => convertCurrency(100, 'USD', 'XYZ' as any)).toThrow(); }); }); describe('2. calculateInternationalTax (国际合规发票税制计算)', () => { it('阿联酋企业或个人消费应按 5% VAT 计税', () => { const res = calculateInternationalTax({ amount: 1000, currency: 'AED', country: 'AE', isB2b: true, }); expect(res.taxRate).toBe(0.05); expect(res.taxAmount).toBe(50); expect(res.totalAmount).toBe(1050); expect(res.taxName).toBe('UAE VAT'); }); it('欧盟企业间跨国 B2B (Reverse Charge) 应适用反向征税 0% VAT', () => { const res = calculateInternationalTax({ amount: 2000, currency: 'EUR', country: 'DE', // 德国 isB2b: true, vatNumber: 'DE123456789', }); expect(res.taxRate).toBe(0); expect(res.taxAmount).toBe(0); expect(res.totalAmount).toBe(2000); expect(res.isReverseCharge).toBe(true); expect(res.taxName).toContain('Reverse Charge'); }); it('零税区或未开税国家 (如免税州/部分离岸) 税额为 0', () => { const res = calculateInternationalTax({ amount: 500, currency: 'USD', country: 'US', isB2b: true, }); expect(res.taxRate).toBe(0); expect(res.taxAmount).toBe(0); expect(res.totalAmount).toBe(500); }); }); describe('3. CurrencyTaxCalculatorService 综合结算账单生成', () => { it('应生成包含格式化币种符号与详细税务明细的结算单', async () => { const invoice = await service.generateTaxInvoiceSummary({ baseAmountUsd: 199, // 199 美元标准版年费 targetCurrency: 'AED', billingCountry: 'AE', isB2b: true, }); expect(invoice.currency).toBe('AED'); expect(invoice.currencySymbol).toBe('AED '); expect(invoice.subtotal).toBeCloseTo(730.83, 1); expect(invoice.taxAmount).toBeGreaterThan(0); expect(invoice.totalAmount).toBeGreaterThan(invoice.subtotal); }); }); });