2019-07-30 09:35:42 +02:00
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
2018-10-30 02:17:50 +02:00
|
|
|
require('app-module-path').addPath(__dirname);
|
|
|
|
|
|
|
|
const { time } = require('lib/time-utils.js');
|
|
|
|
const { asyncTest, fileContentEqual, setupDatabase, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync } = require('test-utils.js');
|
|
|
|
const Folder = require('lib/models/Folder.js');
|
|
|
|
const Note = require('lib/models/Note.js');
|
2018-10-31 02:35:57 +02:00
|
|
|
const BaseItem = require('lib/models/BaseItem.js');
|
2018-10-30 02:17:50 +02:00
|
|
|
const Resource = require('lib/models/Resource.js');
|
|
|
|
const BaseModel = require('lib/BaseModel.js');
|
|
|
|
const { shim } = require('lib/shim');
|
|
|
|
|
|
|
|
process.on('unhandledRejection', (reason, p) => {
|
|
|
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
|
|
|
});
|
|
|
|
|
|
|
|
async function allItems() {
|
|
|
|
let folders = await Folder.all();
|
|
|
|
let notes = await Note.all();
|
|
|
|
return folders.concat(notes);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('models_BaseItem', function() {
|
|
|
|
|
|
|
|
beforeEach(async (done) => {
|
|
|
|
await setupDatabaseAndSynchronizer(1);
|
|
|
|
await switchClient(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2018-10-31 02:35:57 +02:00
|
|
|
// This is to handle the case where a property is removed from a BaseItem table - in that case files in
|
|
|
|
// the sync target will still have the old property but we don't need it locally.
|
|
|
|
it('should ignore properties that are present in sync file but not in database when serialising', asyncTest(async () => {
|
2019-07-30 09:35:42 +02:00
|
|
|
let folder = await Folder.save({ title: 'folder1' });
|
|
|
|
|
2018-10-31 02:35:57 +02:00
|
|
|
let serialized = await Folder.serialize(folder);
|
2019-07-30 09:35:42 +02:00
|
|
|
serialized += '\nignore_me: true';
|
2018-10-31 02:35:57 +02:00
|
|
|
|
|
|
|
let unserialized = await Folder.unserialize(serialized);
|
|
|
|
|
|
|
|
expect('ignore_me' in unserialized).toBe(false);
|
2018-10-30 02:17:50 +02:00
|
|
|
}));
|
2019-07-30 09:35:42 +02:00
|
|
|
|
2019-05-06 22:25:14 +02:00
|
|
|
it('should not modify title when unserializing', asyncTest(async () => {
|
2019-07-30 09:35:42 +02:00
|
|
|
let folder1 = await Folder.save({ title: '' });
|
|
|
|
let folder2 = await Folder.save({ title: 'folder1' });
|
|
|
|
|
|
|
|
let serialized1 = await Folder.serialize(folder1);
|
|
|
|
let unserialized1 = await Folder.unserialize(serialized1);
|
|
|
|
|
|
|
|
expect(unserialized1.title).toBe(folder1.title);
|
|
|
|
|
|
|
|
let serialized2 = await Folder.serialize(folder2);
|
|
|
|
let unserialized2 = await Folder.unserialize(serialized2);
|
|
|
|
|
|
|
|
expect(unserialized2.title).toBe(folder2.title);
|
2019-05-06 22:25:14 +02:00
|
|
|
}));
|
2018-10-30 02:17:50 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|