1
0
Fork 0
mirror of synced 2024-07-28 17:46:09 +12:00
budibase/packages/backend-core/tests/extra/DBTestConfiguration.ts

37 lines
722 B
TypeScript

import "../core/utilities/mocks"
import * as structures from "../core/utilities/structures"
import * as testEnv from "./testEnv"
import * as context from "../../src/context"
class DBTestConfiguration {
tenantId: string
constructor() {
// db tests need to be multi tenant to prevent conflicts
testEnv.multiTenant()
this.tenantId = structures.tenant.id()
}
newTenant() {
this.tenantId = structures.tenant.id()
}
// TENANCY
doInTenant(task: any) {
return context.doInTenant(this.tenantId, () => {
return task()
})
}
getTenantId() {
try {
return context.getTenantId()
} catch (e) {
return this.tenantId!
}
}
}
export default DBTestConfiguration