2023-03-31 04:35:25 +13:00
|
|
|
import "../core/utilities/mocks"
|
|
|
|
import * as structures from "../core/utilities/structures"
|
2023-02-14 00:57:30 +13:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2023-02-22 06:13:24 +13:00
|
|
|
newTenant() {
|
|
|
|
this.tenantId = structures.tenant.id()
|
|
|
|
}
|
|
|
|
|
2023-02-14 00:57:30 +13:00
|
|
|
// TENANCY
|
|
|
|
|
2023-09-19 22:02:52 +12:00
|
|
|
doInTenant<T>(task: () => Promise<T>) {
|
2023-02-14 00:57:30 +13:00
|
|
|
return context.doInTenant(this.tenantId, () => {
|
|
|
|
return task()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
getTenantId() {
|
|
|
|
try {
|
|
|
|
return context.getTenantId()
|
|
|
|
} catch (e) {
|
|
|
|
return this.tenantId!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DBTestConfiguration
|