Add persisting tests

This commit is contained in:
Adria Navarro 2024-02-29 15:28:35 +01:00
parent 64ea969aaf
commit b1027527b3
1 changed files with 38 additions and 1 deletions

View File

@ -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)
})
})
})
})