import { describe, expect, it } from 'vitest';
import {
  buildLiveShowStreamUrl,
  DEFAULT_LIVE_SHOW_SETTINGS,
  normalizeLiveShowSettings,
} from '../liveShowApi';

describe('liveShowApi', () => {
  it('merges live show settings with defaults', () => {
    const result = normalizeLiveShowSettings({
      fixed_interval_seconds: 12,
      effect_intensity: 15,
    });

    expect(result.fixed_interval_seconds).toBe(12);
    expect(result.effect_intensity).toBe(15);
    expect(result.layout_mode).toBe(DEFAULT_LIVE_SHOW_SETTINGS.layout_mode);
  });

  it('builds stream url with query params', () => {
    const url = buildLiveShowStreamUrl('demo-token', {
      cursor: { approved_at: '2025-01-01T00:00:00Z', id: 42 },
      settingsVersion: 'abc',
      limit: 60,
    });

    const parsed = new URL(url, 'http://example.test');
    expect(parsed.pathname).toBe('/api/v1/live-show/demo-token/stream');
    expect(parsed.searchParams.get('after_approved_at')).toBe('2025-01-01T00:00:00Z');
    expect(parsed.searchParams.get('after_id')).toBe('42');
    expect(parsed.searchParams.get('settings_version')).toBe('abc');
    expect(parsed.searchParams.get('limit')).toBe('60');
  });
});
