1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

docWritethrough test

This commit is contained in:
Adria Navarro 2024-02-29 15:23:32 +01:00
parent 3998faaf3a
commit 64ea969aaf

View file

@ -0,0 +1,47 @@
import tk from "timekeeper"
import { env } from "../.."
import { DBTestConfiguration, generator, structures } from "../../../tests"
import { getDB } from "../../db"
import { DocWritethrough } from "../docWritethrough"
import _ from "lodash"
env._set("MOCK_REDIS", null)
const initialTime = Date.now()
const WRITE_RATE_MS = 500
describe("docWritethrough", () => {
const config = new DBTestConfiguration()
const db = getDB(structures.db.id())
let documentId: string
let docWritethrough: DocWritethrough
describe("patch", () => {
function generatePatchObject(fieldCount: number) {
const keys = generator.unique(() => generator.word(), fieldCount)
return keys.reduce((acc, c) => {
acc[c] = generator.word()
return acc
}, {} as Record<string, any>)
}
beforeEach(() => {
tk.freeze(initialTime)
documentId = structures.db.id()
docWritethrough = new DocWritethrough(db, documentId, WRITE_RATE_MS)
})
it("patching will not persist until timeout is hit", async () => {
await config.doInTenant(async () => {
await docWritethrough.patch(generatePatchObject(2))
await docWritethrough.patch(generatePatchObject(2))
tk.travel(Date.now() + WRITE_RATE_MS - 1)
await docWritethrough.patch(generatePatchObject(2))
expect(await db.docExists(documentId)).toBe(false)
})
})
})
})