fix: make BookingReferenceRepository integration tests use unique identifiers (#26701)

The integration tests were flaky because they used fixed identifiers
(email, username, uid) that could conflict across parallel test runs
or with leftover data from previous runs.

Changes:
- Add unique testRunId using timestamp and random suffix
- Use testRunId in email, username, and booking uid
- Change afterAll cleanup to use deleteMany instead of delete to
  prevent failures when records are already deleted

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Anik Dhabal Babu
2026-01-10 16:20:11 -03:00
committed by GitHub
co-authored by Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent 2b4be9c34e
commit eecf9e1ab9
@@ -5,6 +5,8 @@ import type { Booking, Credential, User } from "@calcom/prisma/client";
import { BookingReferenceRepository } from "./BookingReferenceRepository";
const testRunId = `${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
describe("BookingReferenceRepository Integration Tests", () => {
let testUser: User;
let testCredential: Credential;
@@ -14,8 +16,8 @@ describe("BookingReferenceRepository Integration Tests", () => {
beforeAll(async () => {
testUser = await prisma.user.create({
data: {
email: "bookingreference-test@example.com",
username: "bookingreference-test",
email: `bookingreference-test-${testRunId}@example.com`,
username: `bookingreference-test-${testRunId}`,
},
});
@@ -29,7 +31,7 @@ describe("BookingReferenceRepository Integration Tests", () => {
testBooking = await prisma.booking.create({
data: {
uid: "test-booking-uid-123",
uid: `test-booking-uid-${testRunId}`,
title: "Test Booking",
startTime: new Date(),
endTime: new Date(),
@@ -52,19 +54,25 @@ describe("BookingReferenceRepository Integration Tests", () => {
});
afterAll(async () => {
await prisma.booking.delete({
await prisma.bookingReference.deleteMany({
where: {
bookingId: testBooking.id,
},
});
await prisma.booking.deleteMany({
where: {
id: testBooking.id,
},
});
await prisma.credential.delete({
await prisma.credential.deleteMany({
where: {
id: testCredential.id,
},
});
await prisma.user.delete({
await prisma.user.deleteMany({
where: {
id: testUser.id,
},