File size: 836 Bytes
5433b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { afterEach, describe, expect, it, vi } from 'vitest'
import { cancelJob, getJobStatus } from './api'
import { setCurrentLocale } from '../i18n/runtime'

describe('api error parsing', () => {
  afterEach(() => {
    vi.restoreAllMocks()
    setCurrentLocale('en-US')
  })

  it('falls back to a stable message when job status returns an empty error body', async () => {
    vi.stubGlobal('fetch', vi.fn(async () => new Response('', { status: 500 })))

    await expect(getJobStatus('job-1')).rejects.toThrow('Failed to fetch job status')
  })

  it('falls back to a stable message when cancel returns invalid json', async () => {
    setCurrentLocale('zh-CN')
    vi.stubGlobal('fetch', vi.fn(async () => new Response('oops', { status: 500 })))

    await expect(cancelJob('job-2')).rejects.toThrow('取消任务失败')
  })
})