Skip to content

Scheduling infrastructure for absolutely everyone.

fix: resolve flaky no-show-updated-action integration test (#27772)

Hariom Balhara0ec07b0005b5
diff --git a/packages/features/booking-audit/lib/service/__tests__/no-show-updated-action.integration-test.ts b/packages/features/booking-audit/lib/service/__tests__/no-show-updated-action.integration-test.ts
index 75fc38b8fa5..9d3303225ec 100644
--- a/packages/features/booking-audit/lib/service/__tests__/no-show-updated-action.integration-test.ts
+++ b/packages/features/booking-audit/lib/service/__tests__/no-show-updated-action.integration-test.ts
@@ -1,19 +1,18 @@
-import { describe, expect, it, beforeEach, afterEach } from "vitest";
-
import type { BookingStatus } from "@calcom/prisma/enums";
-import type { BookingAuditTaskConsumer } from "../BookingAuditTaskConsumer";
-import type { BookingAuditViewerService } from "../BookingAuditViewerService";
-import { makeUserActor } from "../../makeActor";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { getBookingAuditTaskConsumer } from "../../../di/BookingAuditTaskConsumer.container";
import { getBookingAuditViewerService } from "../../../di/BookingAuditViewerService.container";
+import { makeUserActor } from "../../makeActor";
+import type { BookingAuditTaskConsumer } from "../BookingAuditTaskConsumer";
+import type { BookingAuditViewerService } from "../BookingAuditViewerService";
import {
- createTestUser,
- createTestOrganization,
- createTestMembership,
- createTestEventType,
+ cleanupTestData,
createTestBooking,
+ createTestEventType,
+ createTestMembership,
+ createTestOrganization,
+ createTestUser,
enableFeatureForOrganization,
- cleanupTestData,
} from "./integration-utils";
describe("No-Show Updated Action Integration", () => {
@@ -25,10 +24,11 @@ describe("No-Show Updated Action Integration", () => {
attendee: { id: number; email: string };
organization: { id: number };
eventType: { id: number };
- booking: { uid: string; startTime: Date; endTime: Date; status: BookingStatus };
- attendeeIds: number[];
+ booking: { id: number; uid: string; startTime: Date; endTime: Date; status: BookingStatus };
};
+ const additionalAttendeeEmails: string[] = [];
+
beforeEach(async () => {
bookingAuditTaskConsumer = getBookingAuditTaskConsumer();
bookingAuditViewerService = getBookingAuditViewerService();
@@ -50,25 +50,18 @@ describe("No-Show Updated Action Integration", () => {
],
});
- // Get the attendee IDs from the booking
- const { prisma } = await import("@calcom/prisma");
- const bookingWithAttendees = await prisma.booking.findUnique({
- where: { uid: booking.uid },
- include: { attendees: true },
- });
-
testData = {
owner: { id: owner.id, uuid: owner.uuid, email: owner.email },
attendee: { id: attendee.id, email: attendee.email },
organization: { id: organization.id },
eventType: { id: eventType.id },
booking: {
+ id: booking.id,
uid: booking.uid,
startTime: booking.startTime,
endTime: booking.endTime,
status: booking.status,
},
- attendeeIds: bookingWithAttendees?.attendees.map((a) => a.id) || [],
};
});
@@ -78,12 +71,16 @@ describe("No-Show Updated Action Integration", () => {
await cleanupTestData({
bookingUid: testData.booking?.uid,
userUuids: testData.owner?.uuid ? [testData.owner.uuid] : [],
- attendeeEmails: testData.attendee?.email ? [testData.attendee.email] : [],
+ attendeeEmails: [
+ ...(testData.attendee?.email ? [testData.attendee.email] : []),
+ ...additionalAttendeeEmails,
+ ],
eventTypeId: testData.eventType?.id,
organizationId: testData.organization?.id,
userIds: [testData.owner?.id, testData.attendee?.id].filter((id): id is number => id !== undefined),
featureSlug: "booking-audit",
});
+ additionalAttendeeEmails.length = 0;
});
describe("when host is marked as no-show", () => {
@@ -133,9 +130,7 @@ describe("No-Show Updated Action Integration", () => {
it("should create audit record with attendeesNoShow array", async () => {
const actor = makeUserActor(testData.owner.uuid);
- const attendeesNoShow = [
- { attendeeEmail: testData.attendee.email, noShow: { old: null, new: true } },
- ];
+ const attendeesNoShow = [{ attendeeEmail: testData.attendee.email, noShow: { old: null, new: true } }];
await bookingAuditTaskConsumer.onBookingAction({
bookingUid: testData.booking.uid,
@@ -179,15 +174,15 @@ describe("No-Show Updated Action Integration", () => {
});
it("should handle multiple attendees marked as no-show", async () => {
- // Create a second attendee for this test
const { prisma } = await import("@calcom/prisma");
const secondAttendeeEmail = `second-attendee-${Date.now()}@example.com`;
- const secondAttendee = await prisma.attendee.create({
+ additionalAttendeeEmails.push(secondAttendeeEmail);
+ await prisma.attendee.create({
data: {
email: secondAttendeeEmail,
name: "Second Attendee",
timeZone: "UTC",
- bookingId: (await prisma.booking.findUnique({ where: { uid: testData.booking.uid } }))!.id,
+ bookingId: testData.booking.id,
},
});
@@ -231,9 +226,6 @@ describe("No-Show Updated Action Integration", () => {
const secondAttendeeData = storedAttendeesNoShow.find((a) => a.attendeeEmail === secondAttendeeEmail);
expect(firstAttendee?.noShow).toEqual({ old: null, new: true });
expect(secondAttendeeData?.noShow).toEqual({ old: false, new: true });
-
- // Cleanup the second attendee
- await prisma.attendee.delete({ where: { id: secondAttendee.id } });
});
});
@@ -252,9 +244,7 @@ describe("No-Show Updated Action Integration", () => {
userUuid: testData.owner.uuid,
noShow: { old: null, new: true },
},
- attendeesNoShow: [
- { attendeeEmail: testData.attendee.email, noShow: { old: null, new: true } },
- ],
+ attendeesNoShow: [{ attendeeEmail: testData.attendee.email, noShow: { old: null, new: true } }],
},
timestamp: Date.now(),
});
@@ -293,9 +283,7 @@ describe("No-Show Updated Action Integration", () => {
const actor = makeUserActor(testData.owner.uuid);
const dataWithArrayFormat = {
- attendeesNoShow: [
- { attendeeEmail: testData.attendee.email, noShow: { old: null, new: true } },
- ],
+ attendeesNoShow: [{ attendeeEmail: testData.attendee.email, noShow: { old: null, new: true } }],
};
await bookingAuditTaskConsumer.onBookingAction({