Initial implementation
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import DiffMatchPatch from 'diff-match-patch';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { reconstructRevision } from '../src/domain/revisions.js';
|
||||
import type { RevisionRecord } from '../src/domain/types.js';
|
||||
|
||||
const dmp = new DiffMatchPatch();
|
||||
const patch = (before: string, after: string) => JSON.stringify(dmp.patch_make(before, after));
|
||||
|
||||
describe('revision reconstruction', () => {
|
||||
test('follows Joplin parent revisions and applies text and metadata patches', () => {
|
||||
const first: RevisionRecord = {
|
||||
id: 'r1', parent_id: '', item_id: 'note', item_type: 1, item_updated_time: 10,
|
||||
title_diff: patch('', 'Title one'), body_diff: patch('', 'First body'),
|
||||
metadata_diff: JSON.stringify({ new: { parent_id: 'folder', user_created_time: 1, user_updated_time: 10 }, deleted: [] }),
|
||||
encryption_applied: 0,
|
||||
};
|
||||
const second: RevisionRecord = {
|
||||
id: 'r2', parent_id: 'r1', item_id: 'note', item_type: 1, item_updated_time: 20,
|
||||
title_diff: patch('Title one', 'Title two'), body_diff: patch('First body', 'Second body'),
|
||||
metadata_diff: JSON.stringify({ new: { user_updated_time: 20 }, deleted: [] }),
|
||||
encryption_applied: 0,
|
||||
};
|
||||
expect(reconstructRevision([first, second], 'r2')).toEqual({
|
||||
id: 'r2', note_id: 'note', item_updated_time: 20, title: 'Title two', body: 'Second body',
|
||||
parent_id: 'folder', user_created_time: 1, user_updated_time: 20,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user