Add tests
This commit is contained in:
parent
9396c2fd6a
commit
2a92263df5
|
@ -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[] = [
|
||||
jest.mock<typeof migrations>("../migrations", () => ({
|
||||
MIGRATIONS: [
|
||||
{
|
||||
id: "20231211101320_test",
|
||||
func: async () => {},
|
||||
},
|
||||
]
|
||||
|
||||
jest.doMock<typeof migrations>("../migrations", () => ({
|
||||
MIGRATIONS: mockedMigrations,
|
||||
],
|
||||
}))
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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<App> => {
|
||||
getRaw = async (appId: string): Promise<Response> => {
|
||||
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<App> => {
|
||||
const result = await this.getRaw(appId)
|
||||
return result.body.application as App
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue