Remove addTenantToGlobalDb from helpers

This commit is contained in:
adrinr 2023-02-03 09:59:57 +00:00
parent 4116d19a2b
commit 74fe4ead31
5 changed files with 22 additions and 35 deletions

View File

@ -1,10 +1,9 @@
jest.mock("nodemailer") jest.mock("nodemailer")
import { TestConfiguration, mocks, } from "../../../../tests" import { TestConfiguration, mocks } from "../../../../tests"
const sendMailMock = mocks.email.mock() const sendMailMock = mocks.email.mock()
import { events, tenancy } from "@budibase/backend-core" import { events, tenancy } from "@budibase/backend-core"
import { structures } from "@budibase/backend-core/tests" import { structures } from "@budibase/backend-core/tests"
const expectSetAuthCookie = (res: any) => { const expectSetAuthCookie = (res: any) => {
expect( expect(
res.get("Set-Cookie").find((c: string) => c.startsWith("budibase:auth")) res.get("Set-Cookie").find((c: string) => c.startsWith("budibase:auth"))

View File

@ -18,7 +18,7 @@ describe("/api/global/tenants", () => {
describe("DELETE /api/system/tenants/:tenantId", () => { describe("DELETE /api/system/tenants/:tenantId", () => {
it("allows deleting the current tenant", async () => { it("allows deleting the current tenant", async () => {
const user = await config.createTenant({ addTenantToGlobalDb: true }) const user = await config.createTenant()
await config.api.tenants.delete(user.tenantId, { await config.api.tenants.delete(user.tenantId, {
headers: config.authHeaders(user), headers: config.authHeaders(user),
@ -26,9 +26,9 @@ describe("/api/global/tenants", () => {
}) })
it("rejects deleting another tenant", async () => { it("rejects deleting another tenant", async () => {
const user1 = await config.createTenant({ addTenantToGlobalDb: true }) const user1 = await config.createTenant()
// create a second user in another tenant // create a second user in another tenant
const user2 = await config.createTenant({ addTenantToGlobalDb: true }) const user2 = await config.createTenant()
const status = 403 const status = 403
const res = await config.api.tenants.delete(user1.tenantId, { const res = await config.api.tenants.delete(user1.tenantId, {
@ -43,7 +43,7 @@ describe("/api/global/tenants", () => {
}) })
it("rejects non-admin", async () => { it("rejects non-admin", async () => {
const user1 = await config.createTenant({ addTenantToGlobalDb: true }) const user1 = await config.createTenant()
// create an internal non-admin user // create an internal non-admin user
const user2 = await tenancy.doInTenant(user1.tenantId, () => { const user2 = await tenancy.doInTenant(user1.tenantId, () => {
return config.createUser() return config.createUser()

View File

@ -17,7 +17,7 @@ describe("tenancy middleware", () => {
}) })
it("should get tenant id from user", async () => { it("should get tenant id from user", async () => {
const user = await config.createTenant({ addTenantToGlobalDb: false }) const user = await config.createTenant()
await config.createSession(user) await config.createSession(user)
const res = await config.api.self.getSelf(user) const res = await config.api.self.getSelf(user)
expect(res.headers[constants.Header.TENANT_ID]).toBe(user.tenantId) 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 () => { it("should get tenant id from path variable", async () => {
const user = await config.createTenant({ addTenantToGlobalDb: false }) const user = await config.createTenant()
const res = await config.request const res = await config.request
.post(`/api/global/auth/${user.tenantId}/login`) .post(`/api/global/auth/${user.tenantId}/login`)
.send({ .send({

View File

@ -264,11 +264,6 @@ export const save = async (
builtUser._rev = response.rev builtUser._rev = response.rev
await eventHelpers.handleSaveEvents(builtUser, dbUser) await eventHelpers.handleSaveEvents(builtUser, dbUser)
if (!env.isTest()) {
// Race conditions (existing in prod already) with multiple tests synchronising the global db
// https://github.com/Budibase/budibase/issues/6134
await addTenant(tenantId, _id, email)
}
await cache.user.invalidateUser(response.id) await cache.user.invalidateUser(response.id)
// let server know to sync user // let server know to sync user

View File

@ -160,18 +160,11 @@ class TestConfiguration {
// TENANCY // TENANCY
createTenant = async ({ createTenant = async (): Promise<User> => {
addTenantToGlobalDb,
}: {
addTenantToGlobalDb: boolean
}): Promise<User> => {
// create user / new tenant // create user / new tenant
const res = await this.api.users.createAdminUser() 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
if (addTenantToGlobalDb) {
await sdk.users.addTenant(res.tenantId, res.userId, res.email) await sdk.users.addTenant(res.tenantId, res.userId, res.email)
}
// return the created user // return the created user
const userRes = await this.api.users.getUser(res.userId, { const userRes = await this.api.users.getUser(res.userId, {