/**
 * marketUtils — 시장 판별 + 통화/금액 포매팅 테스트.
 */
import {
    detectMarket, marketOf, currencyOf, formatMoney,
    formatMarketCapKR, formatMarketCapUS,
} from '../src/features/stocks/marketUtils';

describe('stocks marketUtils', () => {
    test('detectMarket — 6자리 숫자 = KR, 알파벳 = US', () => {
        expect(detectMarket('005930')).toBe('KR');
        expect(detectMarket('005935')).toBe('KR');
        expect(detectMarket('005930.KS')).toBe('KR');
        expect(detectMarket('035720.KQ')).toBe('KR');
        expect(detectMarket('AAPL')).toBe('US');
        expect(detectMarket('aapl')).toBe('US');
        expect(detectMarket('BRK.B')).toBe('US');
        expect(detectMarket('TSLA')).toBe('US');
    });

    test('marketOf — 명시 market 우선, 없으면 심볼 판별', () => {
        expect(marketOf({ 심볼: 'AAPL' })).toBe('US');
        expect(marketOf({ 심볼: '005930' })).toBe('KR');
        // 명시값이 심볼 판별을 덮어씀 (예: ADR 등 예외)
        expect(marketOf({ 심볼: 'ABCDEF', market: 'KR' })).toBe('KR');
    });

    test('currencyOf', () => {
        expect(currencyOf('KR')).toBe('KRW');
        expect(currencyOf('US')).toBe('USD');
    });

    test('formatMoney — 원/달러 분기', () => {
        expect(formatMoney(72000, 'KR')).toBe('72,000원');
        expect(formatMoney(232.45, 'US')).toBe('$232.45');
        expect(formatMoney(1234.5, 'US')).toBe('$1,235');  // ≥1000 은 정수 반올림
        expect(formatMoney(undefined, 'US')).toBe('-');
    });

    test('formatMarketCap — KR 억/조, US B/T', () => {
        expect(formatMarketCapKR(5000)).toBe('5,000억');
        expect(formatMarketCapKR(12000)).toBe('1조 2,000억');
        expect(formatMarketCapKR(20000)).toBe('2조');
        expect(formatMarketCapUS(3.2e12)).toBe('$3.20T');
        expect(formatMarketCapUS(5e9)).toBe('$5.00B');
    });
});
