Fix edit mode PUT payload (status field) and add error handling to fetchUsers

This commit is contained in:
2026-03-18 15:51:34 +08:00
parent d64c098a36
commit 5ead63c160
4 changed files with 24 additions and 5 deletions
@@ -157,17 +157,28 @@ describe('UserFormModal', () => {
await flushPromises()
})
it('calls api.put for edit mode', async () => {
it('calls api.put for edit mode with status field', async () => {
const { api } = await import('@/utils/request')
vi.mocked(api.put).mockResolvedValueOnce({})
await mountModal({ mode: 'edit', userData: mockUserData })
// 先以 open=false 挂载,再切换为 true 触发 watch 预填数据,使表单验证通过
const w = await mountModal({ mode: 'edit', userData: mockUserData, open: false })
await w.setProps({ open: true })
await flushPromises()
await nextTick()
// 点击确定按钮
const okBtn = document.body.querySelector('.ant-modal-footer .ant-btn-primary') as HTMLElement
expect(okBtn).toBeTruthy()
okBtn?.click()
await flushPromises()
// 验证 PUT payload 包含 status 且不包含 ext
expect(api.put).toHaveBeenCalledOnce()
const [url, payload] = vi.mocked(api.put).mock.calls[0]
expect(url).toContain('/api/v1/users/')
expect(payload).toHaveProperty('status')
expect(payload).not.toHaveProperty('ext')
})
})
})