1
0
Fork 0
mirror of synced 2024-08-04 21:02:01 +12:00

Updating migration integrity test to allow certain properties to change.

This commit is contained in:
mike12345567 2024-06-06 15:14:59 +01:00
parent f0f8c14216
commit 3c4cf69463

View file

@ -2,6 +2,23 @@ import { context } from "@budibase/backend-core"
import * as setup from "../../api/routes/tests/utilities"
import * as migrations from "../migrations"
function removeChangeableKeys(documents: Document[]) {
const changeableKeys = ["createdAt", "updatedAt", "_rev", "rev"]
function iterate(obj: Record<string, any>) {
for (let key of Object.keys(obj)) {
if (typeof obj[key] === "object") {
iterate(obj[key])
} else if (changeableKeys.indexOf(key) !== -1) {
delete obj[key]
}
}
}
for (let doc of documents) {
iterate(doc)
}
return documents
}
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
@ -13,12 +30,18 @@ describe("migration integrity", () => {
const db = context.getAppDB()
for (const migration of migrations.MIGRATIONS) {
await migration.func()
const docs = await db.allDocs({ include_docs: true })
const preResp = await db.allDocs({ include_docs: true })
await migration.func()
const latestDocs = await db.allDocs({ include_docs: true })
const postResp = await db.allDocs({ include_docs: true })
expect(docs).toEqual(latestDocs)
const preDocs = removeChangeableKeys(
preResp.rows.map(row => row.doc as Document)
)
const postDocs = removeChangeableKeys(
postResp.rows.map(row => row.doc as Document)
)
expect(preDocs).toEqual(postDocs)
}
})
})