Skip to content

Scheduling infrastructure for absolutely everyone.

test: Scenario that replicates the crash in production (#19071)

Hariom Balhara6ca76707dada
diff --git a/apps/web/test/lib/getSchedule.test.ts b/apps/web/test/lib/getSchedule.test.ts
index 69bd8f0db46..10f626fe569 100644
--- a/apps/web/test/lib/getSchedule.test.ts
+++ b/apps/web/test/lib/getSchedule.test.ts
@@ -1753,6 +1753,77 @@ describe("getSchedule", () => {
}
);
});
+
+ test("Edge Case: Same day OOO entries that could accidentally be considered in past shouldn't crash the getSchedule", async () => {
+ // Set a fixed date for testing
+ vi.setSystemTime("2024-05-21T00:00:13Z");
+
+ const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
+ const { dateString: todayDateString } = getDate({ dateIncrement: 0 });
+ const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
+
+ await createBookingScenario({
+ eventTypes: [
+ {
+ id: 1,
+ slotInterval: 45,
+ length: 45,
+ users: [
+ {
+ id: 101,
+ },
+ ],
+ },
+ ],
+ users: [
+ {
+ ...TestData.users.example,
+ id: 101,
+ schedules: [TestData.schedules.IstWorkHours],
+ outOfOffice: {
+ dateRanges: [
+ {
+ start: `${todayDateString}T00:00:00.000Z`,
+ end: `${todayDateString}T23:59:59.999Z`,
+ },
+ ],
+ },
+ },
+ ],
+ });
+
+ const schedule = await getSchedule({
+ input: {
+ eventTypeId: 1,
+ eventTypeSlug: "",
+ startTime: `${plus1DateString}T18:30:00.000Z`,
+ endTime: `${plus2DateString}T18:29:59.999Z`,
+ timeZone: Timezones["+5:30"],
+ isTeamEvent: false,
+ orgSlug: null,
+ },
+ });
+
+ // Verify that we get slots for the requested dates
+ expect(schedule).toHaveTimeSlots(
+ [
+ "04:00:00.000Z",
+ "04:45:00.000Z",
+ "05:30:00.000Z",
+ "06:15:00.000Z",
+ "07:00:00.000Z",
+ "07:45:00.000Z",
+ "08:30:00.000Z",
+ "09:15:00.000Z",
+ "10:00:00.000Z",
+ "10:45:00.000Z",
+ "11:30:00.000Z",
+ ],
+ {
+ dateString: plus2DateString,
+ }
+ );
+ });
});
describe("Team Event", () => {
diff --git a/apps/web/test/utils/bookingScenario/bookingScenario.ts b/apps/web/test/utils/bookingScenario/bookingScenario.ts
index 4aec51d3e51..cbcb836fc8b 100644
--- a/apps/web/test/utils/bookingScenario/bookingScenario.ts
+++ b/apps/web/test/utils/bookingScenario/bookingScenario.ts
@@ -166,6 +166,12 @@ type InputUser = Omit<typeof TestData.users.example, "defaultScheduleId"> & {
weekStart?: string;
profiles?: Prisma.ProfileUncheckedCreateWithoutUserInput[];
completedOnboarding?: boolean;
+ outOfOffice?: {
+ dateRanges: {
+ start: string;
+ end: string;
+ }[];
+ };
};
export type InputEventType = {
@@ -652,14 +658,33 @@ export async function addWorkflowReminders(workflowReminders: InputWorkflowRemin
});
}
-export async function addUsersToDb(
- users: (Prisma.UserCreateInput & { schedules: Prisma.ScheduleCreateInput[]; id?: number })[]
-) {
+export async function addUsersToDb(users: InputUser[]) {
log.silly("TestData: Creating Users", JSON.stringify(users));
await prismock.user.createMany({
data: users,
});
+ // Create OutOfOfficeEntry for users with outOfOffice data
+ for (const user of users) {
+ if (user.outOfOffice) {
+ log.debug("Creating OutOfOfficeEntry for user", user.id);
+ for (const dateRange of user.outOfOffice.dateRanges) {
+ await prismock.outOfOfficeEntry.create({
+ data: {
+ uuid: uuidv4(),
+ start: new Date(dateRange.start),
+ end: new Date(dateRange.end),
+ user: {
+ connect: {
+ id: user.id,
+ },
+ },
+ },
+ });
+ }
+ }
+ }
+
const allUsers = await prismock.user.findMany({
include: {
credentials: true,