Files
moyi-model-intelligence-hub/prototype/tests/media.test.mjs
T

27 lines
1.4 KiB
JavaScript

import { test } from 'node:test'
import assert from 'node:assert/strict'
import { mediaResult, safeMediaUrl } from '../src/services/media.ts'
test('mediaResult keeps provider URLs in their declared media lane', () => {
const result = mediaResult({ url: 'https://cdn.example.test/result.mp4', format: 'mp4' }, '视频')
assert.equal(result.videoUrl, 'https://cdn.example.test/result.mp4')
assert.equal(result.modelUrl, undefined)
assert.equal(result.imageUrl, undefined)
})
test('mediaResult identifies image/audio and rejects unsafe URLs', () => {
assert.equal(safeMediaUrl('javascript:alert(1)'), undefined)
const image = mediaResult({ url: 'https://cdn.example.test/image.png' }, '图像')
const audio = mediaResult({ url: 'https://cdn.example.test/sound.mp3' }, '音频')
assert.equal(image.imageUrl, 'https://cdn.example.test/image.png')
assert.equal(audio.audioUrl, 'https://cdn.example.test/sound.mp3')
})
test('mediaResult supports provider base64 output and nested media objects', () => {
const image = mediaResult({ b64_json: 'iVBORw0KGgo=', format: 'png' }, '')
assert.match(image.imageUrl, /^data:image\/png;base64,iVBORw0KGgo=$/)
const nested = mediaResult({ image_url: { b64_json: 'iVBORw0KGgo=', mime_type: 'image/png' } }, '')
assert.match(nested.imageUrl, /^data:image\/png;base64,iVBORw0KGgo=$/)
assert.equal(safeMediaUrl('data:text/html;base64,PGh0bWw+'), undefined)
})