From 5d58fc5948c6160184e54cb4d96f4b7bc9946f65 Mon Sep 17 00:00:00 2001 From: adrinr Date: Fri, 3 Feb 2023 11:28:27 +0000 Subject: [PATCH] Dry --- packages/backend-core/src/utils/tests/utils.spec.ts | 2 +- packages/backend-core/tests/utilities/structures/index.ts | 1 + packages/backend-core/tests/utilities/structures/tenants.ts | 5 +++++ packages/server/src/tests/utilities/TestConfiguration.ts | 4 ++-- packages/worker/src/tests/TestConfiguration.ts | 3 +-- packages/worker/src/tests/api/users.ts | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 packages/backend-core/tests/utilities/structures/tenants.ts diff --git a/packages/backend-core/src/utils/tests/utils.spec.ts b/packages/backend-core/src/utils/tests/utils.spec.ts index 2d3d40f9d5..b3e9cda353 100644 --- a/packages/backend-core/src/utils/tests/utils.spec.ts +++ b/packages/backend-core/src/utils/tests/utils.spec.ts @@ -14,7 +14,7 @@ describe("utils", () => { }) it("should call platform logout", async () => { - await doInTenant(`tenant-${newid()}`, async () => { + await doInTenant(structures.tenant.name(), async () => { const ctx = structures.koa.newContext() await utils.platformLogout({ ctx, userId: "test" }) expect(events.auth.logout).toBeCalledTimes(1) diff --git a/packages/backend-core/tests/utilities/structures/index.ts b/packages/backend-core/tests/utilities/structures/index.ts index 0d0f0c507f..039502aaaa 100644 --- a/packages/backend-core/tests/utilities/structures/index.ts +++ b/packages/backend-core/tests/utilities/structures/index.ts @@ -8,3 +8,4 @@ export * as apps from "./apps" export * as koa from "./koa" export * as licenses from "./licenses" export * as plugins from "./plugins" +export * as tenant from "./tenants" diff --git a/packages/backend-core/tests/utilities/structures/tenants.ts b/packages/backend-core/tests/utilities/structures/tenants.ts new file mode 100644 index 0000000000..8d593f176b --- /dev/null +++ b/packages/backend-core/tests/utilities/structures/tenants.ts @@ -0,0 +1,5 @@ +import { newid } from "../../../src/newid" + +export function name() { + return `tenant-${newid()}` +} diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index 40a263fb27..64ce55f504 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -1,4 +1,4 @@ -import { generator, mocks } from "@budibase/backend-core/tests" +import { generator, mocks, structures } from "@budibase/backend-core/tests" // init the licensing mock import * as pro from "@budibase/pro" @@ -149,7 +149,7 @@ class TestConfiguration { async init(appName = newid()) { this.defaultUserValues = this.populateDefaultUserValues() if (context.isMultiTenant()) { - this.tenantId = `tenant-${newid()}` + this.tenantId = structures.tenant.name() } if (!this.started) { diff --git a/packages/worker/src/tests/TestConfiguration.ts b/packages/worker/src/tests/TestConfiguration.ts index 1454fa59aa..b7444293df 100644 --- a/packages/worker/src/tests/TestConfiguration.ts +++ b/packages/worker/src/tests/TestConfiguration.ts @@ -20,7 +20,6 @@ import { auth, constants, env as coreEnv, - utils, DEFAULT_TENANT_ID, } from "@budibase/backend-core" import structures, { TENANT_ID, CSRF_TOKEN } from "./structures" @@ -136,7 +135,7 @@ class TestConfiguration { async beforeAll() { try { - this.#tenantId = `tenant-${utils.newid()}` + this.#tenantId = structures.tenant.name() // Running tests in parallel causes issues creating the globaldb twice. This ensures the db is properly created before starting await retry(async () => await this.createDefaultUser()) diff --git a/packages/worker/src/tests/api/users.ts b/packages/worker/src/tests/api/users.ts index bdf5e15641..e9ccb9331d 100644 --- a/packages/worker/src/tests/api/users.ts +++ b/packages/worker/src/tests/api/users.ts @@ -100,7 +100,7 @@ export class UserAPI extends TestAPI { request = { email: structures.email(), password: generator.string(), - tenantId: `tenant-${structures.uuid()}`, + tenantId: structures.tenant.name(), } } const res = await this.request