Update table migration test to use imports, and update TestConfiguration to work with type parameters
This commit is contained in:
parent
3c3c2325e7
commit
4279d3687e
|
@ -1,8 +1,8 @@
|
||||||
import { App, Screen, ScreenProps } from "@budibase/types"
|
import { App, Screen, ScreenProps } from "@budibase/types"
|
||||||
|
|
||||||
const { db: dbCore } = require("@budibase/backend-core")
|
import { db as dbCore } from "@budibase/backend-core"
|
||||||
const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
import TestConfig from "../../../tests/utilities/TestConfiguration"
|
||||||
const migration = require("../tableSettings")
|
import { run as runMigration } from "../tableSettings"
|
||||||
|
|
||||||
// Local type for allowing any child components inside screens
|
// Local type for allowing any child components inside screens
|
||||||
type MigratingScreenProps = ScreenProps & { _children: any[] }
|
type MigratingScreenProps = ScreenProps & { _children: any[] }
|
||||||
|
@ -35,7 +35,7 @@ describe("run", () => {
|
||||||
|
|
||||||
// Run migration
|
// Run migration
|
||||||
screen = await dbCore.doWithDB(app.appId, async (db: any) => {
|
screen = await dbCore.doWithDB(app.appId, async (db: any) => {
|
||||||
await migration.run(db)
|
await runMigration(db)
|
||||||
return await db.get(screen._id)
|
return await db.get(screen._id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ describe("run", () => {
|
||||||
|
|
||||||
// Run migration
|
// Run migration
|
||||||
screen = await dbCore.doWithDB(app.appId, async (db: any) => {
|
screen = await dbCore.doWithDB(app.appId, async (db: any) => {
|
||||||
await migration.run(db)
|
await runMigration(db)
|
||||||
return await db.get(screen._id)
|
return await db.get(screen._id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ describe("run", () => {
|
||||||
|
|
||||||
// Run migration
|
// Run migration
|
||||||
screen = await dbCore.doWithDB(app.appId, async (db: any) => {
|
screen = await dbCore.doWithDB(app.appId, async (db: any) => {
|
||||||
await migration.run(db)
|
await runMigration(db)
|
||||||
return await db.get(screen._id)
|
return await db.get(screen._id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ describe("run", () => {
|
||||||
|
|
||||||
// Run migration
|
// Run migration
|
||||||
screen = await dbCore.doWithDB(app.appId, async (db: any) => {
|
screen = await dbCore.doWithDB(app.appId, async (db: any) => {
|
||||||
await migration.run(db)
|
await runMigration(db)
|
||||||
return await db.get(screen._id)
|
return await db.get(screen._id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ class TestConfiguration {
|
||||||
}
|
}
|
||||||
return tenancy.doInTenant(TENANT_ID, () => {
|
return tenancy.doInTenant(TENANT_ID, () => {
|
||||||
// check if already in a context
|
// check if already in a context
|
||||||
if (context.getAppId() == null && appId !== null) {
|
if (context.getAppId() == null && appId != null) {
|
||||||
return context.doInAppContext(appId, async () => {
|
return context.doInAppContext(appId, async () => {
|
||||||
return task()
|
return task()
|
||||||
})
|
})
|
||||||
|
@ -196,7 +196,7 @@ class TestConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
async createUser(
|
async createUser(
|
||||||
id = null,
|
id,
|
||||||
firstName = FIRSTNAME,
|
firstName = FIRSTNAME,
|
||||||
lastName = LASTNAME,
|
lastName = LASTNAME,
|
||||||
email = EMAIL,
|
email = EMAIL,
|
||||||
|
@ -366,25 +366,25 @@ class TestConfiguration {
|
||||||
|
|
||||||
// TABLE
|
// TABLE
|
||||||
|
|
||||||
async updateTable(config = null) {
|
async updateTable(config) {
|
||||||
config = config || basicTable()
|
config = config || basicTable()
|
||||||
this.table = await this._req(config, null, controllers.table.save)
|
this.table = await this._req(config, null, controllers.table.save)
|
||||||
return this.table
|
return this.table
|
||||||
}
|
}
|
||||||
|
|
||||||
async createTable(config = null) {
|
async createTable(config) {
|
||||||
if (config != null && config._id) {
|
if (config != null && config._id) {
|
||||||
delete config._id
|
delete config._id
|
||||||
}
|
}
|
||||||
return this.updateTable(config)
|
return this.updateTable(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTable(tableId = null) {
|
async getTable(tableId) {
|
||||||
tableId = tableId || this.table._id
|
tableId = tableId || this.table._id
|
||||||
return this._req(null, { tableId }, controllers.table.find)
|
return this._req(null, { tableId }, controllers.table.find)
|
||||||
}
|
}
|
||||||
|
|
||||||
async createLinkedTable(relationshipType = null, links = ["link"]) {
|
async createLinkedTable(relationshipType, links = ["link"]) {
|
||||||
if (!this.table) {
|
if (!this.table) {
|
||||||
throw "Must have created a table first."
|
throw "Must have created a table first."
|
||||||
}
|
}
|
||||||
|
@ -416,7 +416,7 @@ class TestConfiguration {
|
||||||
|
|
||||||
// ROW
|
// ROW
|
||||||
|
|
||||||
async createRow(config = null) {
|
async createRow(config) {
|
||||||
if (!this.table) {
|
if (!this.table) {
|
||||||
throw "Test requires table to be configured."
|
throw "Test requires table to be configured."
|
||||||
}
|
}
|
||||||
|
@ -438,7 +438,7 @@ class TestConfiguration {
|
||||||
|
|
||||||
// ROLE
|
// ROLE
|
||||||
|
|
||||||
async createRole(config = null) {
|
async createRole(config) {
|
||||||
config = config || basicRole()
|
config = config || basicRole()
|
||||||
return this._req(config, null, controllers.role.save)
|
return this._req(config, null, controllers.role.save)
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ class TestConfiguration {
|
||||||
return this._req(null, null, controllers.automation.fetch)
|
return this._req(null, null, controllers.automation.fetch)
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteAutomation(automation = null) {
|
async deleteAutomation(automation) {
|
||||||
automation = automation || this.automation
|
automation = automation || this.automation
|
||||||
if (!automation) {
|
if (!automation) {
|
||||||
return
|
return
|
||||||
|
@ -497,7 +497,7 @@ class TestConfiguration {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async createWebhook(config = null) {
|
async createWebhook(config) {
|
||||||
if (!this.automation) {
|
if (!this.automation) {
|
||||||
throw "Must create an automation before creating webhook."
|
throw "Must create an automation before creating webhook."
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ class TestConfiguration {
|
||||||
|
|
||||||
// DATASOURCE
|
// DATASOURCE
|
||||||
|
|
||||||
async createDatasource(config = null) {
|
async createDatasource(config) {
|
||||||
config = config || basicDatasource()
|
config = config || basicDatasource()
|
||||||
const response = await this._req(config, null, controllers.datasource.save)
|
const response = await this._req(config, null, controllers.datasource.save)
|
||||||
this.datasource = response.datasource
|
this.datasource = response.datasource
|
||||||
|
@ -574,7 +574,7 @@ class TestConfiguration {
|
||||||
.expect(200)
|
.expect(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
async createQuery(config = null) {
|
async createQuery(config) {
|
||||||
if (!this.datasource && !config) {
|
if (!this.datasource && !config) {
|
||||||
throw "No datasource created for query."
|
throw "No datasource created for query."
|
||||||
}
|
}
|
||||||
|
@ -584,14 +584,14 @@ class TestConfiguration {
|
||||||
|
|
||||||
// SCREEN
|
// SCREEN
|
||||||
|
|
||||||
async createScreen(config = null) {
|
async createScreen(config) {
|
||||||
config = config || basicScreen()
|
config = config || basicScreen()
|
||||||
return this._req(config, null, controllers.screen.save)
|
return this._req(config, null, controllers.screen.save)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LAYOUT
|
// LAYOUT
|
||||||
|
|
||||||
async createLayout(config = null) {
|
async createLayout(config) {
|
||||||
config = config || basicLayout()
|
config = config || basicLayout()
|
||||||
return await this._req(config, null, controllers.layout.save)
|
return await this._req(config, null, controllers.layout.save)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue