Add persisting tests
This commit is contained in:
parent
74aae19a7e
commit
bfde028e9b
|
@ -33,7 +33,7 @@ describe("docWritethrough", () => {
|
|||
docWritethrough = new DocWritethrough(db, documentId, WRITE_RATE_MS)
|
||||
})
|
||||
|
||||
it("patching will not persist until timeout is hit", async () => {
|
||||
it("patching will not persist if timeout does not hit", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
await docWritethrough.patch(generatePatchObject(2))
|
||||
await docWritethrough.patch(generatePatchObject(2))
|
||||
|
@ -43,5 +43,42 @@ describe("docWritethrough", () => {
|
|||
expect(await db.docExists(documentId)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
it("patching will persist if timeout hits and next patch is called", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
const patch1 = generatePatchObject(2)
|
||||
const patch2 = generatePatchObject(2)
|
||||
await docWritethrough.patch(patch1)
|
||||
await docWritethrough.patch(patch2)
|
||||
|
||||
tk.travel(Date.now() + WRITE_RATE_MS)
|
||||
|
||||
const patch3 = generatePatchObject(3)
|
||||
await docWritethrough.patch(patch3)
|
||||
|
||||
expect(await db.get(documentId)).toEqual({
|
||||
_id: documentId,
|
||||
...patch1,
|
||||
...patch2,
|
||||
...patch3,
|
||||
_rev: expect.stringMatching(/1-.+/),
|
||||
createdAt: new Date(initialTime + 500).toISOString(),
|
||||
updatedAt: new Date(initialTime + 500).toISOString(),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("patching will not persist even if timeout hits but next patch is not callec", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
const patch1 = generatePatchObject(2)
|
||||
const patch2 = generatePatchObject(2)
|
||||
await docWritethrough.patch(patch1)
|
||||
await docWritethrough.patch(patch2)
|
||||
|
||||
tk.travel(Date.now() + WRITE_RATE_MS)
|
||||
|
||||
expect(await db.docExists(documentId)).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue