Skip to content

Commit

Permalink
StorageSubsystem.test: apply both tests to both adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbCaudill committed Nov 1, 2023
1 parent 4e693be commit 37d9fa4
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions packages/automerge-repo/test/StorageSubsystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,34 @@ describe("StorageSubsystem", () => {
// check that it's the same doc
assert.deepStrictEqual(reloadedDoc, doc)
})
})
})

it("correctly stores incremental changes following a load", async () => {
const adapter = new DummyStorageAdapter()
const storage = new StorageSubsystem(adapter)

const doc = A.change(A.init<any>(), "test", d => {
d.foo = "bar"
})
it("correctly stores incremental changes following a load", async () => {
const storage = new StorageSubsystem(adapter)

// save it to storage
const key = parseAutomergeUrl(generateAutomergeUrl()).documentId
storage.saveDoc(key, doc)
const doc = A.change(A.init<any>(), "test", d => {
d.foo = "bar"
})

// create new storage subsystem to simulate a new process
const storage2 = new StorageSubsystem(adapter)
// save it to storage
const key = parseAutomergeUrl(generateAutomergeUrl()).documentId
storage.saveDoc(key, doc)

// reload it from storage
const reloadedDoc = await storage2.loadDoc(key)
// create new storage subsystem to simulate a new process
const storage2 = new StorageSubsystem(adapter)

assert(reloadedDoc, "doc should be loaded")
// reload it from storage
const reloadedDoc = await storage2.loadDoc(key)

// make a change
const changedDoc = A.change<any>(reloadedDoc, "test 2", d => {
d.foo = "baz"
})
assert(reloadedDoc, "doc should be loaded")

// save it to storage
storage2.saveDoc(key, changedDoc)
// make a change
const changedDoc = A.change<any>(reloadedDoc, "test 2", d => {
d.foo = "baz"
})

// check that the storage adapter contains the correct keys
assert(adapter.keys().some(k => k.startsWith(`${key}.incremental.`)))
// save it to storage
storage2.saveDoc(key, changedDoc)
})
})
})
})

0 comments on commit 37d9fa4

Please sign in to comment.