2021-07-07 10:43:13 +00:00
|
|
|
import { expect, it } from "@jest/globals";
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
import timezone from "dayjs/plugin/timezone";
|
2021-09-22 19:52:38 +00:00
|
|
|
import utc from "dayjs/plugin/utc";
|
|
|
|
import MockDate from "mockdate";
|
|
|
|
|
|
|
|
import getSlots from "@lib/slots";
|
2021-07-07 10:43:13 +00:00
|
|
|
|
2021-06-24 22:15:18 +00:00
|
|
|
dayjs.extend(utc);
|
|
|
|
dayjs.extend(timezone);
|
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
MockDate.set("2021-06-20T11:59:59Z");
|
2021-06-24 22:15:18 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
it("can fit 24 hourly slots for an empty day", async () => {
|
2021-06-24 22:15:18 +00:00
|
|
|
// 24h in a day.
|
2021-08-19 12:27:01 +00:00
|
|
|
expect(
|
|
|
|
getSlots({
|
|
|
|
inviteeDate: dayjs().add(1, "day"),
|
|
|
|
frequency: 60,
|
2021-10-20 15:42:40 +00:00
|
|
|
workingHours: [{ days: Array.from(Array(7).keys()), startTime: 0, endTime: 1440 }],
|
2021-08-19 12:27:01 +00:00
|
|
|
organizerTimeZone: "Europe/London",
|
|
|
|
})
|
|
|
|
).toHaveLength(24);
|
2021-06-30 01:35:08 +00:00
|
|
|
});
|
|
|
|
|
2021-09-21 09:28:12 +00:00
|
|
|
it.skip("only shows future booking slots on the same day", async () => {
|
2021-06-30 01:35:08 +00:00
|
|
|
// The mock date is 1s to midday, so 12 slots should be open given 0 booking notice.
|
2021-08-19 12:27:01 +00:00
|
|
|
expect(
|
|
|
|
getSlots({
|
|
|
|
inviteeDate: dayjs(),
|
|
|
|
frequency: 60,
|
2021-10-20 15:42:40 +00:00
|
|
|
workingHours: [{ days: Array.from(Array(7).keys()), startTime: 0, endTime: 1440 }],
|
2021-08-19 12:27:01 +00:00
|
|
|
organizerTimeZone: "GMT",
|
|
|
|
})
|
|
|
|
).toHaveLength(12);
|
2021-06-30 01:35:08 +00:00
|
|
|
});
|
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
it("can cut off dates that due to invitee timezone differences fall on the next day", async () => {
|
|
|
|
expect(
|
|
|
|
getSlots({
|
|
|
|
inviteeDate: dayjs().tz("Europe/Amsterdam").startOf("day"), // time translation +01:00
|
|
|
|
frequency: 60,
|
|
|
|
workingHours: [{ days: [0], startTime: 1380, endTime: 1440 }],
|
|
|
|
organizerTimeZone: "Europe/London",
|
|
|
|
})
|
|
|
|
).toHaveLength(0);
|
2021-06-30 01:35:08 +00:00
|
|
|
});
|
|
|
|
|
2021-09-21 09:28:12 +00:00
|
|
|
it.skip("can cut off dates that due to invitee timezone differences fall on the previous day", async () => {
|
2021-08-19 12:27:01 +00:00
|
|
|
expect(
|
|
|
|
getSlots({
|
|
|
|
inviteeDate: dayjs().startOf("day"), // time translation -01:00
|
|
|
|
frequency: 60,
|
|
|
|
workingHours: [{ days: [0], startTime: 0, endTime: 60 }],
|
|
|
|
organizerTimeZone: "Europe/London",
|
|
|
|
})
|
|
|
|
).toHaveLength(0);
|
2021-07-07 10:43:13 +00:00
|
|
|
});
|