EteSync test: fix eslint errors.

master
Tom Hacohen 5 years ago
parent 01a71b2840
commit 18c7dcc816

@ -74,60 +74,68 @@ it('Journal Entry sync', async () => {
const entryManager = new EteSync.EntryManager(credentials, testApiBase, journal.uid); const entryManager = new EteSync.EntryManager(credentials, testApiBase, journal.uid);
let entries = await entryManager.list(null); {
expect(entries.length).toBe(0); const entries = await entryManager.list(null);
expect(entries.length).toBe(0);
}
const syncEntry = new EteSync.SyncEntry({ action: 'ADD', content: 'bla' }); const syncEntry = new EteSync.SyncEntry({ action: 'ADD', content: 'bla' });
let prevUid = null; let prevUid = null;
const entry = new EteSync.Entry(); const entry = new EteSync.Entry();
entry.setSyncEntry(cryptoManager, syncEntry, prevUid); entry.setSyncEntry(cryptoManager, syncEntry, prevUid);
entries = [entry]; await expect(entryManager.create([entry], prevUid)).resolves.toBeDefined();
await expect(entryManager.create(entries, prevUid)).resolves.toBeDefined();
prevUid = entry.uid; prevUid = entry.uid;
// Verify we get back what we sent {
entries = await entryManager.list(null); // Verify we get back what we sent
expect(entries[0].serialize()).toEqual(entry.serialize()); const entries = await entryManager.list(null);
syncEntry.uid = entries[0].uid; expect(entries[0].serialize()).toEqual(entry.serialize());
expect(entries[0].getSyncEntry(cryptoManager, null)).toEqual(syncEntry); syncEntry.uid = entries[0].uid;
expect(entries[0].getSyncEntry(cryptoManager, null)).toEqual(syncEntry);
}
let entry2 = new EteSync.Entry(); let entry2 = new EteSync.Entry();
entry2.setSyncEntry(cryptoManager, syncEntry, prevUid); entry2.setSyncEntry(cryptoManager, syncEntry, prevUid);
// Try to push good entries with a bad prevUid {
entries = [entry2]; // Try to push good entries with a bad prevUid
await expect(entryManager.create(entries, null)).rejects.toBeInstanceOf(EteSync.HTTPError); const entries = [entry2];
await expect(entryManager.create(entries, null)).rejects.toBeInstanceOf(EteSync.HTTPError);
// Second try with good prevUid
await expect(entryManager.create(entries, prevUid)).resolves.toBeDefined(); // Second try with good prevUid
prevUid = entry2.uid; await expect(entryManager.create(entries, prevUid)).resolves.toBeDefined();
prevUid = entry2.uid;
// Check last works: }
entries = await entryManager.list(null);
expect(entries.length).toBe(2); {
// Check last works:
entries = await entryManager.list(entry.uid); let entries = await entryManager.list(null);
expect(entries.length).toBe(1); expect(entries.length).toBe(2);
entries = await entryManager.list(entry2.uid); entries = await entryManager.list(entry.uid);
expect(entries.length).toBe(0); expect(entries.length).toBe(1);
// Corrupt the journal and verify we get it: entries = await entryManager.list(entry2.uid);
entry2 = new EteSync.Entry(); expect(entries.length).toBe(0);
entry2.setSyncEntry(cryptoManager, syncEntry, 'somebaduid'); }
entries = [entry2];
await expect(entryManager.create(entries, prevUid)).resolves.toBeDefined(); {
// Corrupt the journal and verify we get it:
entries = await entryManager.list(null); entry2 = new EteSync.Entry();
entry2.setSyncEntry(cryptoManager, syncEntry, 'somebaduid');
expect(() => { await expect(entryManager.create([entry2], prevUid)).resolves.toBeDefined();
let prev = null;
for (const ent of entries) { const entries = await entryManager.list(null);
expect(ent.getSyncEntry(cryptoManager, prev)).toBeDefined();
prev = ent.uid; expect(() => {
} let prev = null;
}).toThrowError(); for (const ent of entries) {
expect(ent.getSyncEntry(cryptoManager, prev)).toBeDefined();
prev = ent.uid;
}
}).toThrowError();
}
}); });
it('User info sync', async () => { it('User info sync', async () => {

Loading…
Cancel
Save