Split tests

This commit is contained in:
Adria Navarro 2023-12-11 13:05:30 +01:00
parent 34d3edc2db
commit 9396c2fd6a
2 changed files with 39 additions and 24 deletions

View File

@ -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)
}
})
})
})

View File

@ -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")
})
})
})