diff --git a/packages/backend-core/src/cache/tests/writethrough.spec.js b/packages/backend-core/src/cache/tests/writethrough.spec.js index f3f8df41a3..fefca30c18 100644 --- a/packages/backend-core/src/cache/tests/writethrough.spec.js +++ b/packages/backend-core/src/cache/tests/writethrough.spec.js @@ -2,16 +2,16 @@ require("../../../tests") const { Writethrough } = require("../writethrough") const { getDB } = require("../../db") const tk = require("timekeeper") +const { structures } = require("../../../tests") const START_DATE = Date.now() tk.freeze(START_DATE) -const { newid } = require("../../newid") const DELAY = 5000 -const db = getDB(`db_${newid()}`) -const db2 = getDB(`db_${newid()}`) +const db = getDB(structures.db.id()) +const db2 = getDB(structures.db.id()) const writethrough = new Writethrough(db, DELAY), writethrough2 = new Writethrough(db2, DELAY) describe("writethrough", () => { diff --git a/packages/backend-core/src/db/tests/index.spec.js b/packages/backend-core/src/db/tests/index.spec.js index 56041ea732..0d257f7ed7 100644 --- a/packages/backend-core/src/db/tests/index.spec.js +++ b/packages/backend-core/src/db/tests/index.spec.js @@ -1,19 +1,19 @@ require("../../../tests") -const { newid } = require("../../newid") +const { structures } = require("../../../tests") const { getDB } = require("../db") describe("db", () => { describe("getDB", () => { it("returns a db", async () => { - const dbName = `db_${newid()}` + const dbName = structures.db.id() const db = getDB(dbName) expect(db).toBeDefined() expect(db.name).toBe(dbName) }) it("uses the custom put function", async () => { - const db = getDB(`db_${newid()}`) + const db = getDB(structures.db.id()) let doc = { _id: "test" } await db.put(doc) doc = await db.get(doc._id) diff --git a/packages/backend-core/src/middleware/logging.ts b/packages/backend-core/src/middleware/logging.ts index 35a9b6c4a6..d1f2d6566b 100644 --- a/packages/backend-core/src/middleware/logging.ts +++ b/packages/backend-core/src/middleware/logging.ts @@ -64,7 +64,7 @@ const print = (fn: any, data: any[]) => { message = message + ` [identityId=${identityId}]` } - // fn(message, data) + fn(message, data) } const logging = (ctx: any, next: any) => { diff --git a/packages/backend-core/src/middleware/passport/tests/third-party-common.seq.spec.js b/packages/backend-core/src/middleware/passport/tests/third-party-common.seq.spec.js index 474d234ee1..d377d602f1 100644 --- a/packages/backend-core/src/middleware/passport/tests/third-party-common.seq.spec.js +++ b/packages/backend-core/src/middleware/passport/tests/third-party-common.seq.spec.js @@ -6,8 +6,6 @@ const { DEFAULT_TENANT_ID } = require("../../../constants") const { generateGlobalUserID } = require("../../../db/utils") const { newid } = require("../../../utils") const { doWithGlobalDB, doInTenant } = require("../../../tenancy") -const { default: environment } = require("../../../environment") -environment._set("MULTI_TENANCY", 'TRUE') const done = jest.fn() diff --git a/packages/backend-core/src/migrations/tests/index.spec.js b/packages/backend-core/src/migrations/tests/index.spec.js index 3efb10fbf3..c1915510c3 100644 --- a/packages/backend-core/src/migrations/tests/index.spec.js +++ b/packages/backend-core/src/migrations/tests/index.spec.js @@ -2,9 +2,8 @@ require("../../../tests") const { runMigrations, getMigrationsDoc } = require("../index") const { getGlobalDBName, getDB } = require("../../db") -const { default: environment } = require("../../environment") -const { newid } = require("../../newid") -environment._set("MULTI_TENANCY", 'TRUE') +const { structures, testEnv } = require("../../../tests") +testEnv.multiTenant() let db @@ -21,7 +20,7 @@ describe("migrations", () => { let tenantId beforeEach(() => { - tenantId = `tenant_${newid()}` + tenantId = structures.tenant.id() db = getDB(getGlobalDBName(tenantId)) }) diff --git a/packages/backend-core/src/utils/tests/utils.spec.ts b/packages/backend-core/src/utils/tests/utils.spec.ts index 64594302f2..b3cd527fb3 100644 --- a/packages/backend-core/src/utils/tests/utils.spec.ts +++ b/packages/backend-core/src/utils/tests/utils.spec.ts @@ -4,15 +4,10 @@ import * as events from "../../events" import * as db from "../../db" import { Header } from "../../constants" import { doInTenant } from "../../context" -import environment from "../../environment" import { newid } from "../../utils" describe("utils", () => { describe("platformLogout", () => { - beforeEach(() => { - environment._set("MULTI_TENANCY", "TRUE") - }) - it("should call platform logout", async () => { await doInTenant(structures.tenant.id(), async () => { const ctx = structures.koa.newContext() @@ -23,10 +18,6 @@ describe("utils", () => { }) describe("getAppIdFromCtx", () => { - beforeEach(() => { - environment._set("MULTI_TENANCY", undefined) - }) - it("gets appId from header", async () => { const ctx = structures.koa.newContext() const expected = db.generateAppID() diff --git a/packages/backend-core/tests/utilities/structures/db.ts b/packages/backend-core/tests/utilities/structures/db.ts new file mode 100644 index 0000000000..e25b707cb9 --- /dev/null +++ b/packages/backend-core/tests/utilities/structures/db.ts @@ -0,0 +1,5 @@ +import { newid } from "../../../src/newid" + +export function id() { + return `db_${newid()}` +} diff --git a/packages/backend-core/tests/utilities/structures/index.ts b/packages/backend-core/tests/utilities/structures/index.ts index 039502aaaa..e74751e479 100644 --- a/packages/backend-core/tests/utilities/structures/index.ts +++ b/packages/backend-core/tests/utilities/structures/index.ts @@ -9,3 +9,4 @@ export * as koa from "./koa" export * as licenses from "./licenses" export * as plugins from "./plugins" export * as tenant from "./tenants" +export * as db from "./db" diff --git a/packages/server/src/api/routes/tests/webhook.spec.js b/packages/server/src/api/routes/tests/webhook.spec.js index 988d0e3748..55368fb8ab 100644 --- a/packages/server/src/api/routes/tests/webhook.spec.js +++ b/packages/server/src/api/routes/tests/webhook.spec.js @@ -47,6 +47,8 @@ describe("/webhooks", () => { }) describe("fetch", () => { + beforeAll(setupTest) + it("returns the correct routing for basic user", async () => { const res = await request .get(`/api/webhooks`) @@ -67,6 +69,8 @@ describe("/webhooks", () => { }) describe("delete", () => { + beforeAll(setupTest) + it("should successfully delete", async () => { const res = await request .delete(`/api/webhooks/${webhook._id}/${webhook._rev}`)