2019-07-30 09:35:42 +02:00
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
2019-01-14 21:11:54 +02:00
|
|
|
require('app-module-path').addPath(__dirname);
|
|
|
|
|
|
|
|
const { time } = require('lib/time-utils.js');
|
2019-05-06 22:35:29 +02:00
|
|
|
const { asyncTest, fileContentEqual, revisionService, setupDatabase, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync } = require('test-utils.js');
|
2020-08-08 01:13:21 +02:00
|
|
|
const SearchEngine = require('lib/services/searchengine/SearchEngine');
|
2019-01-14 21:11:54 +02:00
|
|
|
const ResourceService = require('lib/services/ResourceService');
|
|
|
|
const ItemChangeUtils = require('lib/services/ItemChangeUtils');
|
|
|
|
const Note = require('lib/models/Note');
|
2020-10-09 19:35:46 +02:00
|
|
|
const Setting = require('lib/models/Setting').default;
|
2019-01-14 21:11:54 +02:00
|
|
|
const ItemChange = require('lib/models/ItemChange');
|
|
|
|
|
|
|
|
process.on('unhandledRejection', (reason, p) => {
|
|
|
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete old changes that have been processed', asyncTest(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
|
|
|
});
|