fix all tests

This commit is contained in:
Bruno Windels 2020-03-14 21:38:37 +01:00
parent 8ac230a691
commit 06e43d9ee3
2 changed files with 19 additions and 11 deletions

View file

@ -162,9 +162,11 @@ export function tests() {
return { return {
"membership trigger change": function(assert) { "membership trigger change": function(assert) {
const summary = new RoomSummary("id"); const summary = new RoomSummary("id");
const changes = summary.writeSync({}, "join"); let written = false;
const changes = summary.writeSync({}, "join", {roomSummary: {set: () => { written = true; }}});
assert(changes); assert(changes);
assert(changes.changed); assert(written);
assert.equal(changes.membership, "join");
} }
} }
} }

View file

@ -107,7 +107,7 @@ export default class Session {
} }
export function tests() { export function tests() {
function createStorageMock(session, pendingEvents) { function createStorageMock(session, pendingEvents = []) {
return { return {
readTxn() { readTxn() {
return Promise.resolve({ return Promise.resolve({
@ -120,9 +120,15 @@ export function tests() {
getAll() { getAll() {
return Promise.resolve(pendingEvents); return Promise.resolve(pendingEvents);
} }
},
roomSummary: {
getAll() {
return Promise.resolve([]);
}
} }
}); });
} },
storeNames: {}
}; };
} }
@ -131,25 +137,25 @@ export function tests() {
const session = new Session({storage: createStorageMock({ const session = new Session({storage: createStorageMock({
syncToken: "a", syncToken: "a",
syncFilterId: 5, syncFilterId: 5,
})}); }), sessionInfo: {userId: ""}});
await session.load(); await session.load();
let txnSetCalled = false; let txnSetCalled = false;
const syncTxn = { const syncTxn = {
session: { session: {
set({syncToken, syncFilterId}) { set({syncToken, syncFilterId}) {
txnSetCalled = true; txnSetCalled = true;
assert.equals(syncToken, "b"); assert.equal(syncToken, "b");
assert.equals(syncFilterId, 6); assert.equal(syncFilterId, 6);
} }
} }
}; };
const newSessionData = session.writeSync("b", 6, {}, syncTxn); const newSessionData = session.writeSync("b", 6, {}, syncTxn);
assert(txnSetCalled); assert(txnSetCalled);
assert.equals(session.syncToken, "a"); assert.equal(session.syncToken, "a");
assert.equals(session.syncFilterId, 5); assert.equal(session.syncFilterId, 5);
session.afterSync(newSessionData); session.afterSync(newSessionData);
assert.equals(session.syncToken, "b"); assert.equal(session.syncToken, "b");
assert.equals(session.syncFilterId, 6); assert.equal(session.syncFilterId, 6);
} }
} }
} }