Skip to content

Commit 44aa262

Browse files
authored
fix: flaky integrations tests (calcom#25218)
* Revert "fix: resolve flaky integration tests (calcom#25030)" This reverts commit 4e5d4f6. * update * test * Remove connection pool setup in Prisma index Set the connection pool to undefined, removing conditional pooling logic. * update
1 parent b8530e2 commit 44aa262

11 files changed

Lines changed: 128 additions & 216 deletions

File tree

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ permissions:
55
contents: read
66
env:
77
NODE_OPTIONS: --max-old-space-size=4096
8+
INTEGRATION_TESTS: "true"
89
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
910
CALENDSO_ENCRYPTION_KEY: ${{ secrets.CI_CALENDSO_ENCRYPTION_KEY }}
1011
DAILY_API_KEY: ${{ secrets.CI_DAILY_API_KEY }}

apps/api/v1/lib/utils/isAdmin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ export const isAdminGuard = async (req: NextApiRequest) => {
1919
team: {
2020
isOrganization: true,
2121
organizationSettings: {
22-
is: {
23-
isAdminAPIEnabled: true,
24-
},
22+
isAdminAPIEnabled: true,
2523
},
2624
},
2725
OR: [{ role: MembershipRole.OWNER }, { role: MembershipRole.ADMIN }],

apps/api/v1/test/lib/bookings/[id]/_patch.integration-test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Request, Response } from "express";
22
import type { NextApiRequest, NextApiResponse } from "next";
33
import { createMocks } from "node-mocks-http";
4-
import { describe, it, expect } from "vitest";
4+
import { describe, it, expect, beforeAll } from "vitest";
55

66
import prisma from "@calcom/prisma";
77

@@ -11,6 +11,30 @@ type CustomNextApiRequest = NextApiRequest & Request;
1111
type CustomNextApiResponse = NextApiResponse & Response;
1212

1313
describe("PATCH /api/bookings", () => {
14+
beforeAll(async () => {
15+
const acmeOrg = await prisma.team.findFirst({
16+
where: {
17+
slug: "acme",
18+
isOrganization: true,
19+
},
20+
});
21+
22+
if (acmeOrg) {
23+
await prisma.organizationSettings.upsert({
24+
where: {
25+
organizationId: acmeOrg.id,
26+
},
27+
update: {
28+
isAdminAPIEnabled: true,
29+
},
30+
create: {
31+
organizationId: acmeOrg.id,
32+
orgAutoAcceptEmail: "acme.com",
33+
isAdminAPIEnabled: true,
34+
},
35+
});
36+
}
37+
});
1438
it("Returns 403 when user has no permission to the booking", async () => {
1539
const memberUser = await prisma.user.findFirstOrThrow({ where: { email: "member2-acme@example.com" } });
1640
const proUser = await prisma.user.findFirstOrThrow({ where: { email: "pro@example.com" } });

apps/api/v1/test/lib/bookings/_get.integration-test.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,33 @@ const DefaultPagination = {
1616
skip: 0,
1717
};
1818

19-
describe("GET /api/bookings", () => {
20-
let proUser: Awaited<ReturnType<typeof prisma.user.findFirstOrThrow>>;
21-
let proUserBooking: Awaited<ReturnType<typeof prisma.booking.findFirstOrThrow>>;
22-
19+
describe("GET /api/bookings", async () => {
2320
beforeAll(async () => {
24-
proUser = await prisma.user.findFirstOrThrow({ where: { email: "pro@example.com" } });
25-
proUserBooking = await prisma.booking.findFirstOrThrow({ where: { userId: proUser.id } });
21+
const acmeOrg = await prisma.team.findFirst({
22+
where: {
23+
slug: "acme",
24+
isOrganization: true,
25+
},
26+
});
27+
28+
if (acmeOrg) {
29+
await prisma.organizationSettings.upsert({
30+
where: {
31+
organizationId: acmeOrg.id,
32+
},
33+
update: {
34+
isAdminAPIEnabled: true,
35+
},
36+
create: {
37+
organizationId: acmeOrg.id,
38+
orgAutoAcceptEmail: "acme.com",
39+
isAdminAPIEnabled: true,
40+
},
41+
});
42+
}
2643
});
44+
const proUser = await prisma.user.findFirstOrThrow({ where: { email: "pro@example.com" } });
45+
const proUserBooking = await prisma.booking.findFirstOrThrow({ where: { userId: proUser.id } });
2746

2847
it("Does not return bookings of other users when user has no permission", async () => {
2948
const memberUser = await prisma.user.findFirstOrThrow({ where: { email: "member2-acme@example.com" } });

apps/api/v1/test/lib/utils/isAdmin.integration-test.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Request, Response } from "express";
22
import type { NextApiRequest, NextApiResponse } from "next";
33
import { createMocks } from "node-mocks-http";
4-
import { describe, it, expect } from "vitest";
4+
import { describe, it, expect, beforeAll } from "vitest";
55

66
import prisma from "@calcom/prisma";
77

@@ -12,6 +12,53 @@ type CustomNextApiRequest = NextApiRequest & Request;
1212
type CustomNextApiResponse = NextApiResponse & Response;
1313

1414
describe("isAdmin guard", () => {
15+
beforeAll(async () => {
16+
const acmeOrg = await prisma.team.findFirst({
17+
where: {
18+
slug: "acme",
19+
isOrganization: true,
20+
},
21+
});
22+
23+
if (acmeOrg) {
24+
await prisma.organizationSettings.upsert({
25+
where: {
26+
organizationId: acmeOrg.id,
27+
},
28+
update: {
29+
isAdminAPIEnabled: true,
30+
},
31+
create: {
32+
organizationId: acmeOrg.id,
33+
orgAutoAcceptEmail: "acme.com",
34+
isAdminAPIEnabled: true,
35+
},
36+
});
37+
}
38+
39+
const dunderOrg = await prisma.team.findFirst({
40+
where: {
41+
slug: "dunder-mifflin",
42+
isOrganization: true,
43+
},
44+
});
45+
46+
if (dunderOrg) {
47+
await prisma.organizationSettings.upsert({
48+
where: {
49+
organizationId: dunderOrg.id,
50+
},
51+
update: {
52+
isAdminAPIEnabled: false,
53+
},
54+
create: {
55+
organizationId: dunderOrg.id,
56+
orgAutoAcceptEmail: "dunder-mifflin.com",
57+
isAdminAPIEnabled: false,
58+
},
59+
});
60+
}
61+
});
1562
it("Returns false when user does not exist in the system", async () => {
1663
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
1764
method: "POST",

apps/api/v1/test/lib/utils/retrieveScopedAccessibleUsers.integration-test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect } from "vitest";
1+
import { describe, it, expect, beforeAll } from "vitest";
22

33
import prisma from "@calcom/prisma";
44

@@ -8,6 +8,30 @@ import {
88
} from "../../../lib/utils/retrieveScopedAccessibleUsers";
99

1010
describe("retrieveScopedAccessibleUsers tests", () => {
11+
beforeAll(async () => {
12+
const acmeOrg = await prisma.team.findFirst({
13+
where: {
14+
slug: "acme",
15+
isOrganization: true,
16+
},
17+
});
18+
19+
if (acmeOrg) {
20+
await prisma.organizationSettings.upsert({
21+
where: {
22+
organizationId: acmeOrg.id,
23+
},
24+
update: {
25+
isAdminAPIEnabled: true,
26+
},
27+
create: {
28+
organizationId: acmeOrg.id,
29+
orgAutoAcceptEmail: "acme.com",
30+
isAdminAPIEnabled: true,
31+
},
32+
});
33+
}
34+
});
1135
describe("getAccessibleUsers", () => {
1236
it("Does not return members when only admin user ID is supplied", async () => {
1337
const adminUser = await prisma.user.findFirstOrThrow({ where: { email: "owner1-acme@example.com" } });

packages/prisma/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { excludePendingPaymentsExtension } from "./extensions/exclude-pending-pa
88
import { PrismaClient, type Prisma } from "./generated/prisma/client";
99

1010
const connectionString = process.env.DATABASE_URL || "";
11+
const isIntegrationTest = process.env.INTEGRATION_TESTS === "true";
1112
const pool =
12-
process.env.USE_POOL === "true" || process.env.USE_POOL === "1"
13+
!isIntegrationTest && (process.env.USE_POOL === "true" || process.env.USE_POOL === "1")
1314
? new Pool({
1415
connectionString: connectionString,
1516
max: 5,

tests/integration/global-setup.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)