From e07bc5b5720546e9c5229ff4ca88bfb0f4182078 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jul 2024 17:26:29 +0200 Subject: [PATCH] Add bulkDocs test --- .../src/db/couch/tests/DatabaseImpl.spec.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/packages/backend-core/src/db/couch/tests/DatabaseImpl.spec.ts b/packages/backend-core/src/db/couch/tests/DatabaseImpl.spec.ts index 8e86cd7f74..039564b243 100644 --- a/packages/backend-core/src/db/couch/tests/DatabaseImpl.spec.ts +++ b/packages/backend-core/src/db/couch/tests/DatabaseImpl.spec.ts @@ -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(), + }) + } + }) + }) })