Skip to content

Scheduling infrastructure for absolutely everyone.

fix: resolve flaky API v2 slots E2E tests

Keith Williamsb96559b4e8b3
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 3e9d3c99cc0..57715e54227 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 1ba1ff61d5b..cc566c2d14d 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 } });
+ }
}