Updating migration integrity test to allow certain properties to change.
This commit is contained in:
parent
f0f8c14216
commit
3c4cf69463
|
@ -2,6 +2,23 @@ import { context } from "@budibase/backend-core"
|
||||||
import * as setup from "../../api/routes/tests/utilities"
|
import * as setup from "../../api/routes/tests/utilities"
|
||||||
import * as migrations from "../migrations"
|
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", () => {
|
describe("migration integrity", () => {
|
||||||
// These test is checking that each migration is "idempotent".
|
// 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
|
// 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()
|
const db = context.getAppDB()
|
||||||
for (const migration of migrations.MIGRATIONS) {
|
for (const migration of migrations.MIGRATIONS) {
|
||||||
await migration.func()
|
await migration.func()
|
||||||
const docs = await db.allDocs({ include_docs: true })
|
const preResp = await db.allDocs({ include_docs: true })
|
||||||
|
|
||||||
await migration.func()
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue