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

Ensure keys are removed

This commit is contained in:
Adria Navarro 2024-02-29 16:48:16 +01:00
parent 720d5a4105
commit 3068e58c31
2 changed files with 32 additions and 0 deletions

View file

@ -96,6 +96,10 @@ export class DocWritethrough {
}
await this.db.put(doc)
for (const key of keysToPersist) {
await cache.delete(key, { useTenancy: false })
}
}
)

View file

@ -181,5 +181,33 @@ describe("docWritethrough", () => {
)
})
})
it("cached values are persisted only once", async () => {
await config.doInTenant(async () => {
const initialPatch = generatePatchObject(5)
await docWritethrough.patch(initialPatch)
travelForward(WRITE_RATE_MS)
await docWritethrough.patch({})
expect(await db.get(documentId)).toEqual(
expect.objectContaining(initialPatch)
)
await db.remove(await db.get(documentId))
travelForward(WRITE_RATE_MS)
const extraPatch = generatePatchObject(5)
await docWritethrough.patch(extraPatch)
expect(await db.get(documentId)).toEqual(
expect.objectContaining(extraPatch)
)
expect(await db.get(documentId)).not.toEqual(
expect.objectContaining(initialPatch)
)
})
})
})
})