From 643d57b58323172669e86cfe0e5005a96dfdc528 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jul 2024 17:29:03 +0200 Subject: [PATCH] Add extra tests --- .../src/db/couch/tests/DatabaseImpl.spec.ts | 33 +++++++++++++++++++ 1 file changed, 33 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 039564b243..89eecc3785 100644 --- a/packages/backend-core/src/db/couch/tests/DatabaseImpl.spec.ts +++ b/packages/backend-core/src/db/couch/tests/DatabaseImpl.spec.ts @@ -81,5 +81,38 @@ describe("DatabaseImpl", () => { }) } }) + + it("keeps existing createdAt", async () => { + const ids = generator.unique(() => generator.guid(), 2) + + await db.bulkDocs(ids.map(id => ({ _id: id }))) + tk.travel(100) + + const newDocs = generator + .unique(() => generator.guid(), 3) + .map(id => ({ _id: id })) + const docsToUpdate = await Promise.all( + ids.map(async id => ({ ...(await db.get(id)), newValue: 123 })) + ) + await db.bulkDocs([...newDocs, ...docsToUpdate]) + + for (const { _id } of docsToUpdate) { + expect(await db.get(_id)).toEqual({ + _id, + _rev: expect.any(String), + newValue: 123, + createdAt: initialTime.toISOString(), + updatedAt: new Date().toISOString(), + }) + } + for (const { _id } of newDocs) { + expect(await db.get(_id)).toEqual({ + _id, + _rev: expect.any(String), + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + }) + } + }) }) })