import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import ts from 'typescript'

const sourceUrl = new URL('../src/views/Editor/EnglishSpeaking/services/speakingApiConfig.ts', import.meta.url)
const source = await readFile(sourceUrl, 'utf8')
const compiled = ts.transpileModule(source, {
  compilerOptions: {
    module: ts.ModuleKind.ESNext,
    target: ts.ScriptTarget.ES2020,
  },
}).outputText

const mod = await import(`data:text/javascript,${encodeURIComponent(compiled)}`)

assert.equal(
  mod.getSpeakingApiHost({}),
  'https://ppt-english-speaking-api.cocorobo.cn',
)

assert.equal(
  mod.getSpeakingApiBaseUrl({}),
  'https://ppt-english-speaking-api.cocorobo.cn/api/speaking/dialogue',
)

assert.equal(
  mod.getSpeakingApiBaseUrl({ VITE_SPEAKING_API_HOST: 'https://example.com/' }),
  'https://example.com/api/speaking/dialogue',
)

assert.equal(
  mod.buildSpeakingWsUrl('/speak-stream'),
  'wss://ppt-english-speaking-api.cocorobo.cn/api/speaking/dialogue/speak-stream',
)
