Merge pull request 'fix: clear instance history on delete and import' (#37) from fix/delete-clears-history into dev
Reviewed-on: #37
This commit was merged in pull request #37.
This commit is contained in:
@@ -151,11 +151,13 @@ export function updateInstance(vmid, data) {
|
||||
}
|
||||
|
||||
export function deleteInstance(vmid) {
|
||||
return db.prepare('DELETE FROM instances WHERE vmid = ?').run(vmid);
|
||||
db.prepare('DELETE FROM instance_history WHERE vmid = ?').run(vmid);
|
||||
db.prepare('DELETE FROM instances WHERE vmid = ?').run(vmid);
|
||||
}
|
||||
|
||||
export function importInstances(rows) {
|
||||
db.exec('BEGIN');
|
||||
db.exec('DELETE FROM instance_history');
|
||||
db.exec('DELETE FROM instances');
|
||||
const insert = db.prepare(`
|
||||
INSERT INTO instances
|
||||
|
||||
@@ -164,6 +164,19 @@ describe('deleteInstance', () => {
|
||||
expect(getInstance(1)).toBeNull();
|
||||
expect(getInstance(2)).not.toBeNull();
|
||||
});
|
||||
|
||||
it('clears history for the deleted instance', () => {
|
||||
createInstance({ ...base, name: 'a', vmid: 1 });
|
||||
deleteInstance(1);
|
||||
expect(getInstanceHistory(1)).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('does not clear history for other instances', () => {
|
||||
createInstance({ ...base, name: 'a', vmid: 1 });
|
||||
createInstance({ ...base, name: 'b', vmid: 2 });
|
||||
deleteInstance(1);
|
||||
expect(getInstanceHistory(2).length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ── importInstances ───────────────────────────────────────────────────────────
|
||||
@@ -183,6 +196,12 @@ describe('importInstances', () => {
|
||||
importInstances([]);
|
||||
expect(getInstances()).toEqual([]);
|
||||
});
|
||||
|
||||
it('clears history for all replaced instances', () => {
|
||||
createInstance({ ...base, name: 'old', vmid: 1 });
|
||||
importInstances([{ ...base, name: 'new', vmid: 2 }]);
|
||||
expect(getInstanceHistory(1)).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ── instance history ─────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user