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

* Add a case that crashes

* Add proper crash test case

---------

Co-authored-by: Hariom Balhara <hariombalhara@gmgmail.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
Hariom Balhara
2025-02-07 11:20:29 +00:00
committed by GitHub
co-authored by Hariom Balhara Alex van Andel
parent e79af63e6c
commit 6ca76707da
2 changed files with 99 additions and 3 deletions
+71
View File
@@ -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", () => {
@@ -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,