From 3c4cf69463b2460660b7ff6f63523c1b5ae0e39d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 6 Jun 2024 15:14:59 +0100 Subject: [PATCH] Updating migration integrity test to allow certain properties to change. --- .../tests/migrations.integrity.spec.ts | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/server/src/appMigrations/tests/migrations.integrity.spec.ts b/packages/server/src/appMigrations/tests/migrations.integrity.spec.ts index 145a06d7f5..2de27ef9d4 100644 --- a/packages/server/src/appMigrations/tests/migrations.integrity.spec.ts +++ b/packages/server/src/appMigrations/tests/migrations.integrity.spec.ts @@ -2,6 +2,23 @@ import { context } from "@budibase/backend-core" import * as setup from "../../api/routes/tests/utilities" import * as migrations from "../migrations" +function removeChangeableKeys(documents: Document[]) { + const changeableKeys = ["createdAt", "updatedAt", "_rev", "rev"] + function iterate(obj: Record) { + for (let key of Object.keys(obj)) { + if (typeof obj[key] === "object") { + iterate(obj[key]) + } else if (changeableKeys.indexOf(key) !== -1) { + delete obj[key] + } + } + } + for (let doc of documents) { + iterate(doc) + } + return documents +} + describe("migration integrity", () => { // These test is checking that each migration is "idempotent". // We should be able to rerun any migration, with any rerun not modifiying anything. The code should be aware that the migration already ran @@ -13,12 +30,18 @@ describe("migration integrity", () => { const db = context.getAppDB() for (const migration of migrations.MIGRATIONS) { await migration.func() - const docs = await db.allDocs({ include_docs: true }) + const preResp = await db.allDocs({ include_docs: true }) await migration.func() - const latestDocs = await db.allDocs({ include_docs: true }) + const postResp = await db.allDocs({ include_docs: true }) - expect(docs).toEqual(latestDocs) + const preDocs = removeChangeableKeys( + preResp.rows.map(row => row.doc as Document) + ) + const postDocs = removeChangeableKeys( + postResp.rows.map(row => row.doc as Document) + ) + expect(preDocs).toEqual(postDocs) } }) })