fix: improve cleanup for managed event types and fix flaky api v2 e2e test (#26602)

* fix: improve cleanup for managed event types in e2e tests

- Add deleteAllUserEventTypes method to EventTypesRepositoryFixture
- Update afterAll cleanup to delete user event types before deleting users
- This ensures child event types of managed event types are properly cleaned up
- Fixes flaky tests caused by incomplete cleanup between test runs
- Add explicit return types to fixture methods to satisfy lint rules
- Replace @ts-ignore with @ts-expect-error for better type safety

Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>

* fix

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Anik Dhabal Babu
2026-01-09 06:16:59 -03:00
committed by GitHub
co-authored by anik@cal.com Devin AI
parent b78ca7be2a
commit b6c243f1dd
2 changed files with 13 additions and 4 deletions
@@ -67,7 +67,7 @@ describe("Organizations Event Types Endpoints", () => {
beforeAll(async () => {
// Generate unique slug inside beforeAll to ensure uniqueness across test runs
managedEventTypeSlug = `organizations-event-types-managed-${randomString()}`;
managedEventTypeSlug = `organizations-event-types-managed-${Date.now()}-${randomString()}`;
const moduleRef = await withApiAuth(
userEmail,
Test.createTestingModule({
@@ -1381,13 +1381,14 @@ describe("Organizations Event Types Endpoints", () => {
}
afterAll(async () => {
await eventTypesRepositoryFixture.deleteAllUserEventTypes(teammate1.id);
await eventTypesRepositoryFixture.deleteAllUserEventTypes(teammate2.id);
await eventTypesRepositoryFixture.deleteAllTeamEventTypes(team.id);
await eventTypesRepositoryFixture.deleteAllTeamEventTypes(falseTestTeam.id);
await userRepositoryFixture.deleteByEmail(userAdmin.email);
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);
@@ -66,6 +66,14 @@ export class EventTypesRepositoryFixture {
});
}
async deleteAllUserEventTypes(userId: number) {
return this.prismaWriteClient.eventType.deleteMany({
where: {
userId,
},
});
}
async findById(eventTypeId: EventType["id"]) {
return this.prismaReadClient.eventType.findUnique({ where: { id: eventTypeId } });
}