diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-08-16 19:05:48 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-08-16 19:05:48 +0200 |
commit | 67dc8d30c0b9b84b5d1f37eb680729e0b7ac32f6 (patch) | |
tree | 6834aa4202df3d963035da04606b816d4cc477b3 /packages/idb-bridge/src/MemoryBackend.test.ts | |
parent | a1e0fc3b88ed4305f942fadbea66b29a3934721c (diff) | |
download | wallet-core-67dc8d30c0b9b84b5d1f37eb680729e0b7ac32f6.tar.xz |
db import/export and commit callback
Diffstat (limited to 'packages/idb-bridge/src/MemoryBackend.test.ts')
-rw-r--r-- | packages/idb-bridge/src/MemoryBackend.test.ts | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/packages/idb-bridge/src/MemoryBackend.test.ts b/packages/idb-bridge/src/MemoryBackend.test.ts index 7cc0c57e3..41bf1986a 100644 --- a/packages/idb-bridge/src/MemoryBackend.test.ts +++ b/packages/idb-bridge/src/MemoryBackend.test.ts @@ -39,9 +39,7 @@ function promiseFromTransaction( transaction: BridgeIDBTransaction, ): Promise<any> { return new Promise((resolve, reject) => { - console.log("attaching event handlers"); transaction.oncomplete = () => { - console.log("oncomplete was called from promise"); resolve(); }; transaction.onerror = () => { @@ -309,3 +307,42 @@ test("simple deletion", async t => { t.pass(); }); + +test("export", async t => { + const backend = new MemoryBackend(); + const idb = new BridgeIDBFactory(backend); + + const request = idb.open("library"); + request.onupgradeneeded = () => { + const db = request.result; + const store = db.createObjectStore("books", { keyPath: "isbn" }); + const titleIndex = store.createIndex("by_title", "title", { unique: true }); + const authorIndex = store.createIndex("by_author", "author"); + }; + + const db: BridgeIDBDatabase = await promiseFromRequest(request); + + + const tx = db.transaction("books", "readwrite"); + tx.oncomplete = () => { + console.log("oncomplete called"); + }; + + const store = tx.objectStore("books"); + + store.put({ title: "Quarry Memories", author: "Fred", isbn: 123456 }); + store.put({ title: "Water Buffaloes", author: "Fred", isbn: 234567 }); + store.put({ title: "Bedrock Nights", author: "Barney", isbn: 345678 }); + + await promiseFromTransaction(tx); + + const exportedData = backend.exportDump(); + const backend2 = new MemoryBackend(); + backend2.importDump(exportedData); + const exportedData2 = backend2.exportDump(); + + t.assert(exportedData.databases["library"].objectStores["books"].records.length === 3); + t.deepEqual(exportedData, exportedData2); + + t.pass(); +});
\ No newline at end of file |