Fix tenancy issues
This commit is contained in:
parent
e074030a0f
commit
55de45e86b
|
@ -18,7 +18,7 @@ describe("/api/global/tenants", () => {
|
|||
|
||||
describe("DELETE /api/system/tenants/:tenantId", () => {
|
||||
it("allows deleting the current tenant", async () => {
|
||||
const user = await config.createTenant()
|
||||
const user = await config.createTenant({ addTenantToGlobalDb: true })
|
||||
|
||||
await config.api.tenants.delete(user.tenantId, {
|
||||
headers: config.authHeaders(user),
|
||||
|
@ -26,9 +26,9 @@ describe("/api/global/tenants", () => {
|
|||
})
|
||||
|
||||
it("rejects deleting another tenant", async () => {
|
||||
const user1 = await config.createTenant()
|
||||
const user1 = await config.createTenant({ addTenantToGlobalDb: true })
|
||||
// create a second user in another tenant
|
||||
const user2 = await config.createTenant()
|
||||
const user2 = await config.createTenant({ addTenantToGlobalDb: true })
|
||||
|
||||
const status = 403
|
||||
const res = await config.api.tenants.delete(user1.tenantId, {
|
||||
|
@ -43,7 +43,7 @@ describe("/api/global/tenants", () => {
|
|||
})
|
||||
|
||||
it("rejects non-admin", async () => {
|
||||
const user1 = await config.createTenant()
|
||||
const user1 = await config.createTenant({ addTenantToGlobalDb: true })
|
||||
// create an internal non-admin user
|
||||
const user2 = await tenancy.doInTenant(user1.tenantId, () => {
|
||||
return config.createUser()
|
||||
|
|
|
@ -17,7 +17,7 @@ describe("tenancy middleware", () => {
|
|||
})
|
||||
|
||||
it("should get tenant id from user", async () => {
|
||||
const user = await config.createTenant()
|
||||
const user = await config.createTenant({ addTenantToGlobalDb: false })
|
||||
await config.createSession(user)
|
||||
const res = await config.api.self.getSelf(user)
|
||||
expect(res.headers[constants.Header.TENANT_ID]).toBe(user.tenantId)
|
||||
|
@ -54,7 +54,7 @@ describe("tenancy middleware", () => {
|
|||
})
|
||||
|
||||
it("should get tenant id from path variable", async () => {
|
||||
const user = await config.createTenant()
|
||||
const user = await config.createTenant({ addTenantToGlobalDb: false })
|
||||
const res = await config.request
|
||||
.post(`/api/global/auth/${user.tenantId}/login`)
|
||||
.send({
|
||||
|
|
|
@ -136,12 +136,18 @@ class TestConfiguration {
|
|||
|
||||
// TENANCY
|
||||
|
||||
createTenant = async (): Promise<User> => {
|
||||
createTenant = async ({
|
||||
addTenantToGlobalDb,
|
||||
}: {
|
||||
addTenantToGlobalDb: boolean
|
||||
}): Promise<User> => {
|
||||
// create user / new tenant
|
||||
const res = await this.api.users.createAdminUser()
|
||||
|
||||
// This needs to be added because it was disabled for bulk testing: // https://github.com/Budibase/budibase/issues/6134
|
||||
await sdk.users.addTenant(res.tenantId, res.userId, res.email)
|
||||
if (addTenantToGlobalDb) {
|
||||
await sdk.users.addTenant(res.tenantId, res.userId, res.email)
|
||||
}
|
||||
|
||||
// return the created user
|
||||
const userRes = await this.api.users.getUser(res.userId, {
|
||||
|
|
Loading…
Reference in New Issue