Skip to content

Scheduling infrastructure for absolutely everyone.

fix: Add beforeAll hooks to ensure organization settings are properly configured in integration tests (#24674)

Anik Dhabal Babue5abe93940be
diff --git a/apps/api/v1/test/lib/bookings/[id]/_patch.integration-test.ts b/apps/api/v1/test/lib/bookings/[id]/_patch.integration-test.ts
index 5554d6411d2..251583cb280 100644
--- a/apps/api/v1/test/lib/bookings/[id]/_patch.integration-test.ts
+++ b/apps/api/v1/test/lib/bookings/[id]/_patch.integration-test.ts
@@ -1,7 +1,7 @@
import type { Request, Response } from "express";
import type { NextApiRequest, NextApiResponse } from "next";
import { createMocks } from "node-mocks-http";
-import { describe, it, expect } from "vitest";
+import { describe, it, expect, beforeAll } from "vitest";
import prisma from "@calcom/prisma";
@@ -11,6 +11,30 @@ type CustomNextApiRequest = NextApiRequest & Request;
type CustomNextApiResponse = NextApiResponse & Response;
describe("PATCH /api/bookings", () => {
+ beforeAll(async () => {
+ const acmeOrg = await prisma.team.findFirst({
+ where: {
+ slug: "acme",
+ isOrganization: true,
+ },
+ });
+
+ if (acmeOrg) {
+ await prisma.organizationSettings.upsert({
+ where: {
+ organizationId: acmeOrg.id,
+ },
+ update: {
+ isAdminAPIEnabled: true,
+ },
+ create: {
+ organizationId: acmeOrg.id,
+ orgAutoAcceptEmail: "acme.com",
+ isAdminAPIEnabled: true,
+ },
+ });
+ }
+ });
it("Returns 403 when user has no permission to the booking", async () => {
const memberUser = await prisma.user.findFirstOrThrow({ where: { email: "[email protected]" } });
const proUser = await prisma.user.findFirstOrThrow({ where: { email: "[email protected]" } });
diff --git a/apps/api/v1/test/lib/bookings/_get.integration-test.ts b/apps/api/v1/test/lib/bookings/_get.integration-test.ts
index a3a0a6c9e7a..c1ec9e7b292 100644
--- a/apps/api/v1/test/lib/bookings/_get.integration-test.ts
+++ b/apps/api/v1/test/lib/bookings/_get.integration-test.ts
@@ -1,7 +1,7 @@
import type { Request, Response } from "express";
import type { NextApiRequest, NextApiResponse } from "next";
import { createMocks } from "node-mocks-http";
-import { describe, expect, it } from "vitest";
+import { describe, expect, it, beforeAll } from "vitest";
import { ZodError } from "zod";
import prisma from "@calcom/prisma";
@@ -17,6 +17,30 @@ const DefaultPagination = {
};
describe("GET /api/bookings", async () => {
+ beforeAll(async () => {
+ const acmeOrg = await prisma.team.findFirst({
+ where: {
+ slug: "acme",
+ isOrganization: true,
+ },
+ });
+
+ if (acmeOrg) {
+ await prisma.organizationSettings.upsert({
+ where: {
+ organizationId: acmeOrg.id,
+ },
+ update: {
+ isAdminAPIEnabled: true,
+ },
+ create: {
+ organizationId: acmeOrg.id,
+ orgAutoAcceptEmail: "acme.com",
+ isAdminAPIEnabled: true,
+ },
+ });
+ }
+ });
const proUser = await prisma.user.findFirstOrThrow({ where: { email: "[email protected]" } });
const proUserBooking = await prisma.booking.findFirstOrThrow({ where: { userId: proUser.id } });
@@ -318,11 +342,6 @@ describe("GET /api/bookings", async () => {
const testUser = await prisma.user.findFirstOrThrow({ where: { email: "[email protected]" } });
- const testUserBooking = await prisma.booking.findFirstOrThrow({
- where: { userId: testUser.id },
- include: { attendees: true },
- });
-
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
method: "GET",
query: {
diff --git a/apps/api/v1/test/lib/utils/isAdmin.integration-test.ts b/apps/api/v1/test/lib/utils/isAdmin.integration-test.ts
index 2136617d23a..f8485605cb3 100644
--- a/apps/api/v1/test/lib/utils/isAdmin.integration-test.ts
+++ b/apps/api/v1/test/lib/utils/isAdmin.integration-test.ts
@@ -1,7 +1,7 @@
import type { Request, Response } from "express";
import type { NextApiRequest, NextApiResponse } from "next";
import { createMocks } from "node-mocks-http";
-import { describe, it, expect } from "vitest";
+import { describe, it, expect, beforeAll } from "vitest";
import prisma from "@calcom/prisma";
@@ -12,6 +12,53 @@ type CustomNextApiRequest = NextApiRequest & Request;
type CustomNextApiResponse = NextApiResponse & Response;
describe("isAdmin guard", () => {
+ beforeAll(async () => {
+ const acmeOrg = await prisma.team.findFirst({
+ where: {
+ slug: "acme",
+ isOrganization: true,
+ },
+ });
+
+ if (acmeOrg) {
+ await prisma.organizationSettings.upsert({
+ where: {
+ organizationId: acmeOrg.id,
+ },
+ update: {
+ isAdminAPIEnabled: true,
+ },
+ create: {
+ organizationId: acmeOrg.id,
+ orgAutoAcceptEmail: "acme.com",
+ isAdminAPIEnabled: true,
+ },
+ });
+ }
+
+ const dunderOrg = await prisma.team.findFirst({
+ where: {
+ slug: "dunder-mifflin",
+ isOrganization: true,
+ },
+ });
+
+ if (dunderOrg) {
+ await prisma.organizationSettings.upsert({
+ where: {
+ organizationId: dunderOrg.id,
+ },
+ update: {
+ isAdminAPIEnabled: false,
+ },
+ create: {
+ organizationId: dunderOrg.id,
+ orgAutoAcceptEmail: "dunder-mifflin.com",
+ isAdminAPIEnabled: false,
+ },
+ });
+ }
+ });
it("Returns false when user does not exist in the system", async () => {
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
method: "POST",
diff --git a/apps/api/v1/test/lib/utils/retrieveScopedAccessibleUsers.integration-test.ts b/apps/api/v1/test/lib/utils/retrieveScopedAccessibleUsers.integration-test.ts
index d670defc721..66f180c4e05 100644
--- a/apps/api/v1/test/lib/utils/retrieveScopedAccessibleUsers.integration-test.ts
+++ b/apps/api/v1/test/lib/utils/retrieveScopedAccessibleUsers.integration-test.ts
@@ -1,4 +1,4 @@
-import { describe, it, expect } from "vitest";
+import { describe, it, expect, beforeAll } from "vitest";
import prisma from "@calcom/prisma";
@@ -8,6 +8,30 @@ import {
} from "../../../lib/utils/retrieveScopedAccessibleUsers";
describe("retrieveScopedAccessibleUsers tests", () => {
+ beforeAll(async () => {
+ const acmeOrg = await prisma.team.findFirst({
+ where: {
+ slug: "acme",
+ isOrganization: true,
+ },
+ });
+
+ if (acmeOrg) {
+ await prisma.organizationSettings.upsert({
+ where: {
+ organizationId: acmeOrg.id,
+ },
+ update: {
+ isAdminAPIEnabled: true,
+ },
+ create: {
+ organizationId: acmeOrg.id,
+ orgAutoAcceptEmail: "acme.com",
+ isAdminAPIEnabled: true,
+ },
+ });
+ }
+ });
describe("getAccessibleUsers", () => {
it("Does not return members when only admin user ID is supplied", async () => {
const adminUser = await prisma.user.findFirstOrThrow({ where: { email: "[email protected]" } });