Add bulkDocs test
This commit is contained in:
parent
8280c2ccfd
commit
e07bc5b572
|
@ -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(),
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue