1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/packages/lib/services/synchronizer/syncInfoUtils.test.ts

96 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-08-17 13:03:19 +02:00
import { afterAllCleanUp, setupDatabaseAndSynchronizer, switchClient, encryptionService } from '../../testing/test-utils';
import MasterKey from '../../models/MasterKey';
import { masterKeyEnabled, setMasterKeyEnabled, SyncInfo, syncInfoEquals } from './syncInfoUtils';
2021-08-17 13:03:19 +02:00
describe('syncInfoUtils', function() {
beforeEach(async (done) => {
await setupDatabaseAndSynchronizer(1);
await switchClient(1);
done();
});
afterAll(async () => {
await afterAllCleanUp();
});
it('should enable or disable a master key', async () => {
const mk1 = await MasterKey.save(await encryptionService().generateMasterKey('111111'));
const mk2 = await MasterKey.save(await encryptionService().generateMasterKey('111111'));
setMasterKeyEnabled(mk2.id, false);
expect(masterKeyEnabled(await MasterKey.load(mk1.id))).toBe(true);
expect(masterKeyEnabled(await MasterKey.load(mk2.id))).toBe(false);
setMasterKeyEnabled(mk1.id, false);
expect(masterKeyEnabled(await MasterKey.load(mk1.id))).toBe(false);
expect(masterKeyEnabled(await MasterKey.load(mk2.id))).toBe(false);
setMasterKeyEnabled(mk1.id, true);
expect(masterKeyEnabled(await MasterKey.load(mk1.id))).toBe(true);
expect(masterKeyEnabled(await MasterKey.load(mk2.id))).toBe(false);
});
it('should tell if two sync info are equal', async () => {
{
const syncInfo1 = new SyncInfo();
const syncInfo2 = new SyncInfo();
expect(syncInfoEquals(syncInfo1, syncInfo2)).toBe(true);
}
{
const syncInfo1 = new SyncInfo();
syncInfo1.masterKeys = [{
id: 'id',
content: 'content',
}];
const syncInfo2 = new SyncInfo();
syncInfo2.masterKeys = [{
id: 'id',
content: 'different',
}];
expect(syncInfoEquals(syncInfo1, syncInfo2)).toBe(false);
}
{
const syncInfo1 = new SyncInfo();
syncInfo1.masterKeys = [{
id: 'id',
content: 'content',
}];
const syncInfo2 = new SyncInfo();
syncInfo2.masterKeys = [{
id: 'id',
content: 'content',
}];
expect(syncInfoEquals(syncInfo1, syncInfo2)).toBe(true);
}
{
// Should disregard object key order
const syncInfo1 = new SyncInfo();
syncInfo1.masterKeys = [{
content: 'content',
id: 'id',
}];
const syncInfo2 = new SyncInfo();
syncInfo2.masterKeys = [{
id: 'id',
content: 'content',
}];
expect(syncInfoEquals(syncInfo1, syncInfo2)).toBe(true);
}
});
2021-08-17 13:03:19 +02:00
});