fix: flaky integrations tests (#25218)
* Revert "fix: resolve flaky integration tests (#25030)"
This reverts commit 4e5d4f67d5.
* update
* test
* Remove connection pool setup in Prisma index
Set the connection pool to undefined, removing conditional pooling logic.
* update
This commit is contained in:
1 parent
b8530e2d78
commit
44aa26292d
11 files changed
+128
-216
No files matched your search
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* Global setup for integration tests
|
||||
* Runs once before all integration tests to seed org-admin state
|
||||
*/
|
||||
export default async function globalSetup() {
|
||||
const module = await import("../lib/test-team-repository");
|
||||
const TestTeamRepository = module.TestTeamRepository;
|
||||
const teamRepo = await TestTeamRepository.withGlobalPrisma();
|
||||
|
||||
const acmeOrg = await teamRepo.findOrganizationBySlug("acme");
|
||||
|
||||
if (acmeOrg) {
|
||||
await teamRepo.upsertOrganizationSettings({
|
||||
organizationId: acmeOrg.id,
|
||||
isAdminAPIEnabled: true,
|
||||
orgAutoAcceptEmail: "acme.com",
|
||||
});
|
||||
|
||||
await teamRepo.ensureMembership({
|
||||
userEmail: "[email protected]",
|
||||
organizationId: acmeOrg.id,
|
||||
role: "OWNER",
|
||||
accepted: true,
|
||||
});
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const memberEmail = `member${i}[email protected]`;
|
||||
const memberUsername = `member${i}-acme`;
|
||||
const memberName = `Member ${i}`;
|
||||
|
||||
await teamRepo.ensureUser({
|
||||
email: memberEmail,
|
||||
username: memberUsername,
|
||||
name: memberName,
|
||||
});
|
||||
|
||||
await teamRepo.ensureMembership({
|
||||
userEmail: memberEmail,
|
||||
organizationId: acmeOrg.id,
|
||||
role: "MEMBER",
|
||||
accepted: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const dunderOrg = await teamRepo.findOrganizationBySlug("dunder-mifflin");
|
||||
|
||||
if (dunderOrg) {
|
||||
await teamRepo.upsertOrganizationSettings({
|
||||
organizationId: dunderOrg.id,
|
||||
isAdminAPIEnabled: false,
|
||||
orgAutoAcceptEmail: "dunder-mifflin.com",
|
||||
});
|
||||
}
|
||||
|
||||
return async () => {
|
||||
};
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
|
||||
export class TestTeamRepository {
|
||||
constructor(private prismaClient: PrismaClient) {}
|
||||
|
||||
static async withGlobalPrisma() {
|
||||
return new TestTeamRepository((await import("@calcom/prisma")).prisma);
|
||||
}
|
||||
|
||||
async findOrganizationBySlug(slug: string) {
|
||||
return this.prismaClient.team.findFirst({
|
||||
where: {
|
||||
slug,
|
||||
isOrganization: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
name: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async upsertOrganizationSettings({
|
||||
organizationId,
|
||||
isAdminAPIEnabled,
|
||||
orgAutoAcceptEmail,
|
||||
}: {
|
||||
organizationId: number;
|
||||
isAdminAPIEnabled: boolean;
|
||||
orgAutoAcceptEmail?: string;
|
||||
}) {
|
||||
return this.prismaClient.organizationSettings.upsert({
|
||||
where: {
|
||||
organizationId,
|
||||
},
|
||||
update: {
|
||||
isAdminAPIEnabled,
|
||||
},
|
||||
create: {
|
||||
organizationId,
|
||||
orgAutoAcceptEmail: orgAutoAcceptEmail || "",
|
||||
isAdminAPIEnabled,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findUserMembershipsInOrg({
|
||||
userEmail,
|
||||
organizationId,
|
||||
}: {
|
||||
userEmail: string;
|
||||
organizationId: number;
|
||||
}) {
|
||||
return this.prismaClient.membership.findMany({
|
||||
where: {
|
||||
user: {
|
||||
email: userEmail,
|
||||
},
|
||||
teamId: organizationId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
role: true,
|
||||
accepted: true,
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async ensureUser({
|
||||
email,
|
||||
username,
|
||||
name,
|
||||
}: {
|
||||
email: string;
|
||||
username: string;
|
||||
name: string;
|
||||
}) {
|
||||
return this.prismaClient.user.upsert({
|
||||
where: { email },
|
||||
update: {
|
||||
name,
|
||||
},
|
||||
create: {
|
||||
email,
|
||||
username,
|
||||
name,
|
||||
emailVerified: new Date(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async ensureMembership({
|
||||
userEmail,
|
||||
organizationId,
|
||||
role,
|
||||
accepted,
|
||||
}: {
|
||||
userEmail: string;
|
||||
organizationId: number;
|
||||
role: "OWNER" | "ADMIN" | "MEMBER";
|
||||
accepted: boolean;
|
||||
}) {
|
||||
const user = await this.prismaClient.user.findFirst({
|
||||
where: { email: userEmail },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new Error(`User with email ${userEmail} not found`);
|
||||
}
|
||||
|
||||
const existingMembership = await this.prismaClient.membership.findFirst({
|
||||
where: {
|
||||
userId: user.id,
|
||||
teamId: organizationId,
|
||||
},
|
||||
});
|
||||
|
||||
if (existingMembership) {
|
||||
return this.prismaClient.membership.update({
|
||||
where: { id: existingMembership.id },
|
||||
data: {
|
||||
role,
|
||||
accepted,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return this.prismaClient.membership.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
teamId: organizationId,
|
||||
role,
|
||||
accepted,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user