Compare commits
5 Commits
fb3c6405c9
..
v1.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
| aa6e28d818 | |||
| 2cf797545c | |||
| a0381b12cc | |||
| 64eacb28d2 | |||
| ea671535fc |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "catalyst",
|
"name": "catalyst",
|
||||||
"version": "1.6.0",
|
"version": "1.7.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server/server.js",
|
"start": "node server/server.js",
|
||||||
|
|||||||
+7
-3
@@ -112,13 +112,17 @@ router.post('/instances', (req, res) => {
|
|||||||
router.put('/instances/:vmid', (req, res) => {
|
router.put('/instances/:vmid', (req, res) => {
|
||||||
const vmid = parseInt(req.params.vmid, 10);
|
const vmid = parseInt(req.params.vmid, 10);
|
||||||
if (!vmid) return res.status(400).json({ error: 'invalid vmid' });
|
if (!vmid) return res.status(400).json({ error: 'invalid vmid' });
|
||||||
if (!getInstance(vmid)) return res.status(404).json({ error: 'instance not found' });
|
|
||||||
|
|
||||||
const errors = validate(req.body);
|
const existing = getInstance(vmid);
|
||||||
|
if (!existing) return res.status(404).json({ error: 'instance not found' });
|
||||||
|
|
||||||
|
const merged = { ...existing, ...(req.body ?? {}) };
|
||||||
|
|
||||||
|
const errors = validate(merged);
|
||||||
if (errors.length) return res.status(400).json({ errors });
|
if (errors.length) return res.status(400).json({ errors });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = normalise(req.body);
|
const data = normalise(merged);
|
||||||
updateInstance(vmid, data);
|
updateInstance(vmid, data);
|
||||||
res.json(getInstance(data.vmid));
|
res.json(getInstance(data.vmid));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -257,6 +257,18 @@ describe('PUT /api/instances/:vmid', () => {
|
|||||||
const res = await request(app).put('/api/instances/100').send({ ...base, vmid: 200 })
|
const res = await request(app).put('/api/instances/100').send({ ...base, vmid: 200 })
|
||||||
expect(res.status).toBe(409)
|
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 ───────────────────────────────────────────────
|
// ── DELETE /api/instances/:vmid ───────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user