@@ -1,47 +1,81 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { DefaultAudioPlayInfoRepository } from '@/repositories/AudioPlayInfoRepository'
|
||||
|
||||
const stopInfoResponse = {
|
||||
const detailResponse = {
|
||||
code: 0,
|
||||
data: {
|
||||
available: true,
|
||||
targetType: 'STOP',
|
||||
targetId: 'stop-1',
|
||||
resolvedStopId: 'stop-1',
|
||||
lang: 'zh-CN',
|
||||
title: '测试讲解点',
|
||||
description: '测试简介',
|
||||
imageStatus: 'READY',
|
||||
imageSource: 'STOP',
|
||||
galleryUrls: '[]',
|
||||
playTargetType: 'STOP',
|
||||
playTargetId: 'stop-1',
|
||||
hasAudio: false,
|
||||
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,
|
||||
supportedLanguages: ['zh-CN'],
|
||||
audioStatus: 'MISSING',
|
||||
audioOptions: []
|
||||
hasAudio: true
|
||||
}
|
||||
}
|
||||
|
||||
describe('DefaultAudioPlayInfoRepository stop-info loading mode', () => {
|
||||
describe('DefaultAudioPlayInfoRepository unified stop detail', () => {
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
it('defaults H5 detail requests to lightweight mode and keeps its cache separate from legacy mode', async () => {
|
||||
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: stopInfoResponse })
|
||||
success({
|
||||
statusCode: 200,
|
||||
data: {
|
||||
...detailResponse,
|
||||
data: {
|
||||
...detailResponse.data,
|
||||
version: String(url).includes('version=extended') ? 'extended' : 'standard'
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
const repository = new DefaultAudioPlayInfoRepository()
|
||||
|
||||
await repository.getStopInfo({ targetType: 'STOP', targetId: 'stop-1', lang: 'zh-CN' })
|
||||
await repository.getStopInfo({ targetType: 'STOP', targetId: 'stop-1', lang: 'zh-CN', lightweight: false })
|
||||
const first = await repository.getStopDetail('865546647764037632')
|
||||
const second = await repository.getStopDetail('865546647764037632')
|
||||
const extended = await repository.getStopDetail('865546647764037632', { version: 'extended' })
|
||||
|
||||
expect(requestUrls).toHaveLength(2)
|
||||
expect(new URL(requestUrls[0], 'http://localhost').searchParams.get('lightweight')).toBe('true')
|
||||
expect(new URL(requestUrls[1], 'http://localhost').searchParams.get('lightweight')).toBe('false')
|
||||
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('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('导览讲解点不存在')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user