1
0
Fork 0
mirror of synced 2024-10-05 12:34:50 +13:00

Add persisting tests

This commit is contained in:
Adria Navarro 2024-02-29 15:28:35 +01:00
parent 40d7a0a741
commit dc4d1fdbda

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