feat: accept partial bodies on PUT /api/instances/:vmid
Merge the request body onto the existing instance row before validating, so external callers (n8n, scripts) can send only the fields they want to change instead of GET-then-splat-then-PUT the full record. Mirrors the partial-update pattern already used by PUT /api/jobs/:id. Full-body PUTs (today's frontend) are unaffected.
This commit is contained in:
@@ -257,6 +257,18 @@ describe('PUT /api/instances/:vmid', () => {
|
||||
const res = await request(app).put('/api/instances/100').send({ ...base, vmid: 200 })
|
||||
expect(res.status).toBe(409)
|
||||
})
|
||||
|
||||
it('accepts a partial body and preserves unspecified fields', async () => {
|
||||
await request(app).post('/api/instances').send({ ...base, atlas: 1, tailscale_ip: '100.64.0.1' })
|
||||
const res = await request(app).put('/api/instances/100').send({ state: 'degraded' })
|
||||
expect(res.status).toBe(200)
|
||||
expect(res.body.state).toBe('degraded')
|
||||
expect(res.body.name).toBe(base.name)
|
||||
expect(res.body.vmid).toBe(100)
|
||||
expect(res.body.stack).toBe(base.stack)
|
||||
expect(res.body.atlas).toBe(1)
|
||||
expect(res.body.tailscale_ip).toBe('100.64.0.1')
|
||||
})
|
||||
})
|
||||
|
||||
// ── DELETE /api/instances/:vmid ───────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user