Migrated cal.com to apps/web
This commit is contained in:
1 parent
d0e047166e
commit
0bc511a886
617 files changed
+62
No files matched your search
@@ -1,159 +0,0 @@
|
||||
import { expect, it } from "@jest/globals";
|
||||
import dayjs from "dayjs";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import MockDate from "mockdate";
|
||||
|
||||
import { getWorkingHours } from "@lib/availability";
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
MockDate.set("2021-06-20T11:59:59Z");
|
||||
|
||||
it("correctly translates Availability (UTC+0) to UTC workingHours", async () => {
|
||||
expect(
|
||||
getWorkingHours({ timeZone: "GMT" }, [
|
||||
{
|
||||
days: [0],
|
||||
startTime: new Date(Date.UTC(2021, 11, 16, 23)),
|
||||
endTime: new Date(Date.UTC(2021, 11, 16, 23, 59)),
|
||||
},
|
||||
])
|
||||
).toStrictEqual([
|
||||
{
|
||||
days: [0],
|
||||
endTime: 1439,
|
||||
startTime: 1380,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("correctly translates Availability in a positive UTC offset (Pacific/Auckland) to UTC workingHours", async () => {
|
||||
// Take note that (Pacific/Auckland) is UTC+12 on 2021-06-20, NOT +13 like the other half of the year.
|
||||
expect(
|
||||
getWorkingHours({ timeZone: "Pacific/Auckland" }, [
|
||||
{
|
||||
days: [1],
|
||||
startTime: new Date(Date.UTC(2021, 11, 16, 0)),
|
||||
endTime: new Date(Date.UTC(2021, 11, 16, 23, 59)),
|
||||
},
|
||||
])
|
||||
).toStrictEqual([
|
||||
{
|
||||
days: [1],
|
||||
endTime: 719,
|
||||
startTime: 0,
|
||||
},
|
||||
{
|
||||
days: [0],
|
||||
endTime: 1439,
|
||||
startTime: 720, // 0 (midnight) - 12 * 60 (DST)
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("correctly translates Availability in a negative UTC offset (Pacific/Midway) to UTC workingHours", async () => {
|
||||
// Take note that (Pacific/Midway) is UTC-12 on 2021-06-20, NOT +13 like the other half of the year.
|
||||
expect(
|
||||
getWorkingHours({ timeZone: "Pacific/Midway" }, [
|
||||
{
|
||||
days: [1],
|
||||
startTime: new Date(Date.UTC(2021, 11, 16, 0)),
|
||||
endTime: new Date(Date.UTC(2021, 11, 16, 23, 59)),
|
||||
},
|
||||
])
|
||||
).toStrictEqual([
|
||||
{
|
||||
days: [2],
|
||||
endTime: 659,
|
||||
startTime: 0,
|
||||
},
|
||||
{
|
||||
days: [1],
|
||||
endTime: 1439,
|
||||
startTime: 660,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("can do the same with UTC offsets", async () => {
|
||||
// Take note that (Pacific/Midway) is UTC-12 on 2021-06-20, NOT +13 like the other half of the year.
|
||||
expect(
|
||||
getWorkingHours({ utcOffset: dayjs().tz("Pacific/Midway").utcOffset() }, [
|
||||
{
|
||||
days: [1],
|
||||
startTime: new Date(Date.UTC(2021, 11, 16, 0)),
|
||||
endTime: new Date(Date.UTC(2021, 11, 16, 23, 59)),
|
||||
},
|
||||
])
|
||||
).toStrictEqual([
|
||||
{
|
||||
days: [2],
|
||||
endTime: 659,
|
||||
startTime: 0,
|
||||
},
|
||||
{
|
||||
days: [1],
|
||||
endTime: 1439,
|
||||
startTime: 660,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("can also shift UTC into other timeZones", async () => {
|
||||
// UTC+0 time with 23:00 - 23:59 (Sunday) and 00:00 - 16:00 (Monday) when cast into UTC+1 should become 00:00 = 17:00 (Monday)
|
||||
expect(
|
||||
getWorkingHours({ utcOffset: -60 }, [
|
||||
{
|
||||
days: [0],
|
||||
startTime: new Date(Date.UTC(2021, 11, 16, 23)),
|
||||
endTime: new Date(Date.UTC(2021, 11, 16, 23, 59)),
|
||||
},
|
||||
{
|
||||
days: [1],
|
||||
startTime: new Date(Date.UTC(2021, 11, 17, 0)),
|
||||
endTime: new Date(Date.UTC(2021, 11, 17, 16)),
|
||||
},
|
||||
])
|
||||
).toStrictEqual([
|
||||
// TODO: Maybe the desired result is 0-1020 as a single entry, but this requires some post-processing to merge. It may work as is so leaving this as now.
|
||||
{
|
||||
days: [1],
|
||||
endTime: 59,
|
||||
startTime: 0,
|
||||
},
|
||||
{
|
||||
days: [1],
|
||||
endTime: 1020,
|
||||
startTime: 60,
|
||||
},
|
||||
]);
|
||||
// And the other way around; UTC+0 time with 00:00 - 1:00 (Monday) and 21:00 - 24:00 (Sunday) when cast into UTC-1 should become 20:00 = 24:00 (Sunday)
|
||||
expect(
|
||||
getWorkingHours({ utcOffset: 60 }, [
|
||||
{
|
||||
days: [0],
|
||||
startTime: new Date(Date.UTC(2021, 11, 16, 21)),
|
||||
endTime: new Date(Date.UTC(2021, 11, 16, 23, 59)),
|
||||
},
|
||||
{
|
||||
days: [1],
|
||||
startTime: new Date(Date.UTC(2021, 11, 17, 0)),
|
||||
endTime: new Date(Date.UTC(2021, 11, 17, 1)),
|
||||
},
|
||||
])
|
||||
).toStrictEqual([
|
||||
// TODO: Maybe the desired result is 1200-1439 as a single entry, but this requires some post-processing to merge. It may work as is so leaving this as now.
|
||||
{
|
||||
days: [0],
|
||||
endTime: 1379,
|
||||
startTime: 1200,
|
||||
},
|
||||
{
|
||||
days: [0],
|
||||
endTime: 1439,
|
||||
startTime: 1380,
|
||||
},
|
||||
]);
|
||||
});
|
||||
@@ -1,13 +0,0 @@
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
|
||||
import { parseZone } from "@lib/parseZone";
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
const EXPECTED_DATE_STRING = "2021-06-20T11:59:59+02:00";
|
||||
|
||||
it("has the right utcOffset regardless of the local timeZone", async () => {
|
||||
expect(parseZone(EXPECTED_DATE_STRING)?.utcOffset()).toEqual(120);
|
||||
expect(parseZone(EXPECTED_DATE_STRING)?.format()).toEqual(EXPECTED_DATE_STRING);
|
||||
});
|
||||
@@ -1,103 +0,0 @@
|
||||
import { expect, it } from "@jest/globals";
|
||||
import dayjs from "dayjs";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import MockDate from "mockdate";
|
||||
|
||||
import { MINUTES_DAY_END, MINUTES_DAY_START } from "@lib/availability";
|
||||
import getSlots from "@lib/slots";
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
MockDate.set("2021-06-20T11:59:59Z");
|
||||
|
||||
it("can fit 24 hourly slots for an empty day", async () => {
|
||||
// 24h in a day.
|
||||
expect(
|
||||
getSlots({
|
||||
inviteeDate: dayjs.utc().add(1, "day"),
|
||||
frequency: 60,
|
||||
minimumBookingNotice: 0,
|
||||
workingHours: [
|
||||
{
|
||||
days: Array.from(Array(7).keys()),
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: MINUTES_DAY_END,
|
||||
},
|
||||
],
|
||||
})
|
||||
).toHaveLength(24);
|
||||
});
|
||||
|
||||
// TODO: This test is sound; it should pass!
|
||||
it("only shows future booking slots on the same day", async () => {
|
||||
// The mock date is 1s to midday, so 12 slots should be open given 0 booking notice.
|
||||
expect(
|
||||
getSlots({
|
||||
inviteeDate: dayjs.utc(),
|
||||
frequency: 60,
|
||||
minimumBookingNotice: 0,
|
||||
workingHours: [
|
||||
{
|
||||
days: Array.from(Array(7).keys()),
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: MINUTES_DAY_END,
|
||||
},
|
||||
],
|
||||
})
|
||||
).toHaveLength(12);
|
||||
});
|
||||
|
||||
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,
|
||||
minimumBookingNotice: 0,
|
||||
workingHours: [
|
||||
{
|
||||
days: [0],
|
||||
startTime: 23 * 60, // 23h
|
||||
endTime: MINUTES_DAY_END,
|
||||
},
|
||||
],
|
||||
})
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("can cut off dates that due to invitee timezone differences fall on the previous day", async () => {
|
||||
const workingHours = [
|
||||
{
|
||||
days: [0],
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: 1 * 60, // 1h
|
||||
},
|
||||
];
|
||||
expect(
|
||||
getSlots({
|
||||
inviteeDate: dayjs().tz("Atlantic/Cape_Verde").startOf("day"), // time translation -01:00
|
||||
frequency: 60,
|
||||
minimumBookingNotice: 0,
|
||||
workingHours,
|
||||
})
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("adds minimum booking notice correctly", async () => {
|
||||
// 24h in a day.
|
||||
expect(
|
||||
getSlots({
|
||||
inviteeDate: dayjs.utc().add(1, "day").startOf("day"),
|
||||
frequency: 60,
|
||||
minimumBookingNotice: 1500,
|
||||
workingHours: [
|
||||
{
|
||||
days: Array.from(Array(7).keys()),
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: MINUTES_DAY_END,
|
||||
},
|
||||
],
|
||||
})
|
||||
).toHaveLength(11);
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
import { getLuckyUsers } from "../../pages/api/book/event";
|
||||
|
||||
it("can find lucky users", async () => {
|
||||
const users = [
|
||||
{
|
||||
id: 1,
|
||||
username: "test",
|
||||
name: "Test User",
|
||||
credentials: [],
|
||||
timeZone: "GMT",
|
||||
bufferTime: 0,
|
||||
email: "[email protected]",
|
||||
destinationCalendar: null,
|
||||
locale: "en",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
username: "test2",
|
||||
name: "Test 2 User",
|
||||
credentials: [],
|
||||
timeZone: "GMT",
|
||||
bufferTime: 0,
|
||||
email: "[email protected]",
|
||||
destinationCalendar: null,
|
||||
locale: "en",
|
||||
},
|
||||
];
|
||||
expect(
|
||||
getLuckyUsers(users, [
|
||||
{ username: "test", bookingCount: 2 },
|
||||
{ username: "test2", bookingCount: 0 },
|
||||
])
|
||||
).toStrictEqual([users[1]]);
|
||||
});
|
||||
Reference in new issue
Block a user