|
|
@ -74,37 +74,43 @@ 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);
|
|
|
|
{
|
|
|
|
|
|
|
|
const entries = await entryManager.list(null);
|
|
|
|
expect(entries.length).toBe(0);
|
|
|
|
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
|
|
|
|
// Verify we get back what we sent
|
|
|
|
entries = await entryManager.list(null);
|
|
|
|
const entries = await entryManager.list(null);
|
|
|
|
expect(entries[0].serialize()).toEqual(entry.serialize());
|
|
|
|
expect(entries[0].serialize()).toEqual(entry.serialize());
|
|
|
|
syncEntry.uid = entries[0].uid;
|
|
|
|
syncEntry.uid = entries[0].uid;
|
|
|
|
expect(entries[0].getSyncEntry(cryptoManager, null)).toEqual(syncEntry);
|
|
|
|
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
|
|
|
|
// Try to push good entries with a bad prevUid
|
|
|
|
entries = [entry2];
|
|
|
|
const entries = [entry2];
|
|
|
|
await expect(entryManager.create(entries, null)).rejects.toBeInstanceOf(EteSync.HTTPError);
|
|
|
|
await expect(entryManager.create(entries, null)).rejects.toBeInstanceOf(EteSync.HTTPError);
|
|
|
|
|
|
|
|
|
|
|
|
// Second try with good prevUid
|
|
|
|
// Second try with good prevUid
|
|
|
|
await expect(entryManager.create(entries, prevUid)).resolves.toBeDefined();
|
|
|
|
await expect(entryManager.create(entries, prevUid)).resolves.toBeDefined();
|
|
|
|
prevUid = entry2.uid;
|
|
|
|
prevUid = entry2.uid;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
// Check last works:
|
|
|
|
// Check last works:
|
|
|
|
entries = await entryManager.list(null);
|
|
|
|
let entries = await entryManager.list(null);
|
|
|
|
expect(entries.length).toBe(2);
|
|
|
|
expect(entries.length).toBe(2);
|
|
|
|
|
|
|
|
|
|
|
|
entries = await entryManager.list(entry.uid);
|
|
|
|
entries = await entryManager.list(entry.uid);
|
|
|
@ -112,14 +118,15 @@ it('Journal Entry sync', async () => {
|
|
|
|
|
|
|
|
|
|
|
|
entries = await entryManager.list(entry2.uid);
|
|
|
|
entries = await entryManager.list(entry2.uid);
|
|
|
|
expect(entries.length).toBe(0);
|
|
|
|
expect(entries.length).toBe(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
// Corrupt the journal and verify we get it:
|
|
|
|
// Corrupt the journal and verify we get it:
|
|
|
|
entry2 = new EteSync.Entry();
|
|
|
|
entry2 = new EteSync.Entry();
|
|
|
|
entry2.setSyncEntry(cryptoManager, syncEntry, 'somebaduid');
|
|
|
|
entry2.setSyncEntry(cryptoManager, syncEntry, 'somebaduid');
|
|
|
|
entries = [entry2];
|
|
|
|
await expect(entryManager.create([entry2], prevUid)).resolves.toBeDefined();
|
|
|
|
await expect(entryManager.create(entries, prevUid)).resolves.toBeDefined();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entries = await entryManager.list(null);
|
|
|
|
const entries = await entryManager.list(null);
|
|
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
expect(() => {
|
|
|
|
let prev = null;
|
|
|
|
let prev = null;
|
|
|
@ -128,6 +135,7 @@ it('Journal Entry sync', async () => {
|
|
|
|
prev = ent.uid;
|
|
|
|
prev = ent.uid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).toThrowError();
|
|
|
|
}).toThrowError();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('User info sync', async () => {
|
|
|
|
it('User info sync', async () => {
|
|
|
|