Skip to content

Commit b96559b

Browse files
keithwillcodedevin-ai-integration[bot]anikdhabal
authored andcommitted
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>
1 parent 5943a8a commit b96559b

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

apps/api/v2/src/modules/slots/slots-2024-09-04/controllers/e2e/user-event-type-slots.controller.e2e-spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,8 @@ describe("Slots 2024-09-04 Endpoints", () => {
830830
});
831831

832832
it("should do a booking for seated event and slot should show attendees count and bookingUid", async () => {
833+
await selectedSlotRepositoryFixture.deleteAllByUserId(user.id);
834+
833835
const startTime = "2050-09-05T11:00:00.000Z";
834836
const booking = await bookingsRepositoryFixture.create({
835837
uid: `booking-uid-seated-${seatedEventType.id}-${randomString()}`,
@@ -865,7 +867,7 @@ describe("Slots 2024-09-04 Endpoints", () => {
865867
},
866868
});
867869

868-
bookingSeatsRepositoryFixture.create({
870+
await bookingSeatsRepositoryFixture.create({
869871
referenceUid: `seat-${randomString()}`,
870872
data: {},
871873
booking: {
@@ -959,6 +961,8 @@ describe("Slots 2024-09-04 Endpoints", () => {
959961
});
960962

961963
it("should do a booking for seated event and slot should show attendees count and bookingUid and return range format", async () => {
964+
await selectedSlotRepositoryFixture.deleteAllByUserId(user.id);
965+
962966
const startTime = "2050-09-05T11:00:00.000Z";
963967
const booking = await bookingsRepositoryFixture.create({
964968
uid: `booking-uid-seated-range-${seatedEventType.id}-${randomString()}`,
@@ -994,7 +998,7 @@ describe("Slots 2024-09-04 Endpoints", () => {
994998
},
995999
});
9961000

997-
bookingSeatsRepositoryFixture.create({
1001+
await bookingSeatsRepositoryFixture.create({
9981002
referenceUid: `seat-${randomString()}`,
9991003
data: {},
10001004
booking: {
@@ -1324,6 +1328,11 @@ describe("Slots 2024-09-04 Endpoints", () => {
13241328

13251329
describe("variable length", () => {
13261330
let responseReservedVariableSlot: ReserveSlotOutputData_2024_09_04;
1331+
1332+
beforeAll(async () => {
1333+
await selectedSlotRepositoryFixture.deleteAllByUserId(user.id);
1334+
});
1335+
13271336
it("should not be able to reserve a slot for variable length event type with invalid duration", async () => {
13281337
const slotStartTime = "2050-09-05T10:00:00.000Z";
13291338
const reserveResponse = await request(app.getHttpServer())

apps/api/v2/test/fixtures/repository/selected-slot.repository.fixture.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import type { SelectedSlots } from "@calcom/prisma/client";
2+
import { TestingModule } from "@nestjs/testing";
13
import { PrismaReadService } from "@/modules/prisma/prisma-read.service";
24
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
3-
import { TestingModule } from "@nestjs/testing";
4-
5-
import type { SelectedSlots } from "@calcom/prisma/client";
65

76
export class SelectedSlotRepositoryFixture {
87
private prismaReadClient: PrismaReadService["prisma"];
@@ -20,4 +19,8 @@ export class SelectedSlotRepositoryFixture {
2019
async deleteByUId(uid: SelectedSlots["uid"]) {
2120
return this.prismaWriteClient.selectedSlots.deleteMany({ where: { uid } });
2221
}
22+
23+
async deleteAllByUserId(userId: number) {
24+
return this.prismaWriteClient.selectedSlots.deleteMany({ where: { userId } });
25+
}
2326
}

0 commit comments

Comments
 (0)