From 9396c2fd6a5d5f67441fe889ed88e2940d0260ee Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 11 Dec 2023 13:05:30 +0100 Subject: [PATCH] Split tests --- .../tests/migrations.integrity.spec.ts | 25 ++++++++++++ .../appMigrations/tests/migrations.spec.ts | 38 +++++++------------ 2 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 packages/server/src/appMigrations/tests/migrations.integrity.spec.ts diff --git a/packages/server/src/appMigrations/tests/migrations.integrity.spec.ts b/packages/server/src/appMigrations/tests/migrations.integrity.spec.ts new file mode 100644 index 0000000000..145a06d7f5 --- /dev/null +++ b/packages/server/src/appMigrations/tests/migrations.integrity.spec.ts @@ -0,0 +1,25 @@ +import { context } from "@budibase/backend-core" +import * as setup from "../../api/routes/tests/utilities" +import * as migrations from "../migrations" + +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 + it("each migration can rerun safely", async () => { + const config = setup.getConfig() + await config.init() + + await config.doInContext(config.getAppId(), async () => { + const db = context.getAppDB() + for (const migration of migrations.MIGRATIONS) { + await migration.func() + const docs = await db.allDocs({ include_docs: true }) + + await migration.func() + const latestDocs = await db.allDocs({ include_docs: true }) + + expect(docs).toEqual(latestDocs) + } + }) + }) +}) diff --git a/packages/server/src/appMigrations/tests/migrations.spec.ts b/packages/server/src/appMigrations/tests/migrations.spec.ts index 9b1a0a9dd8..d27a1ac37e 100644 --- a/packages/server/src/appMigrations/tests/migrations.spec.ts +++ b/packages/server/src/appMigrations/tests/migrations.spec.ts @@ -1,8 +1,18 @@ -import { context } from "@budibase/backend-core" import * as setup from "../../api/routes/tests/utilities" -import { MIGRATIONS } from "../migrations" +import * as migrations from "../migrations" import { getAppMigrationVersion } from "../appMigrationMetadata" -import { latestMigration } from ".." +import { AppMigration } from ".." + +const mockedMigrations: AppMigration[] = [ + { + id: "20231211101320_test", + func: async () => {}, + }, +] + +jest.doMock("../migrations", () => ({ + MIGRATIONS: mockedMigrations, +})) describe("migrations", () => { it("new apps are created with the latest app migration version set", async () => { @@ -12,27 +22,7 @@ describe("migrations", () => { await config.doInContext(config.getAppId(), async () => { const migrationVersion = await getAppMigrationVersion(config.getAppId()) - expect(migrationVersion).toEqual(latestMigration) - }) - }) - - // 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 - it("each migration can rerun safely", async () => { - const config = setup.getConfig() - await config.init() - - await config.doInContext(config.getAppId(), async () => { - const db = context.getAppDB() - for (const migration of MIGRATIONS) { - await migration.func() - const docs = await db.allDocs({ include_docs: true }) - - await migration.func() - const latestDocs = await db.allDocs({ include_docs: true }) - - expect(docs).toEqual(latestDocs) - } + expect(migrationVersion).toEqual("20231211101320_test") }) }) })