Skip to content

Scheduling infrastructure for absolutely everyone.

fix: improve test isolation for managed event type e2e tests (#26283)

Anik Dhabal Babu96dc3b5cc6f1
diff --git a/apps/api/v2/src/modules/organizations/event-types/organizations-member-team-admin-event-types.e2e-spec.ts b/apps/api/v2/src/modules/organizations/event-types/organizations-member-team-admin-event-types.e2e-spec.ts
index ee1c501125e..065578c72c9 100644
--- a/apps/api/v2/src/modules/organizations/event-types/organizations-member-team-admin-event-types.e2e-spec.ts
+++ b/apps/api/v2/src/modules/organizations/event-types/organizations-member-team-admin-event-types.e2e-spec.ts
@@ -63,9 +63,11 @@ describe("Organizations Event Types Endpoints", () => {
let collectiveEventType: TeamEventTypeOutput_2024_06_14;
let managedEventType: TeamEventTypeOutput_2024_06_14;
- const managedEventTypeSlug = `organizations-event-types-managed-${randomString()}`;
+ let managedEventTypeSlug: string;
beforeAll(async () => {
+ // Generate unique slug inside beforeAll to ensure uniqueness across test runs
+ managedEventTypeSlug = `organizations-event-types-managed-${randomString()}`;
const moduleRef = await withApiAuth(
userEmail,
Test.createTestingModule({
@@ -1383,6 +1385,9 @@ describe("Organizations Event Types Endpoints", () => {
await userRepositoryFixture.deleteByEmail(teammate1.email);
await userRepositoryFixture.deleteByEmail(teammate2.email);
await userRepositoryFixture.deleteByEmail(falseTestUser.email);
+ // Explicitly delete all team event types before deleting the team to ensure proper cleanup
+ await eventTypesRepositoryFixture.deleteAllTeamEventTypes(team.id);
+ await eventTypesRepositoryFixture.deleteAllTeamEventTypes(falseTestTeam.id);
await teamsRepositoryFixture.delete(team.id);
await teamsRepositoryFixture.delete(falseTestTeam.id);
await organizationsRepositoryFixture.delete(org.id);
diff --git a/apps/api/v2/test/fixtures/repository/event-types.repository.fixture.ts b/apps/api/v2/test/fixtures/repository/event-types.repository.fixture.ts
index 949696c9619..2779065978e 100644
--- a/apps/api/v2/test/fixtures/repository/event-types.repository.fixture.ts
+++ b/apps/api/v2/test/fixtures/repository/event-types.repository.fixture.ts
@@ -58,6 +58,14 @@ export class EventTypesRepositoryFixture {
return this.prismaWriteClient.eventType.delete({ where: { id: eventTypeId } });
}
+ async deleteAllTeamEventTypes(teamId: number) {
+ return this.prismaWriteClient.eventType.deleteMany({
+ where: {
+ teamId,
+ },
+ });
+ }
+
async findById(eventTypeId: EventType["id"]) {
return this.prismaReadClient.eventType.findUnique({ where: { id: eventTypeId } });
}