chore: Enable prettier on vitest files without causing test failures (#11190)
This commit is contained in:
parent
3a05ae6f74
commit
2591ad12df
|
@ -7,7 +7,6 @@ public
|
||||||
|
|
||||||
*.lock
|
*.lock
|
||||||
*.log
|
*.log
|
||||||
*.test.ts
|
|
||||||
|
|
||||||
.gitignore
|
.gitignore
|
||||||
.npmignore
|
.npmignore
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
public/embed
|
public/embed
|
||||||
*.test.ts
|
|
|
@ -11,18 +11,17 @@ it("correctly handles 1 day", async () => {
|
||||||
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
||||||
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
||||||
date: null,
|
date: null,
|
||||||
scheduleId: 1
|
scheduleId: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = availabilityAsString(availability, {
|
const result = availabilityAsString(availability, {
|
||||||
locale: 'en',
|
locale: "en",
|
||||||
hour12: true
|
hour12: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(replaceUnicodeSpace(result)).toBe("Mon, 9:00 AM - 5:00 PM");
|
expect(replaceUnicodeSpace(result)).toBe("Mon, 9:00 AM - 5:00 PM");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("correctly handles all days", async () => {
|
it("correctly handles all days", async () => {
|
||||||
const availability = {
|
const availability = {
|
||||||
id: 1,
|
id: 1,
|
||||||
|
@ -32,12 +31,12 @@ it("correctly handles all days", async () => {
|
||||||
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
||||||
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
||||||
date: null,
|
date: null,
|
||||||
scheduleId: 1
|
scheduleId: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = availabilityAsString(availability, {
|
const result = availabilityAsString(availability, {
|
||||||
locale: 'en',
|
locale: "en",
|
||||||
hour12: true
|
hour12: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(replaceUnicodeSpace(result)).toBe("Mon - Sun, 9:00 AM - 5:00 PM");
|
expect(replaceUnicodeSpace(result)).toBe("Mon - Sun, 9:00 AM - 5:00 PM");
|
||||||
|
@ -52,12 +51,12 @@ it("correctly handles staggered days", async () => {
|
||||||
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
||||||
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
||||||
date: null,
|
date: null,
|
||||||
scheduleId: 1
|
scheduleId: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = availabilityAsString(availability, {
|
const result = availabilityAsString(availability, {
|
||||||
locale: 'en',
|
locale: "en",
|
||||||
hour12: true
|
hour12: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(replaceUnicodeSpace(result)).toBe("Mon, Wed, Fri, Sun, 9:00 AM - 5:00 PM");
|
expect(replaceUnicodeSpace(result)).toBe("Mon, Wed, Fri, Sun, 9:00 AM - 5:00 PM");
|
||||||
|
@ -72,12 +71,12 @@ it("correctly produces days and times - 12 hours", async () => {
|
||||||
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
||||||
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
||||||
date: null,
|
date: null,
|
||||||
scheduleId: 1
|
scheduleId: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = availabilityAsString(availability, {
|
const result = availabilityAsString(availability, {
|
||||||
locale: 'en',
|
locale: "en",
|
||||||
hour12: true
|
hour12: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(replaceUnicodeSpace(result)).toBe("Mon - Wed, 9:00 AM - 5:00 PM");
|
expect(replaceUnicodeSpace(result)).toBe("Mon - Wed, 9:00 AM - 5:00 PM");
|
||||||
|
@ -92,12 +91,12 @@ it("correctly produces days and times - 24 hours", async () => {
|
||||||
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)),
|
||||||
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)),
|
||||||
date: null,
|
date: null,
|
||||||
scheduleId: 1
|
scheduleId: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = availabilityAsString(availability, {
|
const result = availabilityAsString(availability, {
|
||||||
locale: 'en',
|
locale: "en",
|
||||||
hour12: false
|
hour12: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(replaceUnicodeSpace(result)).toBe("Mon - Wed, 09:00 - 17:00");
|
expect(replaceUnicodeSpace(result)).toBe("Mon - Wed, 09:00 - 17:00");
|
||||||
|
@ -107,5 +106,5 @@ it("correctly produces days and times - 24 hours", async () => {
|
||||||
// produces Unicode characters. Instead of using line for line code from the
|
// produces Unicode characters. Instead of using line for line code from the
|
||||||
// availability.ts file, opted for this instead.
|
// availability.ts file, opted for this instead.
|
||||||
const replaceUnicodeSpace = (string: string) => {
|
const replaceUnicodeSpace = (string: string) => {
|
||||||
return string.replace(/\u202f/g, ' ');
|
return string.replace(/\u202f/g, " ");
|
||||||
}
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
||||||
|
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { validateIntervalLimitOrder } from "@calcom/lib";
|
import { validateIntervalLimitOrder } from "@calcom/lib";
|
||||||
import { checkBookingLimits, checkBookingLimit } from "@calcom/lib/server";
|
import { checkBookingLimits, checkBookingLimit } from "@calcom/lib/server";
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
||||||
|
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { validateIntervalLimitOrder } from "@calcom/lib";
|
import { validateIntervalLimitOrder } from "@calcom/lib";
|
||||||
import { checkDurationLimit, checkDurationLimits } from "@calcom/lib/server";
|
import { checkDurationLimit, checkDurationLimits } from "@calcom/lib/server";
|
||||||
|
|
||||||
|
|
||||||
type MockData = {
|
type MockData = {
|
||||||
id: number;
|
id: number;
|
||||||
startDate: Date;
|
startDate: Date;
|
||||||
|
|
|
@ -2,10 +2,9 @@ import { expect, it, beforeAll, vi } from "vitest";
|
||||||
|
|
||||||
import { getAggregateWorkingHours } from "@calcom/core/getAggregateWorkingHours";
|
import { getAggregateWorkingHours } from "@calcom/core/getAggregateWorkingHours";
|
||||||
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
|
vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
|
||||||
})
|
});
|
||||||
|
|
||||||
const HAWAII_AND_NEWYORK_TEAM = [
|
const HAWAII_AND_NEWYORK_TEAM = [
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,10 +4,9 @@ import { expect, it, beforeAll, vi } from "vitest";
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { getAvailabilityFromSchedule } from "@calcom/lib/availability";
|
import { getAvailabilityFromSchedule } from "@calcom/lib/availability";
|
||||||
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
|
vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
|
||||||
})
|
});
|
||||||
|
|
||||||
//parse "hh:mm-hh:mm" into <Availability> object
|
//parse "hh:mm-hh:mm" into <Availability> object
|
||||||
const parseWorkingHours = (workingHours: string) => {
|
const parseWorkingHours = (workingHours: string) => {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import prisma from "@calcom/prisma";
|
||||||
import type { BookingStatus } from "@calcom/prisma/enums";
|
import type { BookingStatus } from "@calcom/prisma/enums";
|
||||||
import type { Slot } from "@calcom/trpc/server/routers/viewer/slots/types";
|
import type { Slot } from "@calcom/trpc/server/routers/viewer/slots/types";
|
||||||
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
|
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||||
|
|
||||||
import { getDate, getGoogleCalendarCredential, createBookingScenario } from "../utils/bookingScenario";
|
import { getDate, getGoogleCalendarCredential, createBookingScenario } from "../utils/bookingScenario";
|
||||||
|
|
||||||
// TODO: Mock properly
|
// TODO: Mock properly
|
||||||
|
@ -16,7 +17,7 @@ prismaMock.user.findMany.mockResolvedValue([]);
|
||||||
|
|
||||||
vi.mock("@calcom/lib/constants", () => ({
|
vi.mock("@calcom/lib/constants", () => ({
|
||||||
IS_PRODUCTION: true,
|
IS_PRODUCTION: true,
|
||||||
WEBAPP_URL: "http://localhost:3000"
|
WEBAPP_URL: "http://localhost:3000",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -143,7 +144,6 @@ const TestData = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const cleanup = async () => {
|
const cleanup = async () => {
|
||||||
await prisma.eventType.deleteMany();
|
await prisma.eventType.deleteMany();
|
||||||
await prisma.user.deleteMany();
|
await prisma.user.deleteMany();
|
||||||
|
@ -296,7 +296,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// getSchedule returns timeslots in GMT
|
// getSchedule returns timeslots in GMT
|
||||||
|
@ -328,7 +328,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus3DateString}T18:29:59.999Z`,
|
endTime: `${plus3DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(scheduleForDayWithOneBooking).toHaveTimeSlots(
|
expect(scheduleForDayWithOneBooking).toHaveTimeSlots(
|
||||||
|
@ -393,7 +393,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(scheduleForEventWith30Length).toHaveTimeSlots(
|
expect(scheduleForEventWith30Length).toHaveTimeSlots(
|
||||||
|
@ -429,7 +429,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
// `slotInterval` takes precedence over `length`
|
// `slotInterval` takes precedence over `length`
|
||||||
// 4:30 is utc so it is 10:00 in IST
|
// 4:30 is utc so it is 10:00 in IST
|
||||||
|
@ -493,7 +493,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${todayDateString}T18:29:59.999Z`,
|
endTime: `${todayDateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
expect(scheduleForEventWithBookingNotice13Hrs).toHaveTimeSlots(
|
expect(scheduleForEventWithBookingNotice13Hrs).toHaveTimeSlots(
|
||||||
[
|
[
|
||||||
|
@ -514,7 +514,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${todayDateString}T18:29:59.999Z`,
|
endTime: `${todayDateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
expect(scheduleForEventWithBookingNotice10Hrs).toHaveTimeSlots(
|
expect(scheduleForEventWithBookingNotice10Hrs).toHaveTimeSlots(
|
||||||
[
|
[
|
||||||
|
@ -578,7 +578,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus3DateString}T18:29:59.999Z`,
|
endTime: `${plus3DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(scheduleForEventOnADayWithNonCalBooking).toHaveTimeSlots(
|
expect(scheduleForEventOnADayWithNonCalBooking).toHaveTimeSlots(
|
||||||
|
@ -652,7 +652,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(scheduleForEventOnADayWithCalBooking).toHaveTimeSlots(
|
expect(scheduleForEventOnADayWithCalBooking).toHaveTimeSlots(
|
||||||
|
@ -710,7 +710,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(schedule).toHaveTimeSlots(
|
expect(schedule).toHaveTimeSlots(
|
||||||
|
@ -774,7 +774,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(scheduleForEventOnADayWithDateOverride).toHaveTimeSlots(
|
expect(scheduleForEventOnADayWithDateOverride).toHaveTimeSlots(
|
||||||
|
@ -852,7 +852,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: false,
|
isTeamEvent: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(thisUserAvailability).toHaveTimeSlots(
|
expect(thisUserAvailability).toHaveTimeSlots(
|
||||||
|
@ -950,7 +950,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus1DateString}T18:29:59.999Z`,
|
endTime: `${plus1DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: true,
|
isTeamEvent: true,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(scheduleForTeamEventOnADayWithNoBooking).toHaveTimeSlots(
|
expect(scheduleForTeamEventOnADayWithNoBooking).toHaveTimeSlots(
|
||||||
|
@ -980,7 +980,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: true,
|
isTeamEvent: true,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// A user with blocked time in another event, still affects Team Event availability
|
// A user with blocked time in another event, still affects Team Event availability
|
||||||
|
@ -1088,7 +1088,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: true,
|
isTeamEvent: true,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
// A user with blocked time in another event, still affects Team Event availability
|
// A user with blocked time in another event, still affects Team Event availability
|
||||||
expect(scheduleForTeamEventOnADayWithOneBookingForEachUserButOnDifferentTimeslots).toHaveTimeSlots(
|
expect(scheduleForTeamEventOnADayWithOneBookingForEachUserButOnDifferentTimeslots).toHaveTimeSlots(
|
||||||
|
@ -1116,7 +1116,7 @@ describe("getSchedule", () => {
|
||||||
endTime: `${plus3DateString}T18:29:59.999Z`,
|
endTime: `${plus3DateString}T18:29:59.999Z`,
|
||||||
timeZone: Timezones["+5:30"],
|
timeZone: Timezones["+5:30"],
|
||||||
isTeamEvent: true,
|
isTeamEvent: true,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
// A user with blocked time in another event, still affects Team Event availability
|
// A user with blocked time in another event, still affects Team Event availability
|
||||||
expect(scheduleForTeamEventOnADayWithOneBookingForEachUserOnSameTimeSlot).toHaveTimeSlots(
|
expect(scheduleForTeamEventOnADayWithOneBookingForEachUserOnSameTimeSlot).toHaveTimeSlots(
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { getWorkingHours } from "@calcom/lib/availability";
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
|
vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
|
||||||
})
|
});
|
||||||
|
|
||||||
it("correctly translates Availability (UTC+0) to UTC workingHours", async () => {
|
it("correctly translates Availability (UTC+0) to UTC workingHours", async () => {
|
||||||
expect(
|
expect(
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
||||||
|
|
||||||
import type { EventType } from "@prisma/client";
|
import type { EventType } from "@prisma/client";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
@ -6,8 +8,6 @@ import { buildEventType } from "@calcom/lib/test/builder";
|
||||||
import type { Prisma } from "@calcom/prisma/client";
|
import type { Prisma } from "@calcom/prisma/client";
|
||||||
import type { CompleteEventType, CompleteWorkflowsOnEventTypes } from "@calcom/prisma/zod";
|
import type { CompleteEventType, CompleteWorkflowsOnEventTypes } from "@calcom/prisma/zod";
|
||||||
|
|
||||||
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
|
||||||
|
|
||||||
const mockFindFirstEventType = (data?: Partial<CompleteEventType>) => {
|
const mockFindFirstEventType = (data?: Partial<CompleteEventType>) => {
|
||||||
const eventType = buildEventType(data as Partial<EventType>);
|
const eventType = buildEventType(data as Partial<EventType>);
|
||||||
prismaMock.eventType.findFirst.mockResolvedValue(eventType as EventType);
|
prismaMock.eventType.findFirst.mockResolvedValue(eventType as EventType);
|
||||||
|
@ -97,11 +97,12 @@ describe("handleChildrenEventTypes", () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const { schedulingType, id, teamId, timeZone, users,requiresBookerEmailVerification, ...evType } = mockFindFirstEventType({
|
const { schedulingType, id, teamId, timeZone, users, requiresBookerEmailVerification, ...evType } =
|
||||||
id: 123,
|
mockFindFirstEventType({
|
||||||
metadata: { managedEventConfig: {} },
|
id: 123,
|
||||||
locations: [],
|
metadata: { managedEventConfig: {} },
|
||||||
});
|
locations: [],
|
||||||
|
});
|
||||||
const result = await updateChildrenEventTypes({
|
const result = await updateChildrenEventTypes({
|
||||||
eventTypeId: 1,
|
eventTypeId: 1,
|
||||||
oldEventType: { children: [], team: { name: "" } },
|
oldEventType: { children: [], team: { name: "" } },
|
||||||
|
@ -133,11 +134,21 @@ describe("handleChildrenEventTypes", () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const { schedulingType, id, teamId, timeZone, locations, parentId, userId, scheduleId,requiresBookerEmailVerification, ...evType } =
|
const {
|
||||||
mockFindFirstEventType({
|
schedulingType,
|
||||||
metadata: { managedEventConfig: {} },
|
id,
|
||||||
locations: [],
|
teamId,
|
||||||
});
|
timeZone,
|
||||||
|
locations,
|
||||||
|
parentId,
|
||||||
|
userId,
|
||||||
|
scheduleId,
|
||||||
|
requiresBookerEmailVerification,
|
||||||
|
...evType
|
||||||
|
} = mockFindFirstEventType({
|
||||||
|
metadata: { managedEventConfig: {} },
|
||||||
|
locations: [],
|
||||||
|
});
|
||||||
const result = await updateChildrenEventTypes({
|
const result = await updateChildrenEventTypes({
|
||||||
eventTypeId: 1,
|
eventTypeId: 1,
|
||||||
oldEventType: { children: [{ userId: 4 }], team: { name: "" } },
|
oldEventType: { children: [{ userId: 4 }], team: { name: "" } },
|
||||||
|
@ -218,11 +229,12 @@ describe("handleChildrenEventTypes", () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const { schedulingType, id, teamId, timeZone, users,requiresBookerEmailVerification, ...evType } = mockFindFirstEventType({
|
const { schedulingType, id, teamId, timeZone, users, requiresBookerEmailVerification, ...evType } =
|
||||||
id: 123,
|
mockFindFirstEventType({
|
||||||
metadata: { managedEventConfig: {} },
|
id: 123,
|
||||||
locations: [],
|
metadata: { managedEventConfig: {} },
|
||||||
});
|
locations: [],
|
||||||
|
});
|
||||||
prismaMock.eventType.deleteMany.mockResolvedValue([123] as unknown as Prisma.BatchPayload);
|
prismaMock.eventType.deleteMany.mockResolvedValue([123] as unknown as Prisma.BatchPayload);
|
||||||
const result = await updateChildrenEventTypes({
|
const result = await updateChildrenEventTypes({
|
||||||
eventTypeId: 1,
|
eventTypeId: 1,
|
||||||
|
@ -255,11 +267,20 @@ describe("handleChildrenEventTypes", () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const { schedulingType, id, teamId, timeZone, users, locations, parentId, userId,requiresBookerEmailVerification, ...evType } =
|
const {
|
||||||
mockFindFirstEventType({
|
schedulingType,
|
||||||
metadata: { managedEventConfig: {} },
|
id,
|
||||||
locations: [],
|
teamId,
|
||||||
});
|
timeZone,
|
||||||
|
locations,
|
||||||
|
parentId,
|
||||||
|
userId,
|
||||||
|
requiresBookerEmailVerification,
|
||||||
|
...evType
|
||||||
|
} = mockFindFirstEventType({
|
||||||
|
metadata: { managedEventConfig: {} },
|
||||||
|
locations: [],
|
||||||
|
});
|
||||||
prismaMock.eventType.deleteMany.mockResolvedValue([123] as unknown as Prisma.BatchPayload);
|
prismaMock.eventType.deleteMany.mockResolvedValue([123] as unknown as Prisma.BatchPayload);
|
||||||
const result = await updateChildrenEventTypes({
|
const result = await updateChildrenEventTypes({
|
||||||
eventTypeId: 1,
|
eventTypeId: 1,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { it, expect, describe, beforeAll } from "vitest";
|
import { it, expect, describe, beforeAll } from "vitest";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const { getSubdomainRegExp } = require("../../getSubdomainRegExp");
|
const { getSubdomainRegExp } = require("../../getSubdomainRegExp");
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
@ -30,67 +31,50 @@ beforeAll(async () => {
|
||||||
|
|
||||||
describe("next.config.js - Org Rewrite", () => {
|
describe("next.config.js - Org Rewrite", () => {
|
||||||
const orgHostRegExp = (subdomainRegExp: string) =>
|
const orgHostRegExp = (subdomainRegExp: string) =>
|
||||||
// RegExp copied from pagesAndRewritePaths.js orgHostPath. Do make the change there as well.
|
// RegExp copied from pagesAndRewritePaths.js orgHostPath. Do make the change there as well.
|
||||||
new RegExp(`^(?<orgSlug>${subdomainRegExp})\\.(?!vercel\.app).*`);
|
new RegExp(`^(?<orgSlug>${subdomainRegExp})\\.(?!vercel\.app).*`);
|
||||||
|
|
||||||
describe("Host matching based on NEXT_PUBLIC_WEBAPP_URL", () => {
|
describe("Host matching based on NEXT_PUBLIC_WEBAPP_URL", () => {
|
||||||
it("https://app.cal.com", () => {
|
it("https://app.cal.com", () => {
|
||||||
const subdomainRegExp = getSubdomainRegExp("https://app.cal.com");
|
const subdomainRegExp = getSubdomainRegExp("https://app.cal.com");
|
||||||
expect(orgHostRegExp(subdomainRegExp).exec("app.cal.com")).toEqual(null);
|
expect(orgHostRegExp(subdomainRegExp).exec("app.cal.com")).toEqual(null);
|
||||||
expect(
|
expect(orgHostRegExp(subdomainRegExp).exec("company.app.cal.com")?.groups?.orgSlug).toEqual("company");
|
||||||
orgHostRegExp(subdomainRegExp).exec("company.app.cal.com")?.groups
|
expect(orgHostRegExp(subdomainRegExp).exec("org.cal.com")?.groups?.orgSlug).toEqual("org");
|
||||||
?.orgSlug
|
|
||||||
).toEqual("company");
|
|
||||||
expect(
|
|
||||||
orgHostRegExp(subdomainRegExp).exec("org.cal.com")?.groups?.orgSlug
|
|
||||||
).toEqual("org");
|
|
||||||
|
|
||||||
expect(
|
expect(orgHostRegExp(subdomainRegExp).exec("localhost:3000")).toEqual(null);
|
||||||
orgHostRegExp(subdomainRegExp).exec("localhost:3000")
|
|
||||||
).toEqual(null);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("app.cal.com", () => {
|
it("app.cal.com", () => {
|
||||||
const subdomainRegExp = getSubdomainRegExp("app.cal.com");
|
const subdomainRegExp = getSubdomainRegExp("app.cal.com");
|
||||||
expect(orgHostRegExp(subdomainRegExp).exec("app.cal.com")).toEqual(null);
|
expect(orgHostRegExp(subdomainRegExp).exec("app.cal.com")).toEqual(null);
|
||||||
expect(
|
expect(orgHostRegExp(subdomainRegExp).exec("company.app.cal.com")?.groups?.orgSlug).toEqual("company");
|
||||||
orgHostRegExp(subdomainRegExp).exec("company.app.cal.com")?.groups
|
|
||||||
?.orgSlug
|
|
||||||
).toEqual("company");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("https://calcom.app.company.com", () => {
|
it("https://calcom.app.company.com", () => {
|
||||||
const subdomainRegExp = getSubdomainRegExp(
|
const subdomainRegExp = getSubdomainRegExp("https://calcom.app.company.com");
|
||||||
"https://calcom.app.company.com"
|
expect(orgHostRegExp(subdomainRegExp).exec("calcom.app.company.com")).toEqual(null);
|
||||||
|
expect(orgHostRegExp(subdomainRegExp).exec("acme.calcom.app.company.com")?.groups?.orgSlug).toEqual(
|
||||||
|
"acme"
|
||||||
);
|
);
|
||||||
expect(
|
|
||||||
orgHostRegExp(subdomainRegExp).exec("calcom.app.company.com")
|
|
||||||
).toEqual(null);
|
|
||||||
expect(
|
|
||||||
orgHostRegExp(subdomainRegExp).exec("acme.calcom.app.company.com")
|
|
||||||
?.groups?.orgSlug
|
|
||||||
).toEqual("acme");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("https://calcom.example.com", () => {
|
it("https://calcom.example.com", () => {
|
||||||
const subdomainRegExp = getSubdomainRegExp("https://calcom.example.com");
|
const subdomainRegExp = getSubdomainRegExp("https://calcom.example.com");
|
||||||
expect(orgHostRegExp(subdomainRegExp).exec("calcom.example.com")).toEqual(
|
expect(orgHostRegExp(subdomainRegExp).exec("calcom.example.com")).toEqual(null);
|
||||||
null
|
expect(orgHostRegExp(subdomainRegExp).exec("acme.calcom.example.com")?.groups?.orgSlug).toEqual("acme");
|
||||||
);
|
|
||||||
expect(
|
|
||||||
orgHostRegExp(subdomainRegExp).exec("acme.calcom.example.com")?.groups
|
|
||||||
?.orgSlug
|
|
||||||
).toEqual("acme");
|
|
||||||
// The following also matches which causes anything other than the domain in NEXT_PUBLIC_WEBAPP_URL to give 404
|
// The following also matches which causes anything other than the domain in NEXT_PUBLIC_WEBAPP_URL to give 404
|
||||||
expect(
|
expect(orgHostRegExp(subdomainRegExp).exec("some-other.company.com")?.groups?.orgSlug).toEqual(
|
||||||
orgHostRegExp(subdomainRegExp).exec("some-other.company.com")?.groups
|
"some-other"
|
||||||
?.orgSlug
|
);
|
||||||
).toEqual("some-other");
|
|
||||||
});
|
});
|
||||||
it("Should ignore Vercel preview URLs", () => {
|
it("Should ignore Vercel preview URLs", () => {
|
||||||
const subdomainRegExp = getSubdomainRegExp("https://cal-xxxxxxxx-cal.vercel.app");
|
const subdomainRegExp = getSubdomainRegExp("https://cal-xxxxxxxx-cal.vercel.app");
|
||||||
expect(orgHostRegExp(subdomainRegExp).exec("https://cal-xxxxxxxx-cal.vercel.app")).toMatchInlineSnapshot('null')
|
expect(
|
||||||
expect(orgHostRegExp(subdomainRegExp).exec("cal-xxxxxxxx-cal.vercel.app")).toMatchInlineSnapshot('null')
|
orgHostRegExp(subdomainRegExp).exec("https://cal-xxxxxxxx-cal.vercel.app")
|
||||||
|
).toMatchInlineSnapshot("null");
|
||||||
|
expect(orgHostRegExp(subdomainRegExp).exec("cal-xxxxxxxx-cal.vercel.app")).toMatchInlineSnapshot(
|
||||||
|
"null"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { expect, it } from "vitest";
|
|
||||||
|
|
||||||
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
||||||
|
|
||||||
|
import { expect, it } from "vitest";
|
||||||
|
|
||||||
import { getLuckyUser } from "@calcom/lib/server";
|
import { getLuckyUser } from "@calcom/lib/server";
|
||||||
import { buildUser } from "@calcom/lib/test/builder";
|
import { buildUser } from "@calcom/lib/test/builder";
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import appStoreMock from "../../../../tests/libs/__mocks__/app-store";
|
||||||
|
import i18nMock from "../../../../tests/libs/__mocks__/libServerI18n";
|
||||||
|
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
EventType as PrismaEventType,
|
EventType as PrismaEventType,
|
||||||
User as PrismaUser,
|
User as PrismaUser,
|
||||||
|
@ -17,10 +21,6 @@ import type { BookingStatus } from "@calcom/prisma/enums";
|
||||||
import type { EventBusyDate } from "@calcom/types/Calendar";
|
import type { EventBusyDate } from "@calcom/types/Calendar";
|
||||||
import type { Fixtures } from "@calcom/web/test/fixtures/fixtures";
|
import type { Fixtures } from "@calcom/web/test/fixtures/fixtures";
|
||||||
|
|
||||||
import appStoreMock from "../../../../tests/libs/__mocks__/app-store";
|
|
||||||
import i18nMock from "../../../../tests/libs/__mocks__/libServerI18n";
|
|
||||||
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
|
||||||
|
|
||||||
type App = {
|
type App = {
|
||||||
slug: string;
|
slug: string;
|
||||||
dirName: string;
|
dirName: string;
|
||||||
|
|
|
@ -8,6 +8,9 @@ module.exports = {
|
||||||
printWidth: 110,
|
printWidth: 110,
|
||||||
arrowParens: "always",
|
arrowParens: "always",
|
||||||
importOrder: [
|
importOrder: [
|
||||||
|
// Mocks must be at the top as they contain vi.mock calls
|
||||||
|
"(.*)/__mocks__/(.*)",
|
||||||
|
"<THIRD_PARTY_MODULES>",
|
||||||
"^@(calcom|ee)/(.*)$",
|
"^@(calcom|ee)/(.*)$",
|
||||||
"^@lib/(.*)$",
|
"^@lib/(.*)$",
|
||||||
"^@components/(.*)$",
|
"^@components/(.*)$",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user