mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
core: fix sync & monographs tests
This commit is contained in:
@@ -53,9 +53,7 @@ test(
|
||||
|
||||
const monographId = await db.monographs.publish(id);
|
||||
|
||||
expect(
|
||||
(await db.monographs.all()).find((m) => m.id === id)
|
||||
).toBeDefined();
|
||||
expect(await db.monographs.all.has(id)).toBeTruthy();
|
||||
|
||||
const monograph = await db.monographs.get(monographId);
|
||||
const note = await db.notes.note(id);
|
||||
@@ -98,14 +96,10 @@ test(
|
||||
await db.monographs.refresh();
|
||||
|
||||
await db.monographs.publish(id);
|
||||
expect(
|
||||
(await db.monographs.all()).find((m) => m.id === id)
|
||||
).toBeDefined();
|
||||
expect(await db.monographs.all.has(id)).toBeTruthy();
|
||||
|
||||
await db.monographs.unpublish(id);
|
||||
expect(
|
||||
(await db.monographs.all()).find((m) => m.id === id)
|
||||
).toBeUndefined();
|
||||
expect(await db.monographs.all.has(id)).toBeFalsy();
|
||||
|
||||
await logout(db);
|
||||
}),
|
||||
|
||||
@@ -48,7 +48,10 @@ test(
|
||||
deviceB.eventManager.subscribe(EVENTS.syncProgress, onSyncProgress);
|
||||
|
||||
await deviceC.notes.add({ title: "new note 1" });
|
||||
await syncAndWait(deviceC, deviceC);
|
||||
|
||||
await deviceC.sync(true);
|
||||
await deviceA.sync(true);
|
||||
await deviceB.sync(true);
|
||||
|
||||
expect(types.every((t) => t === "download")).toBe(true);
|
||||
|
||||
@@ -74,6 +77,7 @@ test(
|
||||
});
|
||||
|
||||
await syncAndWait(deviceA, deviceB);
|
||||
await deviceA.sync(true);
|
||||
|
||||
expect(await deviceA.notes.note(note2Id)).toBeTruthy();
|
||||
expect(await deviceB.notes.note(note1Id)).toBeTruthy();
|
||||
@@ -326,7 +330,9 @@ async function initializeDevice(id, capabilities = []) {
|
||||
compressor: Compressor,
|
||||
sqliteOptions: {
|
||||
dialect: (name) =>
|
||||
new SqliteDialect({ database: BetterSQLite3(":memory:") })
|
||||
new SqliteDialect({
|
||||
database: BetterSQLite3(":memory:").unsafeMode(true)
|
||||
})
|
||||
},
|
||||
batchSize: 500
|
||||
});
|
||||
@@ -367,25 +373,19 @@ function syncAndWait(deviceA, deviceB, force = false) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ref2 = deviceB.eventManager.subscribe(
|
||||
EVENTS.databaseSyncRequested,
|
||||
(full, force, lastSynced) => {
|
||||
console.log("sync requested by device A", full, force, lastSynced);
|
||||
(full, force) => {
|
||||
if (!full) return;
|
||||
console.log("sync requested by device A", full, force);
|
||||
ref2.unsubscribe();
|
||||
deviceB
|
||||
.sync({
|
||||
type: full ? "full" : "send",
|
||||
force,
|
||||
serverLastSynced: lastSynced
|
||||
force
|
||||
})
|
||||
.catch(reject);
|
||||
}
|
||||
);
|
||||
|
||||
const ref = deviceB.eventManager.subscribe(EVENTS.syncCompleted, () => {
|
||||
ref.unsubscribe();
|
||||
console.log("sync completed.");
|
||||
resolve();
|
||||
});
|
||||
|
||||
console.log(
|
||||
"waiting for sync...",
|
||||
"Device A:",
|
||||
|
||||
@@ -50,7 +50,9 @@ function databaseTest() {
|
||||
compressor: Compressor,
|
||||
sqliteOptions: {
|
||||
dialect: (name) =>
|
||||
new SqliteDialect({ database: BetterSQLite3(":memory:") })
|
||||
new SqliteDialect({
|
||||
database: BetterSQLite3(":memory:").unsafeMode(true)
|
||||
})
|
||||
},
|
||||
batchSize: 500
|
||||
});
|
||||
|
||||
@@ -59,7 +59,8 @@ export class AutoSync {
|
||||
item &&
|
||||
(item.remote ||
|
||||
("localOnly" in item && item.localOnly) ||
|
||||
("failed" in item && item.failed) || ("dateUploaded" in item && item.dateUploaded))
|
||||
("failed" in item && item.failed) ||
|
||||
("dateUploaded" in item && item.dateUploaded))
|
||||
)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user