Add bulkDocs test

This commit is contained in:
Adria Navarro 2024-07-30 17:26:29 +02:00
parent 8280c2ccfd
commit e07bc5b572
1 changed files with 38 additions and 0 deletions

View File

@ -44,4 +44,42 @@ describe("DatabaseImpl", () => {
})
})
})
describe("bulkDocs", () => {
it("persists createdAt and updatedAt fields", async () => {
const ids = generator.unique(() => generator.guid(), 5)
await db.bulkDocs(ids.map(id => ({ _id: id })))
for (const id of ids) {
expect(await db.get(id)).toEqual({
_id: id,
_rev: expect.any(String),
createdAt: initialTime.toISOString(),
updatedAt: initialTime.toISOString(),
})
}
})
it("updates updated at fields", async () => {
const ids = generator.unique(() => generator.guid(), 5)
await db.bulkDocs(ids.map(id => ({ _id: id })))
tk.travel(100)
const docsToUpdate = await Promise.all(
ids.map(async id => ({ ...(await db.get(id)), newValue: 123 }))
)
await db.bulkDocs(docsToUpdate)
for (const id of ids) {
expect(await db.get(id)).toEqual({
_id: id,
_rev: expect.any(String),
newValue: 123,
createdAt: initialTime.toISOString(),
updatedAt: new Date().toISOString(),
})
}
})
})
})