convert storage mock to TS and add utility for mock raw database

This commit is contained in:
Bruno Windels 2021-09-28 14:19:29 +02:00
parent 9036b21b5c
commit edc3a1d33c
9 changed files with 28 additions and 10 deletions

View file

@ -181,7 +181,7 @@ import {FragmentIdComparer} from "../../../../matrix/room/timeline/FragmentIdCom
import {createAnnotation} from "../../../../matrix/room/timeline/relations.js"; import {createAnnotation} from "../../../../matrix/room/timeline/relations.js";
// mocks // mocks
import {Clock as MockClock} from "../../../../mocks/Clock.js"; import {Clock as MockClock} from "../../../../mocks/Clock.js";
import {createMockStorage} from "../../../../mocks/Storage.js"; import {createMockStorage} from "../../../../mocks/Storage";
import {ListObserver} from "../../../../mocks/ListObserver.js"; import {ListObserver} from "../../../../mocks/ListObserver.js";
import {createEvent, withTextBody, withContent} from "../../../../mocks/event.js"; import {createEvent, withTextBody, withContent} from "../../../../mocks/event.js";
import {NullLogItem, NullLogger} from "../../../../logging/NullLogger.js"; import {NullLogItem, NullLogger} from "../../../../logging/NullLogger.js";

View file

@ -351,7 +351,7 @@ export class SendQueue {
} }
import {HomeServer as MockHomeServer} from "../../../mocks/HomeServer.js"; import {HomeServer as MockHomeServer} from "../../../mocks/HomeServer.js";
import {createMockStorage} from "../../../mocks/Storage.js"; import {createMockStorage} from "../../../mocks/Storage";
import {ListObserver} from "../../../mocks/ListObserver.js"; import {ListObserver} from "../../../mocks/ListObserver.js";
import {NullLogger, NullLogItem} from "../../../logging/NullLogger.js"; import {NullLogger, NullLogItem} from "../../../logging/NullLogger.js";
import {createEvent, withTextBody, withTxnId} from "../../../mocks/event.js"; import {createEvent, withTextBody, withTxnId} from "../../../mocks/event.js";

View file

@ -343,7 +343,7 @@ export class Timeline {
import {FragmentIdComparer} from "./FragmentIdComparer.js"; import {FragmentIdComparer} from "./FragmentIdComparer.js";
import {poll} from "../../../mocks/poll.js"; import {poll} from "../../../mocks/poll.js";
import {Clock as MockClock} from "../../../mocks/Clock.js"; import {Clock as MockClock} from "../../../mocks/Clock.js";
import {createMockStorage} from "../../../mocks/Storage.js"; import {createMockStorage} from "../../../mocks/Storage";
import {ListObserver} from "../../../mocks/ListObserver.js"; import {ListObserver} from "../../../mocks/ListObserver.js";
import {createEvent, withTextBody, withContent, withSender} from "../../../mocks/event.js"; import {createEvent, withTextBody, withContent, withSender} from "../../../mocks/event.js";
import {NullLogItem} from "../../../logging/NullLogger.js"; import {NullLogItem} from "../../../logging/NullLogger.js";

View file

@ -203,7 +203,7 @@ export class GapWriter {
import {FragmentIdComparer} from "../FragmentIdComparer.js"; import {FragmentIdComparer} from "../FragmentIdComparer.js";
import {RelationWriter} from "./RelationWriter.js"; import {RelationWriter} from "./RelationWriter.js";
import {createMockStorage} from "../../../../mocks/Storage.js"; import {createMockStorage} from "../../../../mocks/Storage";
import {FragmentBoundaryEntry} from "../entries/FragmentBoundaryEntry.js"; import {FragmentBoundaryEntry} from "../entries/FragmentBoundaryEntry.js";
import {NullLogItem} from "../../../../logging/NullLogger.js"; import {NullLogItem} from "../../../../logging/NullLogger.js";
import {TimelineMock, eventIds, eventId} from "../../../../mocks/TimelineMock.ts"; import {TimelineMock, eventIds, eventId} from "../../../../mocks/TimelineMock.ts";

View file

@ -253,7 +253,7 @@ const _REDACT_KEEP_CONTENT_MAP = {
}; };
// end of matrix-js-sdk code // end of matrix-js-sdk code
import {createMockStorage} from "../../../../mocks/Storage.js"; import {createMockStorage} from "../../../../mocks/Storage";
import {createEvent, withTextBody, withRedacts, withContent} from "../../../../mocks/event.js"; import {createEvent, withTextBody, withRedacts, withContent} from "../../../../mocks/event.js";
import {createAnnotation} from "../relations.js"; import {createAnnotation} from "../relations.js";
import {FragmentIdComparer} from "../FragmentIdComparer.js"; import {FragmentIdComparer} from "../FragmentIdComparer.js";

View file

@ -256,7 +256,7 @@ export class SyncWriter {
} }
} }
import {createMockStorage} from "../../../../mocks/Storage.js"; import {createMockStorage} from "../../../../mocks/Storage";
import {createEvent, withTextBody} from "../../../../mocks/event.js"; import {createEvent, withTextBody} from "../../../../mocks/event.js";
import {Instance as nullLogger} from "../../../../logging/NullLogger.js"; import {Instance as nullLogger} from "../../../../logging/NullLogger.js";
export function tests() { export function tests() {

View file

@ -317,7 +317,7 @@ export class TimelineEventStore {
} }
} }
import {createMockStorage} from "../../../../mocks/Storage.js"; import {createMockStorage} from "../../../../mocks/Storage";
import {createEvent, withTextBody} from "../../../../mocks/event.js"; import {createEvent, withTextBody} from "../../../../mocks/event.js";
import {createEventEntry} from "../../../room/timeline/persistence/common.js"; import {createEventEntry} from "../../../room/timeline/persistence/common.js";

View file

@ -68,7 +68,7 @@ export function decodeUint32(str: string): number {
return parseInt(str, 16); return parseInt(str, 16);
} }
type CreateObjectStore = (db : IDBDatabase, txn: IDBTransaction | null, oldVersion: number, version: number) => any export type CreateObjectStore = (db : IDBDatabase, txn: IDBTransaction | null, oldVersion: number, version: number) => any
export function openDatabase(name: string, createObjectStore: CreateObjectStore, version: number, idbFactory: IDBFactory = window.indexedDB): Promise<IDBDatabase> { export function openDatabase(name: string, createObjectStore: CreateObjectStore, version: number, idbFactory: IDBFactory = window.indexedDB): Promise<IDBDatabase> {
const req = idbFactory.open(name, version); const req = idbFactory.open(name, version);

View file

@ -16,8 +16,26 @@ limitations under the License.
import {FDBFactory, FDBKeyRange} from "../../lib/fake-indexeddb/index.js"; import {FDBFactory, FDBKeyRange} from "../../lib/fake-indexeddb/index.js";
import {StorageFactory} from "../matrix/storage/idb/StorageFactory"; import {StorageFactory} from "../matrix/storage/idb/StorageFactory";
import {Storage} from "../matrix/storage/idb/Storage";
import {Instance as nullLogger} from "../logging/NullLogger.js"; import {Instance as nullLogger} from "../logging/NullLogger.js";
import {openDatabase, CreateObjectStore} from "../matrix/storage/idb/utils";
export function createMockStorage() { export function createMockStorage(): Promise<Storage> {
return new StorageFactory(null, new FDBFactory(), FDBKeyRange).create(1, nullLogger.item); return new StorageFactory(null as any, new FDBFactory(), FDBKeyRange).create("1", nullLogger.item);
}
export function createMockDatabase(name: string, createObjectStore: CreateObjectStore, impl: MockIDBImpl): Promise<IDBDatabase> {
return openDatabase(name, createObjectStore, 1, impl.idbFactory);
}
export class MockIDBImpl {
idbFactory: FDBFactory;
constructor() {
this.idbFactory = new FDBFactory();
}
get IDBKeyRange(): typeof IDBKeyRange {
return FDBKeyRange;
}
} }