20260917165839
This commit is contained in:
1 parent
182ed86966
commit
38e1e66c3b
108 files changed
+2497
-1215
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import http from '@/services/http'
|
||||
import { countExportApi, exportListApi, loadTotalsApi } from '@/services/exportService'
|
||||
|
||||
describe('导出服务响应契约', () => {
|
||||
const originalAdapter = http.defaults.adapter
|
||||
beforeEach(() => setActivePinia(createPinia()))
|
||||
afterEach(() => {
|
||||
http.defaults.adapter = originalAdapter
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('条数和合计接口剥离 Axios 响应,调用方可直接取业务 data', async () => {
|
||||
http.defaults.adapter = async (config) => ({
|
||||
data: { code: 0, data: config.url.endsWith('count') ? { total: 23 } : { b_amount: 12.5 } },
|
||||
status: 200,
|
||||
headers: {},
|
||||
config,
|
||||
})
|
||||
expect((await countExportApi({ moduleId: 'm1' })).data.total).toBe(23)
|
||||
expect((await loadTotalsApi({ moduleId: 'm1' })).data.b_amount).toBe(12.5)
|
||||
})
|
||||
|
||||
it('下载请求不受普通请求超时限制,业务错误不会被保存为 Excel', async () => {
|
||||
const post = vi.spyOn(http, 'post').mockResolvedValue({
|
||||
data: { text: async () => JSON.stringify({ code: 1, message: '没有导出权限' }) },
|
||||
headers: { 'content-type': 'application/json' },
|
||||
})
|
||||
await expect(exportListApi({ moduleId: 'm1' })).rejects.toThrow('没有导出权限')
|
||||
expect(post.mock.calls[0][2]).toEqual({ responseType: 'blob', timeout: 0 })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user