* wip * wip * wip * Add tests * Update getSchedule.test.ts * Update types.ts * Self review fixes * Update text * PR feedback from Carina * Use utcoffset for range as well * Remove logging from the function that runs on every timeslot * Add one more test * Show x days instead of x+1 days for both ROLLING and ROLLING_WINDOW * refactor tests * Move bookingScenario imports to the top as they import prismock mock that has to be imported very early * More reordering of imports * Fix accidental min update at wrong place * Handle legacy value of zero for periodDays * Range fix * Fix isDateOutOfBound not being checked properly during booking. Also added a test for the case * Fix duplicate element, how the hell it reached there * Use today plus x days for ROLLING periodType * Add disabled for Checkbox as well * Revert logger.ts * Formatting Signed-off-by: zomars <zomars@me.com> * Fix ordering of imports that is causing tests failure --------- Signed-off-by: zomars <zomars@me.com> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
106 lines
2.8 KiB
TypeScript
106 lines
2.8 KiB
TypeScript
import { diff } from "jest-diff";
|
|
import { expect } from "vitest";
|
|
|
|
import type { Slot } from "@calcom/trpc/server/routers/viewer/slots/types";
|
|
|
|
export const expectedSlotsForSchedule = {
|
|
IstWorkHours: {
|
|
interval: {
|
|
"1hr": {
|
|
allPossibleSlotsStartingAt430: [
|
|
"04:30:00.000Z",
|
|
"05:30:00.000Z",
|
|
"06:30:00.000Z",
|
|
"07:30:00.000Z",
|
|
"08:30:00.000Z",
|
|
"09:30:00.000Z",
|
|
"10:30:00.000Z",
|
|
"11:30:00.000Z",
|
|
],
|
|
allPossibleSlotsStartingAt4: [
|
|
"04:00:00.000Z",
|
|
"05:00:00.000Z",
|
|
"06:00:00.000Z",
|
|
"07:00:00.000Z",
|
|
"08:00:00.000Z",
|
|
"09:00:00.000Z",
|
|
"10:00:00.000Z",
|
|
"11:00:00.000Z",
|
|
],
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
declare global {
|
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
namespace jest {
|
|
interface Matchers<R> {
|
|
toHaveTimeSlots(expectedSlots: string[], date: { dateString: string; doExactMatch?: boolean }): R;
|
|
toHaveNoTimeSlots(date: { dateString: string }): R;
|
|
}
|
|
}
|
|
}
|
|
|
|
expect.extend({
|
|
toHaveTimeSlots(
|
|
schedule: { slots: Record<string, Slot[]> },
|
|
expectedSlots: string[],
|
|
{ dateString, doExactMatch }: { dateString: string; doExactMatch: boolean }
|
|
) {
|
|
if (!schedule.slots[`${dateString}`]) {
|
|
return {
|
|
pass: false,
|
|
message: () => `has no timeslots for ${dateString}`,
|
|
};
|
|
}
|
|
|
|
if (
|
|
!schedule.slots[`${dateString}`]
|
|
.map((slot) => slot.time)
|
|
.every((actualSlotTime, index) => {
|
|
return `${dateString}T${expectedSlots[index]}` === actualSlotTime;
|
|
})
|
|
) {
|
|
return {
|
|
pass: false,
|
|
message: () =>
|
|
`has incorrect timeslots for ${dateString}.\n\r ${diff(
|
|
expectedSlots.map((expectedSlot) => `${dateString}T${expectedSlot}`),
|
|
schedule.slots[`${dateString}`].map((slot) => slot.time)
|
|
)}`,
|
|
};
|
|
}
|
|
|
|
if (doExactMatch) {
|
|
return {
|
|
pass: expectedSlots.length === schedule.slots[`${dateString}`].length,
|
|
message: () =>
|
|
`number of slots don't match for ${dateString}. Expected ${expectedSlots.length} but got ${
|
|
schedule.slots[`${dateString}`].length
|
|
}`,
|
|
};
|
|
}
|
|
|
|
return {
|
|
pass: true,
|
|
message: () => "has correct timeslots ",
|
|
};
|
|
},
|
|
|
|
toHaveNoTimeSlots(schedule: { slots: Record<string, Slot[]> }, { dateString }: { dateString: string }) {
|
|
if (!schedule.slots[`${dateString}`] || schedule.slots[`${dateString}`].length === 0) {
|
|
return {
|
|
pass: true,
|
|
message: () => `has no timeslots for ${dateString}`,
|
|
};
|
|
}
|
|
return {
|
|
pass: false,
|
|
message: () => `has timeslots for ${dateString}`,
|
|
};
|
|
},
|
|
});
|
|
|
|
export { expect } from "vitest";
|