2019-07-30 09:35:42 +02:00
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
2019-01-14 21:11:54 +02:00
|
|
|
|
2020-11-07 17:59:37 +02:00
|
|
|
const time = require('@joplin/lib/time').default;
|
2020-12-01 20:05:24 +02:00
|
|
|
const { fileContentEqual, revisionService, setupDatabase, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync } = require('./test-utils.js');
|
2020-11-07 17:59:37 +02:00
|
|
|
const SearchEngine = require('@joplin/lib/services/searchengine/SearchEngine');
|
2020-11-08 18:46:48 +02:00
|
|
|
const ResourceService = require('@joplin/lib/services/ResourceService').default;
|
2020-11-07 17:59:37 +02:00
|
|
|
const ItemChangeUtils = require('@joplin/lib/services/ItemChangeUtils');
|
|
|
|
const Note = require('@joplin/lib/models/Note');
|
|
|
|
const Setting = require('@joplin/lib/models/Setting').default;
|
|
|
|
const ItemChange = require('@joplin/lib/models/ItemChange');
|
2019-01-14 21:11:54 +02:00
|
|
|
|
|
|
|
let searchEngine = null;
|
|
|
|
|
|
|
|
describe('models_ItemChange', function() {
|
|
|
|
|
|
|
|
beforeEach(async (done) => {
|
|
|
|
await setupDatabaseAndSynchronizer(1);
|
2019-11-12 18:16:39 +02:00
|
|
|
await switchClient(1);
|
2019-01-14 21:11:54 +02:00
|
|
|
searchEngine = new SearchEngine();
|
|
|
|
searchEngine.setDb(db());
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should delete old changes that have been processed', (async () => {
|
2019-07-30 09:35:42 +02:00
|
|
|
const n1 = await Note.save({ title: 'abcd efgh' }); // 3
|
2019-01-14 21:11:54 +02:00
|
|
|
|
|
|
|
await ItemChange.waitForAllSaved();
|
|
|
|
|
|
|
|
expect(await ItemChange.lastChangeId()).toBe(1);
|
|
|
|
|
|
|
|
const resourceService = new ResourceService();
|
|
|
|
|
|
|
|
await searchEngine.syncTables();
|
|
|
|
// If we run this now, it should not delete any change because
|
|
|
|
// the resource service has not yet processed the change
|
|
|
|
await ItemChangeUtils.deleteProcessedChanges();
|
|
|
|
expect(await ItemChange.lastChangeId()).toBe(1);
|
|
|
|
|
|
|
|
await resourceService.indexNoteResources();
|
|
|
|
await ItemChangeUtils.deleteProcessedChanges();
|
2019-05-06 22:35:29 +02:00
|
|
|
expect(await ItemChange.lastChangeId()).toBe(1);
|
2019-01-14 21:11:54 +02:00
|
|
|
|
2019-05-06 22:35:29 +02:00
|
|
|
await revisionService().collectRevisions();
|
|
|
|
await ItemChangeUtils.deleteProcessedChanges();
|
2019-01-14 21:11:54 +02:00
|
|
|
expect(await ItemChange.lastChangeId()).toBe(0);
|
|
|
|
}));
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|