forked from mystiq/hydrogen-web
add tests
This commit is contained in:
parent
6cded5319a
commit
704d7b32da
1 changed files with 32 additions and 0 deletions
|
@ -256,3 +256,35 @@ export class SyncWriter {
|
|||
return this._lastLiveKey;
|
||||
}
|
||||
}
|
||||
|
||||
import {createMockStorage} from "../../../../mocks/Storage.js";
|
||||
import {createEvent, withTextBody} from "../../../../mocks/event.js";
|
||||
import {Instance as nullLogger} from "../../../../logging/NullLogger.js";
|
||||
export function tests() {
|
||||
const roomId = "!abc:hs.tld";
|
||||
return {
|
||||
"calling timelineEvents.tryInsert with the same event id a second time fails": async assert => {
|
||||
const storage = await createMockStorage();
|
||||
const txn = await storage.readWriteTxn([storage.storeNames.timelineEvents]);
|
||||
const event = withTextBody("hello!", createEvent("m.room.message", "$abc", "@alice:hs.tld"));
|
||||
const entry1 = createEventEntry(EventKey.defaultLiveKey, roomId, event);
|
||||
assert.equal(await txn.timelineEvents.tryInsert(entry1, nullLogger.item), true);
|
||||
const entry2 = createEventEntry(EventKey.defaultLiveKey.nextKey(), roomId, event);
|
||||
assert.equal(await txn.timelineEvents.tryInsert(entry2, nullLogger.item), false);
|
||||
// fake-indexeddb still aborts the transaction when preventDefault is called by tryInsert, so don't await as it will abort
|
||||
// await txn.complete();
|
||||
},
|
||||
"calling timelineEvents.tryInsert with the same event key a second time fails": async assert => {
|
||||
const storage = await createMockStorage();
|
||||
const txn = await storage.readWriteTxn([storage.storeNames.timelineEvents]);
|
||||
const event1 = withTextBody("hello!", createEvent("m.room.message", "$abc", "@alice:hs.tld"));
|
||||
const entry1 = createEventEntry(EventKey.defaultLiveKey, roomId, event1);
|
||||
assert.equal(await txn.timelineEvents.tryInsert(entry1, nullLogger.item), true);
|
||||
const event2 = withTextBody("hello!", createEvent("m.room.message", "$def", "@alice:hs.tld"));
|
||||
const entry2 = createEventEntry(EventKey.defaultLiveKey, roomId, event2);
|
||||
assert.equal(await txn.timelineEvents.tryInsert(entry2, nullLogger.item), false);
|
||||
// fake-indexeddb still aborts the transaction when preventDefault is called by tryInsert, so don't await as it will abort
|
||||
// await txn.complete();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue