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

- Remove unused attendeeIds field and unnecessary prisma.booking.findUnique from beforeEach
- Store booking.id in testData to avoid re-querying booking in test body
- Track additional attendee emails via additionalAttendeeEmails array for proper afterEach cleanup
- Remove fragile prisma.attendee.delete (throws P2025 on missing record) from test body
- Use deleteMany-based cleanupTestData for second attendee cleanup instead

The test was flaky because:
1. It used prisma.attendee.delete (singular) which throws if record is already gone
2. It re-queried the booking via findUnique mid-test which could fail if cascade-deleted
3. The second attendee email was not tracked in afterEach cleanup

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Hariom BalharaandDevin AI authored and GitHub committed 2026-02-09 05:10:37 +00:00
1 parent e940aac2f1
commit 0ec07b0005
1 file changed
+25 -37
@@ -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,
createTestBooking,
enableFeatureForOrganization,
cleanupTestData,
createTestBooking,
createTestEventType,
createTestMembership,
createTestOrganization,
createTestUser,
enableFeatureForOrganization,
} 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({