Skip to content

Commit

Permalink
Added test for validating fixed host behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
emrysal committed Jan 21, 2025
1 parent 0e10874 commit abc4b70
Showing 1 changed file with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ import dayjs from "@calcom/dayjs";

import { getAggregatedAvailability } from ".";

// Helper to check if a time range overlaps with availability
const isAvailable = (availability: { start: Dayjs; end: Dayjs }[], range: { start: Dayjs; end: Dayjs }) => {
return availability.some(({ start, end }) => {
return start <= range.start && end >= range.end;
});
};

describe("getAggregatedAvailability", () => {
// This test shouldn't pass; but highlights the issue.
// rr-host availability used to combine into erroneous slots, this confirms it no longer happens
it("should have no host available between 11:00 and 11:30 on January 23, 2025", () => {
const userAvailability = [
{
Expand All @@ -28,19 +35,50 @@ describe("getAggregatedAvailability", () => {
];

const result = getAggregatedAvailability(userAvailability, "ROUND_ROBIN");
const timeRangeToCheck = {
const timeRangeToCheckBusy = {
start: dayjs("2025-01-23T11:00:00.000Z"),
end: dayjs("2025-01-23T11:30:00.000Z"),
};
// Helper to check if a time range overlaps with availability
const isAvailable = (
availability: { start: Dayjs; end: Dayjs }[],
range: { start: Dayjs; end: Dayjs }
) => {
return availability.some(({ start, end }) => {
return start <= range.start && end >= range.end;
});

expect(isAvailable(result, timeRangeToCheckBusy)).toBe(false);

const timeRangeToCheckAvailable = {
start: dayjs("2025-01-23T11:00:00.000Z"),
end: dayjs("2025-01-23T11:20:00.000Z"),
};

expect(isAvailable(result, timeRangeToCheckAvailable)).toBe(true);
});
// validates fixed host behaviour, they all have to be available
it("should only have all fixed hosts available between 11:15 and 11:20 on January 23, 2025", () => {
const userAvailability = [
{
dateRanges: [],
oooExcludedDateRanges: [
{ start: dayjs("2025-01-23T11:00:00.000Z"), end: dayjs("2025-01-23T11:20:00.000Z") },
{ start: dayjs("2025-01-23T16:10:00.000Z"), end: dayjs("2025-01-23T16:30:00.000Z") },
],
user: { isFixed: true },
},
{
dateRanges: [],
oooExcludedDateRanges: [
{ start: dayjs("2025-01-23T11:15:00.000Z"), end: dayjs("2025-01-23T11:30:00.000Z") },
{ start: dayjs("2025-01-23T13:20:00.000Z"), end: dayjs("2025-01-23T13:30:00.000Z") },
],
user: { isFixed: true },
},
];

const result = getAggregatedAvailability(userAvailability, "ROUND_ROBIN");
const timeRangeToCheckBusy = {
start: dayjs("2025-01-23T11:00:00.000Z"),
end: dayjs("2025-01-23T11:30:00.000Z"),
};
expect(isAvailable(result, timeRangeToCheck)).toBe(false);

expect(isAvailable(result, timeRangeToCheckBusy)).toBe(false);

expect(result[0].start.format()).toEqual(dayjs("2025-01-23T11:15:00.000Z").format());
expect(result[0].end.format()).toEqual(dayjs("2025-01-23T11:20:00.000Z").format());
});
});

0 comments on commit abc4b70

Please sign in to comment.