From b96559b4e8b3b7474af6939a9a35a529aac2fd75 Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Tue, 17 Feb 2026 13:40:56 -0300 Subject: [PATCH] fix: resolve flaky API v2 slots E2E tests - Add await to unawaited bookingSeatsRepositoryFixture.create calls - Clean up leftover selected slots before seated and variable length tests - Add deleteAllByUserId method to SelectedSlotRepositoryFixture The flakiness was caused by reserved slots from earlier tests leaking into subsequent test groups. The availability calculation fetches all unexpired reserved slots by userId (not eventTypeId), so non-seat reserved slots from regular event type tests appeared as busy times when computing slots for seated and variable length event types. Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> --- .../user-event-type-slots.controller.e2e-spec.ts | 13 +++++++++++-- .../repository/selected-slot.repository.fixture.ts | 9 ++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts b/apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts index 3e9d3c99cc..57715e5422 100644 --- a/apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts +++ b/apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts @@ -830,6 +830,8 @@ describe("Slots 2024-09-04 Endpoints", () => { }); it("should do a booking for seated event and slot should show attendees count and bookingUid", async () => { + await selectedSlotRepositoryFixture.deleteAllByUserId(user.id); + const startTime = "2050-09-05T11:00:00.000Z"; const booking = await bookingsRepositoryFixture.create({ uid: `booking-uid-seated-${seatedEventType.id}-${randomString()}`, @@ -865,7 +867,7 @@ describe("Slots 2024-09-04 Endpoints", () => { }, }); - bookingSeatsRepositoryFixture.create({ + await bookingSeatsRepositoryFixture.create({ referenceUid: `seat-${randomString()}`, data: {}, booking: { @@ -959,6 +961,8 @@ describe("Slots 2024-09-04 Endpoints", () => { }); it("should do a booking for seated event and slot should show attendees count and bookingUid and return range format", async () => { + await selectedSlotRepositoryFixture.deleteAllByUserId(user.id); + const startTime = "2050-09-05T11:00:00.000Z"; const booking = await bookingsRepositoryFixture.create({ uid: `booking-uid-seated-range-${seatedEventType.id}-${randomString()}`, @@ -994,7 +998,7 @@ describe("Slots 2024-09-04 Endpoints", () => { }, }); - bookingSeatsRepositoryFixture.create({ + await bookingSeatsRepositoryFixture.create({ referenceUid: `seat-${randomString()}`, data: {}, booking: { @@ -1324,6 +1328,11 @@ describe("Slots 2024-09-04 Endpoints", () => { describe("variable length", () => { let responseReservedVariableSlot: ReserveSlotOutputData_2024_09_04; + + beforeAll(async () => { + await selectedSlotRepositoryFixture.deleteAllByUserId(user.id); + }); + it("should not be able to reserve a slot for variable length event type with invalid duration", async () => { const slotStartTime = "2050-09-05T10:00:00.000Z"; const reserveResponse = await request(app.getHttpServer()) diff --git a/apps/api/v2/test/fixtures/repository/selected-slot.repository.fixture.ts b/apps/api/v2/test/fixtures/repository/selected-slot.repository.fixture.ts index 1ba1ff61d5..cc566c2d14 100644 --- a/apps/api/v2/test/fixtures/repository/selected-slot.repository.fixture.ts +++ b/apps/api/v2/test/fixtures/repository/selected-slot.repository.fixture.ts @@ -1,8 +1,7 @@ +import type { SelectedSlots } from "@calcom/prisma/client"; +import { TestingModule } from "@nestjs/testing"; import { PrismaReadService } from "@/modules/prisma/prisma-read.service"; import { PrismaWriteService } from "@/modules/prisma/prisma-write.service"; -import { TestingModule } from "@nestjs/testing"; - -import type { SelectedSlots } from "@calcom/prisma/client"; export class SelectedSlotRepositoryFixture { private prismaReadClient: PrismaReadService["prisma"]; @@ -20,4 +19,8 @@ export class SelectedSlotRepositoryFixture { async deleteByUId(uid: SelectedSlots["uid"]) { return this.prismaWriteClient.selectedSlots.deleteMany({ where: { uid } }); } + + async deleteAllByUserId(userId: number) { + return this.prismaWriteClient.selectedSlots.deleteMany({ where: { userId } }); + } }