- 新增物品分类申请及审核记录相关数据库表结构 - 添加物品分类管理菜单及对应的角色权限配置 - 实现物品分类申请组件支持新增申请与历史记录查询 - 开发批量AI分类组件以支持采购明细的智能分类推荐 - 新增批量确认小类组件以便管理员快速处理待确认分类 - 构建物品分类管理页面提供分类审核调整及关联记录查看
49 lines
3.4 KiB
JavaScript
49 lines
3.4 KiB
JavaScript
import {beforeEach,expect,it,vi} from 'vitest'
|
|
const capture=vi.hoisted(()=>({success:null,failure:null}))
|
|
vi.mock('axios',()=>({default:{defaults:{headers:{}},isCancel:()=>false,create:()=>({interceptors:{request:{use:()=>{}},response:{use:(success,failure)=>{capture.success=success;capture.failure=failure}}}})}}))
|
|
vi.mock('@/utils/auth',()=>({getToken:()=>null}))
|
|
vi.mock('@/store/modules/user',()=>({default:()=>({})}))
|
|
vi.mock('@/plugins/cache',()=>({default:{session:{getJSON:()=>undefined,setJSON:()=>{}}}}))
|
|
vi.mock('element-plus',()=>({ElMessage:vi.fn(),ElMessageBox:{confirm:vi.fn(()=>Promise.reject())},ElNotification:{error:vi.fn()},ElLoading:{}}))
|
|
import {ElMessage,ElNotification,ElMessageBox} from 'element-plus'
|
|
import '@/utils/request'
|
|
const config={url:'/project/workspace/capabilities',method:'get',workspaceCapabilityProbe:true}
|
|
beforeEach(()=>vi.clearAllMocks())
|
|
it('only the optional capabilities probe tolerates the exact Spring legacy missing-route envelope',()=>{
|
|
const result=capture.success({config,data:{code:500,msg:'No static resource project/workspace/capabilities.'}})
|
|
expect(result.data).toEqual({supported:false,ready:false});expect(ElMessage).not.toHaveBeenCalled()
|
|
})
|
|
it('an HTTP 404 from that probe also identifies a legacy backend without error toast',()=>{
|
|
expect(capture.failure({config,response:{status:404},message:'Request failed with status code 404'}).data.supported).toBe(false)
|
|
expect(ElMessage).not.toHaveBeenCalled()
|
|
})
|
|
it('unrelated endpoints and unexpected server errors do not fall back',async()=>{
|
|
for(const [cfg,msg] of [[{...config,url:'/project/workspace/71'},'No static resource project/workspace/capabilities.'],[config,'Database unavailable']]){
|
|
await expect(capture.success({config:cfg,request:{},data:{code:500,msg}})).rejects.toThrow()
|
|
}
|
|
expect(ElMessage).toHaveBeenCalledTimes(2)
|
|
})
|
|
it('permission failures remain failures and expired sessions still request login',async()=>{
|
|
await expect(capture.success({config,request:{},data:{code:403,msg:'请联系项目负责人'}})).rejects.toThrow()
|
|
expect(ElNotification.error).toHaveBeenCalled()
|
|
await expect(capture.success({config,request:{},data:{code:401}})).rejects.toBeTruthy()
|
|
expect(ElMessageBox.confirm).toHaveBeenCalled()
|
|
})
|
|
it('network failures never identify a legacy backend',async()=>{
|
|
const error={config,message:'Network Error'}
|
|
await expect(capture.failure(error)).rejects.toBe(error)
|
|
expect(ElMessage).toHaveBeenCalled()
|
|
})
|
|
it.each([403,409,500])('purchase autosave preserves server error code %s without misreporting every failure as a conflict',async code=>{
|
|
const failure={code,msg:'核对保存状态',data:{reason:'test'}}
|
|
await expect(capture.success({config:{url:'/warehouse/purchase/sheet',purchaseSheetRequest:true},request:{},data:failure})).rejects.toMatchObject({code,data:failure.data})
|
|
expect(ElMessage).not.toHaveBeenCalled();expect(ElNotification.error).not.toHaveBeenCalled()
|
|
})
|
|
it('offline autosave uses the persistent collaboration status instead of repeated global error toasts',async()=>{
|
|
const error={config:{url:'/warehouse/purchase/sheet',purchaseSheetRequest:true},message:'Network Error'}
|
|
await expect(capture.failure(error)).rejects.toMatchObject({message:'连接暂时中断,本机草稿已保留'})
|
|
expect(ElMessage).not.toHaveBeenCalled()
|
|
const denied={...error,response:{status:403,data:{code:403,msg:'没有编辑权限'}}}
|
|
await expect(capture.failure(denied)).rejects.toMatchObject({code:403,message:'没有编辑权限'})
|
|
})
|