diff --git a/packages/server/src/appMigrations/tests/migrations.spec.ts b/packages/server/src/appMigrations/tests/migrations.spec.ts index d27a1ac37e..5eb8535695 100644 --- a/packages/server/src/appMigrations/tests/migrations.spec.ts +++ b/packages/server/src/appMigrations/tests/migrations.spec.ts @@ -1,17 +1,15 @@ +import { Header } from "@budibase/backend-core" import * as setup from "../../api/routes/tests/utilities" import * as migrations from "../migrations" import { getAppMigrationVersion } from "../appMigrationMetadata" -import { AppMigration } from ".." -const mockedMigrations: AppMigration[] = [ - { - id: "20231211101320_test", - func: async () => {}, - }, -] - -jest.doMock("../migrations", () => ({ - MIGRATIONS: mockedMigrations, +jest.mock("../migrations", () => ({ + MIGRATIONS: [ + { + id: "20231211101320_test", + func: async () => {}, + }, + ], })) describe("migrations", () => { @@ -25,4 +23,31 @@ describe("migrations", () => { expect(migrationVersion).toEqual("20231211101320_test") }) }) + + it("accessing an app that has no pending migrations will not attach the migrating header", async () => { + const config = setup.getConfig() + await config.init() + + const appId = config.getAppId() + + const response = await config.api.application.getRaw(appId) + + expect(response.headers[Header.MIGRATING_APP]).toBeUndefined() + }) + + it("accessing an app that has pending migrations will attach the migrating header", async () => { + const config = setup.getConfig() + await config.init() + + const appId = config.getAppId() + + migrations.MIGRATIONS.push({ + id: "20231211105812_new-test", + func: async () => {}, + }) + + const response = await config.api.application.getRaw(appId) + + expect(response.headers[Header.MIGRATING_APP]).toEqual(appId) + }) }) diff --git a/packages/server/src/tests/utilities/api/application.ts b/packages/server/src/tests/utilities/api/application.ts index 85bc4e4173..9c784bade1 100644 --- a/packages/server/src/tests/utilities/api/application.ts +++ b/packages/server/src/tests/utilities/api/application.ts @@ -1,3 +1,4 @@ +import { Response } from "supertest" import { App } from "@budibase/types" import TestConfiguration from "../TestConfiguration" import { TestAPI } from "./base" @@ -7,12 +8,17 @@ export class ApplicationAPI extends TestAPI { super(config) } - get = async (appId: string): Promise => { + getRaw = async (appId: string): Promise => { const result = await this.request .get(`/api/applications/${appId}/appPackage`) .set(this.config.defaultHeaders()) .expect("Content-Type", /json/) .expect(200) + return result + } + + get = async (appId: string): Promise => { + const result = await this.getRaw(appId) return result.body.application as App } }