27 lines
1.9 KiB
JavaScript
27 lines
1.9 KiB
JavaScript
|
|
import {expect,it,vi} from 'vitest'
|
||
|
|
const capture=vi.hoisted(()=>({request:null}))
|
||
|
|
vi.mock('axios',()=>({default:{defaults:{headers:{}},create:()=>({interceptors:{request:{use:fn=>{capture.request=fn}},response:{use:()=>{}}}})}}))
|
||
|
|
vi.mock('@/utils/auth',()=>({getToken:()=>null}))
|
||
|
|
vi.mock('@/store/modules/user',()=>({default:()=>({})}))
|
||
|
|
vi.mock('@/plugins/cache',()=>({default:{session:{getJSON:()=>undefined,setJSON:()=>{}}}}))
|
||
|
|
import '@/utils/request'
|
||
|
|
|
||
|
|
it('actual Axios interceptor cleans every owned query before URL encoding',()=>{
|
||
|
|
for(const path of ['/warehouse/product/list','/warehouse/stock/list','/production/bom/list','/project/info/options','/system/user/list']){
|
||
|
|
const original={productName:' \u3000路由器\u200b ',spec:' AX 5400 ',params:{beginTime:' 2026-10-01 '},empty:' \t ',pageNum:1}
|
||
|
|
const config=capture.request({url:path,method:'get',headers:{},params:original})
|
||
|
|
const params=new URL(config.url,'http://localhost').searchParams
|
||
|
|
expect(params.get('productName')).toBe('路由器');expect(params.get('spec')).toBe('AX 5400')
|
||
|
|
expect(params.get('params[beginTime]')).toBe('2026-10-01');expect(params.has('empty')).toBe(false)
|
||
|
|
expect(original.productName).toBe(' \u3000路由器\u200b ')
|
||
|
|
}
|
||
|
|
})
|
||
|
|
it('filtered exports agree with lists without changing mutation, credentials, or collaboration payloads',()=>{
|
||
|
|
const exported=capture.request({url:'/warehouse/product/export',method:'post',headers:{},data:{productName:' 路由器 '}})
|
||
|
|
expect(exported.data.productName).toBe('路由器')
|
||
|
|
const body={productName:' 新物品 ',remark:' 保留说明 ',password:' password '}
|
||
|
|
expect(capture.request({url:'/warehouse/product',method:'post',headers:{},data:body}).data).toBe(body)
|
||
|
|
const collaborative=capture.request({url:'/project/manage/projects',method:'get',headers:{},params:{keyword:' 原样 '}})
|
||
|
|
expect(new URL(collaborative.url,'http://localhost').searchParams.get('keyword')).toBe(' 原样 ')
|
||
|
|
})
|