From 4116d19a2b93aca2673b5b4e9976521099c6909f Mon Sep 17 00:00:00 2001 From: adrinr Date: Fri, 3 Feb 2023 09:54:25 +0000 Subject: [PATCH] Clean tests --- .../src/api/routes/global/tests/auth.spec.ts | 36 ++++++++++--------- .../src/api/routes/global/tests/email.spec.ts | 2 +- .../src/api/routes/global/tests/users.spec.ts | 4 +-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/packages/worker/src/api/routes/global/tests/auth.spec.ts b/packages/worker/src/api/routes/global/tests/auth.spec.ts index d58d56ac87..4e1302f951 100644 --- a/packages/worker/src/api/routes/global/tests/auth.spec.ts +++ b/packages/worker/src/api/routes/global/tests/auth.spec.ts @@ -1,7 +1,9 @@ jest.mock("nodemailer") -import { TestConfiguration, mocks } from "../../../../tests" +import { TestConfiguration, mocks, } from "../../../../tests" const sendMailMock = mocks.email.mock() -import { events, tenancy, utils } from "@budibase/backend-core" +import { events, tenancy } from "@budibase/backend-core" +import { structures } from "@budibase/backend-core/tests" + const expectSetAuthCookie = (res: any) => { expect( @@ -26,7 +28,7 @@ describe("/api/global/auth", () => { describe("password", () => { describe("POST /api/global/auth/:tenantId/login", () => { - it("should login", () => {}) + it("should login", () => { }) }) describe("POST /api/global/auth/logout", () => { @@ -41,7 +43,7 @@ describe("/api/global/auth", () => { describe("POST /api/global/auth/:tenantId/reset", () => { it("should generate password reset email", async () => { await tenancy.doInTenant(config.tenant1User!.tenantId, async () => { - const userEmail = `${utils.newid()}@test.com` + const userEmail = structures.email() const { res, code } = await config.api.auth.requestPasswordReset( sendMailMock, userEmail @@ -63,7 +65,7 @@ describe("/api/global/auth", () => { describe("POST /api/global/auth/:tenantId/reset/update", () => { it("should reset password", async () => { await tenancy.doInTenant(config.tenant1User!.tenantId, async () => { - const userEmail = `${utils.newid()}@test.com` + const userEmail = structures.email() const { code } = await config.api.auth.requestPasswordReset( sendMailMock, userEmail @@ -83,35 +85,35 @@ describe("/api/global/auth", () => { }) describe("init", () => { - describe("POST /api/global/auth/init", () => {}) + describe("POST /api/global/auth/init", () => { }) - describe("GET /api/global/auth/init", () => {}) + describe("GET /api/global/auth/init", () => { }) }) describe("datasource", () => { // MULTI TENANT - describe("GET /api/global/auth/:tenantId/datasource/:provider", () => {}) + describe("GET /api/global/auth/:tenantId/datasource/:provider", () => { }) - describe("GET /api/global/auth/:tenantId/datasource/:provider/callback", () => {}) + describe("GET /api/global/auth/:tenantId/datasource/:provider/callback", () => { }) // SINGLE TENANT - describe("GET /api/global/auth/datasource/:provider/callback", () => {}) + describe("GET /api/global/auth/datasource/:provider/callback", () => { }) }) describe("google", () => { // MULTI TENANT - describe("GET /api/global/auth/:tenantId/google", () => {}) + describe("GET /api/global/auth/:tenantId/google", () => { }) - describe("GET /api/global/auth/:tenantId/google/callback", () => {}) + describe("GET /api/global/auth/:tenantId/google/callback", () => { }) // SINGLE TENANT - describe("GET /api/global/auth/google/callback", () => {}) + describe("GET /api/global/auth/google/callback", () => { }) - describe("GET /api/admin/auth/google/callback", () => {}) + describe("GET /api/admin/auth/google/callback", () => { }) }) describe("oidc", () => { @@ -176,10 +178,10 @@ describe("/api/global/auth", () => { // SINGLE TENANT - describe("GET /api/global/auth/oidc/callback", () => {}) + describe("GET /api/global/auth/oidc/callback", () => { }) - describe("GET /api/global/auth/oidc/callback", () => {}) + describe("GET /api/global/auth/oidc/callback", () => { }) - describe("GET /api/admin/auth/oidc/callback", () => {}) + describe("GET /api/admin/auth/oidc/callback", () => { }) }) }) diff --git a/packages/worker/src/api/routes/global/tests/email.spec.ts b/packages/worker/src/api/routes/global/tests/email.spec.ts index d71af18577..9e65cda3c5 100644 --- a/packages/worker/src/api/routes/global/tests/email.spec.ts +++ b/packages/worker/src/api/routes/global/tests/email.spec.ts @@ -6,7 +6,7 @@ import { EmailTemplatePurpose } from "../../../../constants" describe("/api/global/email", () => { const config = new TestConfiguration() - beforeEach(async () => { + beforeAll(async () => { await config.beforeAll() }) diff --git a/packages/worker/src/api/routes/global/tests/users.spec.ts b/packages/worker/src/api/routes/global/tests/users.spec.ts index 7ebc8d9e71..a8b07ec815 100644 --- a/packages/worker/src/api/routes/global/tests/users.spec.ts +++ b/packages/worker/src/api/routes/global/tests/users.spec.ts @@ -3,7 +3,7 @@ import { InviteUsersResponse, User } from "@budibase/types" jest.mock("nodemailer") import { TestConfiguration, mocks, structures } from "../../../../tests" const sendMailMock = mocks.email.mock() -import { context, events, tenancy, utils } from "@budibase/backend-core" +import { context, events, tenancy } from "@budibase/backend-core" describe("/api/global/users", () => { const config = new TestConfiguration() @@ -443,7 +443,7 @@ describe("/api/global/users", () => { }) it("should not be able to update email address", async () => { - const email = `${utils.newid()}@test.com` + const email = structures.email() const user = await config.createUser(structures.users.user({ email })) user.email = "new@test.com"