feat: review all remote HolodoriDB changes before collection

This commit is contained in:
2026-09-08 15:31:06 +09:00
parent be94ee4be6
commit c7206377f0
12 changed files with 228 additions and 73 deletions
+19
View File
@@ -0,0 +1,19 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { jsonChanges } from './holodoridb-diff.mjs';
test('row reordering is ignored while string edits retain ID and before/after', () => {
const before = [{ id: 'a', data: { text: 'old' } }, { id: 'b', data: { text: 'same' } }];
const after = [{ id: 'b', data: { text: 'same' } }, { id: 'a', data: { text: 'new' } }];
assert.deepEqual(jsonChanges(before, after), [{ path: '$["a"]["data"]["text"]', type: 'modified', before: 'old', after: 'new' }]);
});
test('added and deleted records retain full values', () => {
const changes = jsonChanges([{ id: 'old', value: 2 }], [{ id: 'new', value: 3 }]);
assert.equal(changes[0].type, 'deleted');
assert.deepEqual(changes[0].before, { id: 'old', value: 2 });
assert.equal(changes[1].type, 'added');
assert.deepEqual(changes[1].after, { id: 'new', value: 3 });
});
test('nulls and arrays without IDs are retained without losing changes', () => {
assert.deepEqual(jsonChanges({ a: null, b: [1, 2] }, { a: false, b: [2, 1] }).map(c => c.type), ['modified', 'modified']);
});