Ensure keys are removed

This commit is contained in:
Adria Navarro 2024-02-29 16:48:16 +01:00
parent 41dde9722f
commit 223637999a
2 changed files with 32 additions and 0 deletions

View File

@ -96,6 +96,10 @@ export class DocWritethrough {
} }
await this.db.put(doc) 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)
)
})
})
}) })
}) })