1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Desktop,Mobile,Cli: Fixes #11017: Delete revisions on the sync target when deleted locally (#11035)

This commit is contained in:
Henry Heino
2024-09-21 05:04:54 -07:00
committed by GitHub
parent a56f104fe8
commit d13e7b32c3
3 changed files with 152 additions and 28 deletions

View File

@ -6,6 +6,32 @@ import Revision from '../models/Revision';
import BaseModel, { ModelType } from '../BaseModel';
import RevisionService from '../services/RevisionService';
import { MarkupLanguage } from '../../renderer';
import { NoteEntity } from './database/types';
interface CreateTestRevisionOptions {
// How long to pause (in milliseconds) between each note modification.
// For example, [10, 20] would modify the note twice, with pauses of 10ms and 20ms.
delaysBetweenModifications: number[];
}
const createTestRevisions = async (
noteProperties: Partial<NoteEntity>,
{ delaysBetweenModifications }: CreateTestRevisionOptions,
) => {
const note = await Note.save({
title: 'note',
...noteProperties,
});
let counter = 0;
for (const delay of delaysBetweenModifications) {
jest.advanceTimersByTime(delay);
await Note.save({ ...noteProperties, id: note.id, title: `note REV${counter++}` });
await revisionService().collectRevisions();
}
return note;
};
describe('services/RevisionService', () => {
@ -13,6 +39,8 @@ describe('services/RevisionService', () => {
await setupDatabaseAndSynchronizer(1);
await switchClient(1);
Setting.setValue('revisionService.intervalBetweenRevisions', 0);
jest.useFakeTimers({ advanceTimers: true });
});
it('should create diff and rebuild notes', (async () => {
@ -185,6 +213,25 @@ describe('services/RevisionService', () => {
}
}));
it('should not error on revisions for missing (not downloaded yet/permanently deleted) notes', async () => {
Setting.setValue('revisionService.intervalBetweenRevisions', 100);
const note = await createTestRevisions({
share_id: 'test-share-id',
}, { delaysBetweenModifications: [200, 400, 600, 8_000] });
const getNoteRevisions = () => {
return Revision.allByType(BaseModel.TYPE_NOTE, note.id);
};
expect(await getNoteRevisions()).toHaveLength(4);
await Note.delete(note.id, { toTrash: false, sourceDescription: 'tests/RevisionService' });
await revisionService().deleteOldRevisions(4_000);
// Should leave newer revisions (handle the case where revisions are downloaded before the note).
expect(await getNoteRevisions()).toHaveLength(1);
});
it('should handle conflicts', (async () => {
const service = new RevisionService();