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']); });