adds test for aggregated availability

pull/12169/head
david-m-l21s 2023-10-31 14:46:38 +01:00
parent e9d86fd03c
commit 1dfba22b14
1 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,59 @@
import { expect, describe, it } from "vitest";
import { getAggregatedAvailability } from "@calcom/core/getAggregatedAvailability";
import dayjs from "@calcom/dayjs";
import { buildDateRanges } from "@calcom/lib/date-ranges";
describe("aggregated availability for round robin with multiple hosts", () => {
it("should return a valid dateRange since both users share the same availability", () => {
const testAvailability = buildDateRanges({
availability: [
{
date: new Date(Date.UTC(2023, 5, 13)),
startTime: new Date(Date.UTC(0, 0, 0, 22, 0)),
endTime: new Date(Date.UTC(0, 0, 0, 23, 0)),
},
],
timeZone: "America/New_York",
dateFrom: dayjs("2023-06-13T00:00:00Z"),
dateTo: dayjs("2023-06-15T00:00:00Z"),
});
const results = getAggregatedAvailability(
[
{ dateRanges: testAvailability, user: { isFixed: false } },
{ dateRanges: testAvailability, user: { isFixed: false } },
],
null,
2
);
expect(results.length).toBe(1);
});
it("should not return a dateRange since there are not enough users available", () => {
const testAvailability = buildDateRanges({
availability: [
{
date: new Date(Date.UTC(2023, 5, 13)),
startTime: new Date(Date.UTC(0, 0, 0, 22, 0)),
endTime: new Date(Date.UTC(0, 0, 0, 23, 0)),
},
],
timeZone: "America/New_York",
dateFrom: dayjs("2023-06-13T00:00:00Z"),
dateTo: dayjs("2023-06-15T00:00:00Z"),
});
const results = getAggregatedAvailability(
[
{ dateRanges: testAvailability, user: { isFixed: false } },
{ dateRanges: testAvailability, user: { isFixed: false } },
],
null,
3
);
expect(results.length).toBe(0);
});
});