fix(trucks): skip active-site check when PATCH leaves site unchanged

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 11:53:32 +08:00
co-authored by Claude Sonnet 5.5
parent 5f1d7a6ed4
commit 17c32ecd04
3 changed files with 24 additions and 1 deletions
+12
View File
@@ -128,6 +128,18 @@ describe('PATCH /api/admin/trucks', () => {
expect((await PATCH(req('PATCH', { id: 't1', site_id: SITE }))).status).toBe(422)
expect(setSpy).not.toHaveBeenCalled()
})
it('skips the active-site check when the site is unchanged', async () => {
selectQueue.push([{ id: 't1', siteId: SITE }])
const res = await PATCH(req('PATCH', { id: 't1', truck_no: 'NEW 1', site_id: SITE }))
expect(res.status).toBe(200)
expect(setSpy).toHaveBeenCalledWith({ truckNo: 'NEW 1', siteId: SITE })
})
it('422 when moving a site-less truck to an inactive site', async () => {
selectQueue.push([{ id: 't1', siteId: null }], [])
const res = await PATCH(req('PATCH', { id: 't1', site_id: SITE }))
expect(res.status).toBe(422)
expect(setSpy).not.toHaveBeenCalled()
})
it('409 for a duplicate truck number', async () => {
selectQueue.push([{ id: 't1' }])
txError.code = '23505'