80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
import {
|
|
getVideoDownloadAvailability,
|
|
getVideoDownloadUnavailableMessage,
|
|
VIDEO_DOWNLOAD_WAIT_DAYS,
|
|
} from '@/lib/video-download-policy'
|
|
import { DownloadErrorCode, parseDownloadError } from '@/lib/download-errors'
|
|
|
|
describe('video download policy', () => {
|
|
const now = new Date('2026-05-25T12:00:00.000Z')
|
|
|
|
test('安装视频不受 15 天限制', () => {
|
|
const availability = getVideoDownloadAvailability(
|
|
'安装视频',
|
|
'2026-05-25T11:00:00.000Z',
|
|
now,
|
|
)
|
|
|
|
expect(availability.allowed).toBe(true)
|
|
})
|
|
|
|
test('非安装视频上传未满 15 天时禁止下载', () => {
|
|
const availability = getVideoDownloadAvailability(
|
|
'淘系-主图视频',
|
|
'2026-05-20T12:00:00.000Z',
|
|
now,
|
|
)
|
|
|
|
expect(availability).toMatchObject({
|
|
allowed: false,
|
|
reason: 'VIDEO_WAIT_PERIOD',
|
|
remainingDays: 10,
|
|
})
|
|
expect(availability.availableAt?.toISOString()).toBe('2026-06-04T12:00:00.000Z')
|
|
expect(getVideoDownloadUnavailableMessage(availability)).toContain(
|
|
`满 ${VIDEO_DOWNLOAD_WAIT_DAYS} 天才能下载`,
|
|
)
|
|
})
|
|
|
|
test('非安装视频上传满 15 天后允许下载', () => {
|
|
const availability = getVideoDownloadAvailability(
|
|
'抖音-千川素材',
|
|
'2026-05-10T12:00:00.000Z',
|
|
now,
|
|
)
|
|
|
|
expect(availability.allowed).toBe(true)
|
|
})
|
|
|
|
test('兼容旧视频类型名称', () => {
|
|
const availability = getVideoDownloadAvailability(
|
|
'主图视频',
|
|
'2026-05-24T12:00:00.000Z',
|
|
now,
|
|
)
|
|
|
|
expect(availability.allowed).toBe(false)
|
|
expect(availability.reason).toBe('VIDEO_WAIT_PERIOD')
|
|
})
|
|
|
|
test('非视频素材不受限制', () => {
|
|
const availability = getVideoDownloadAvailability(
|
|
'买家秀图片',
|
|
'2026-05-25T11:00:00.000Z',
|
|
now,
|
|
)
|
|
|
|
expect(availability.allowed).toBe(true)
|
|
})
|
|
|
|
test('下载错误解析应优先展示等待期详情', () => {
|
|
const parsed = parseDownloadError({
|
|
code: DownloadErrorCode.VIDEO_WAIT_PERIOD,
|
|
error: '视频类素材上传后满 15 天才能下载',
|
|
details: '视频类素材上传后满 15 天才能下载,当前还需约 3 天',
|
|
})
|
|
|
|
expect(parsed.message).toBe('视频类素材上传后满 15 天才能下载,当前还需约 3 天')
|
|
})
|
|
})
|