Split tests
This commit is contained in:
parent
34d3edc2db
commit
9396c2fd6a
|
@ -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)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
|
@ -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<typeof migrations>("../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")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue