Some checks failed
CI / verify (push) Has been cancelled
- 使用真实讲解编号解析接口替换本地演示映射 - 成功后复用现有详情页并自动播放讲解 - 增加查询状态、业务错误提示和相关测试 Made-with: Proma
134 lines
4.7 KiB
TypeScript
134 lines
4.7 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { DefaultAudioPlayInfoRepository } from '@/repositories/AudioPlayInfoRepository'
|
|
|
|
const detailResponse = {
|
|
code: 0,
|
|
data: {
|
|
id: '865546647764037632',
|
|
version: 'standard',
|
|
name: '测试讲解点',
|
|
imageStatus: 'MISSING',
|
|
textVariants: [{ version: 'standard', languageCode: 'zh-CN', text: '测试正文' }],
|
|
audioTracks: [{
|
|
version: 'standard', languageCode: 'zh-CN', gender: 'female',
|
|
playUrl: '/museum-assets/audio/zh-female.mp3'
|
|
}],
|
|
hasText: true,
|
|
hasAudio: true
|
|
}
|
|
}
|
|
|
|
describe('DefaultAudioPlayInfoRepository unified stop detail', () => {
|
|
afterEach(() => vi.unstubAllGlobals())
|
|
|
|
it('requests the versioned endpoint and caches each detail version independently', async () => {
|
|
const requestUrls: string[] = []
|
|
vi.stubGlobal('uni', {
|
|
request: ({ url, success }: { url: string, success: (response: unknown) => void }) => {
|
|
requestUrls.push(url)
|
|
success({
|
|
statusCode: 200,
|
|
data: {
|
|
...detailResponse,
|
|
data: {
|
|
...detailResponse.data,
|
|
version: String(url).includes('version=extended') ? 'extended' : 'standard'
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
const repository = new DefaultAudioPlayInfoRepository()
|
|
|
|
const first = await repository.getStopDetail('865546647764037632')
|
|
const second = await repository.getStopDetail('865546647764037632')
|
|
const extended = await repository.getStopDetail('865546647764037632', { version: 'extended' })
|
|
|
|
expect(first.id).toBe('865546647764037632')
|
|
expect(second).toBe(first)
|
|
expect(extended).not.toBe(first)
|
|
expect(extended.version).toBe('extended')
|
|
expect(requestUrls).toEqual([
|
|
'/app-api/gis/guide/stops/865546647764037632?version=standard',
|
|
'/app-api/gis/guide/stops/865546647764037632?version=extended'
|
|
])
|
|
expect(first.audioTracks[0]?.channelCode).toBe('standard.zh-CN.female')
|
|
})
|
|
|
|
it('bypasses a completed entry only when refresh is explicitly requested', async () => {
|
|
const request = vi.fn(({ success }: { success: (response: unknown) => void }) => {
|
|
success({ statusCode: 200, data: detailResponse })
|
|
})
|
|
vi.stubGlobal('uni', { request })
|
|
const repository = new DefaultAudioPlayInfoRepository()
|
|
|
|
await repository.getStopDetail('stop-1')
|
|
await repository.getStopDetail('stop-1', { refresh: true })
|
|
|
|
expect(request).toHaveBeenCalledTimes(2)
|
|
})
|
|
|
|
it('resolves a museum code through info-by-code and preserves the code string', async () => {
|
|
const requestUrls: string[] = []
|
|
vi.stubGlobal('uni', {
|
|
request: ({ url, success }: { url: string, success: (response: unknown) => void }) => {
|
|
requestUrls.push(url)
|
|
success({
|
|
statusCode: 200,
|
|
data: {
|
|
code: 0,
|
|
data: {
|
|
available: true,
|
|
targetType: 'STOP',
|
|
targetId: '865546652298080256',
|
|
resolvedStopId: '865546652298080256',
|
|
lang: 'zh-CN',
|
|
title: '手持折射望远镜',
|
|
imageStatus: 'READY',
|
|
playTargetType: 'STOP',
|
|
playTargetId: '865546652298080256',
|
|
hasAudio: true,
|
|
supportedLanguages: ['zh-CN', 'yue-HK'],
|
|
audioStatus: 'READY'
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
const repository = new DefaultAudioPlayInfoRepository()
|
|
|
|
const result = await repository.getStopInfoByCode('0101', 'zh-CN')
|
|
|
|
expect(requestUrls).toEqual([
|
|
'/app-api/gis/guide/stop/info-by-code?code=0101&lang=zh-CN'
|
|
])
|
|
expect(result.resolvedStopId).toBe('865546652298080256')
|
|
expect(result.title).toBe('手持折射望远镜')
|
|
})
|
|
|
|
it('preserves info-by-code business error codes', async () => {
|
|
vi.stubGlobal('uni', {
|
|
request: ({ success }: { success: (response: unknown) => void }) => {
|
|
success({ statusCode: 200, data: { code: 1020007001, msg: '馆方讲解点编号不存在', data: null } })
|
|
}
|
|
})
|
|
const repository = new DefaultAudioPlayInfoRepository()
|
|
|
|
await expect(repository.getStopInfoByCode('9999')).rejects.toMatchObject({
|
|
message: '馆方讲解点编号不存在',
|
|
code: 1020007001
|
|
})
|
|
})
|
|
|
|
it('surfaces a business missing-detail response as a detail error', async () => {
|
|
vi.stubGlobal('uni', {
|
|
request: ({ success }: { success: (response: unknown) => void }) => {
|
|
success({ statusCode: 200, data: { code: 1020005000, msg: '导览讲解点不存在' } })
|
|
}
|
|
})
|
|
const repository = new DefaultAudioPlayInfoRepository()
|
|
|
|
await expect(repository.getStopDetail('not-found')).rejects.toThrow('导览讲解点不存在')
|
|
})
|
|
})
|