import { describe, expect, it } from 'vitest'
import { toSpotDisplaySymbol } from './to-spot-display-symbol'

describe('toSpotDisplaySymbol', () => {
  it('falls back to the curated symbol when nothing names the token', () => {
    expect(toSpotDisplaySymbol({ displaySymbol: 'HYPE', name: 'HYPE' })).toBe(
      'HYPE',
    )
  })

  it('prefers the live annotation over the raw name', () => {
    expect(
      toSpotDisplaySymbol({
        annotationDisplayName: 'Purr',
        displaySymbol: 'PURR',
        name: 'PURR',
      }),
    ).toBe('Purr')
  })

  // A curated override (`UBTC` -> `BTC`) is ours; the deployer's annotation
  // must not rename a listing we deliberately renamed already.
  it('lets a curated override beat the live annotation', () => {
    expect(
      toSpotDisplaySymbol({
        annotationDisplayName: 'Unit BTC',
        displaySymbol: 'BTC',
        name: 'UBTC',
      }),
    ).toBe('BTC')
  })

  it('refuses an annotation that is not a plausible market name', () => {
    expect(
      toSpotDisplaySymbol({
        annotationDisplayName: 'a/../b',
        displaySymbol: 'NQ',
        name: 'NQ',
      }),
    ).toBe('NQ')
  })

  it('refuses a blank annotation', () => {
    expect(
      toSpotDisplaySymbol({
        annotationDisplayName: '   ',
        displaySymbol: 'NQ',
        name: 'NQ',
      }),
    ).toBe('NQ')
  })
})
