diff --git a/.prettierignore b/.prettierignore index 013d82b3a2..7944833941 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,7 +7,6 @@ public *.lock *.log -*.test.ts .gitignore .npmignore diff --git a/apps/web/.prettierignore b/apps/web/.prettierignore index e0f842003c..a31370892c 100644 --- a/apps/web/.prettierignore +++ b/apps/web/.prettierignore @@ -1,2 +1 @@ -public/embed -*.test.ts +public/embed \ No newline at end of file diff --git a/apps/web/test/lib/availabilityAsString.test.ts b/apps/web/test/lib/availabilityAsString.test.ts index 144a621d71..69c8fe8e07 100644 --- a/apps/web/test/lib/availabilityAsString.test.ts +++ b/apps/web/test/lib/availabilityAsString.test.ts @@ -11,18 +11,17 @@ it("correctly handles 1 day", async () => { startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)), endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)), date: null, - scheduleId: 1 + scheduleId: 1, }; const result = availabilityAsString(availability, { - locale: 'en', - hour12: true + locale: "en", + hour12: true, }); expect(replaceUnicodeSpace(result)).toBe("Mon, 9:00 AM - 5:00 PM"); }); - it("correctly handles all days", async () => { const availability = { id: 1, @@ -32,12 +31,12 @@ it("correctly handles all days", async () => { startTime: new Date(Date.UTC(1970, 1, 1, 9, 0, 0, 0)), endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)), date: null, - scheduleId: 1 + scheduleId: 1, }; const result = availabilityAsString(availability, { - locale: 'en', - hour12: true + locale: "en", + hour12: true, }); 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)), endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)), date: null, - scheduleId: 1 + scheduleId: 1, }; const result = availabilityAsString(availability, { - locale: 'en', - hour12: true + locale: "en", + hour12: true, }); 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)), endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)), date: null, - scheduleId: 1 + scheduleId: 1, }; const result = availabilityAsString(availability, { - locale: 'en', - hour12: true + locale: "en", + hour12: true, }); 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)), endTime: new Date(Date.UTC(1970, 1, 1, 17, 0, 0, 0)), date: null, - scheduleId: 1 + scheduleId: 1, }; const result = availabilityAsString(availability, { - locale: 'en', - hour12: false + locale: "en", + hour12: false, }); 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 // availability.ts file, opted for this instead. const replaceUnicodeSpace = (string: string) => { - return string.replace(/\u202f/g, ' '); -} + return string.replace(/\u202f/g, " "); +}; diff --git a/apps/web/test/lib/checkBookingLimits.test.ts b/apps/web/test/lib/checkBookingLimits.test.ts index e834c10482..4cab8d21c3 100644 --- a/apps/web/test/lib/checkBookingLimits.test.ts +++ b/apps/web/test/lib/checkBookingLimits.test.ts @@ -1,6 +1,7 @@ -import { describe, expect, it } from "vitest"; import prismaMock from "../../../../tests/libs/__mocks__/prisma"; +import { describe, expect, it } from "vitest"; + import dayjs from "@calcom/dayjs"; import { validateIntervalLimitOrder } from "@calcom/lib"; import { checkBookingLimits, checkBookingLimit } from "@calcom/lib/server"; diff --git a/apps/web/test/lib/checkDurationLimits.test.ts b/apps/web/test/lib/checkDurationLimits.test.ts index 2fd6d39c27..d8c7daf827 100644 --- a/apps/web/test/lib/checkDurationLimits.test.ts +++ b/apps/web/test/lib/checkDurationLimits.test.ts @@ -1,11 +1,11 @@ -import { describe, expect, it } from "vitest"; import prismaMock from "../../../../tests/libs/__mocks__/prisma"; +import { describe, expect, it } from "vitest"; + import dayjs from "@calcom/dayjs"; import { validateIntervalLimitOrder } from "@calcom/lib"; import { checkDurationLimit, checkDurationLimits } from "@calcom/lib/server"; - type MockData = { id: number; startDate: Date; diff --git a/apps/web/test/lib/getAggregateWorkingHours.test.ts b/apps/web/test/lib/getAggregateWorkingHours.test.ts index afedcd0e9d..f054a505ed 100644 --- a/apps/web/test/lib/getAggregateWorkingHours.test.ts +++ b/apps/web/test/lib/getAggregateWorkingHours.test.ts @@ -2,10 +2,9 @@ import { expect, it, beforeAll, vi } from "vitest"; import { getAggregateWorkingHours } from "@calcom/core/getAggregateWorkingHours"; - beforeAll(() => { vi.setSystemTime(new Date("2021-06-20T11:59:59Z")); -}) +}); const HAWAII_AND_NEWYORK_TEAM = [ { diff --git a/apps/web/test/lib/getAvailabilityFromSchedule.test.ts b/apps/web/test/lib/getAvailabilityFromSchedule.test.ts index 8bfcbfad3d..0052254e22 100644 --- a/apps/web/test/lib/getAvailabilityFromSchedule.test.ts +++ b/apps/web/test/lib/getAvailabilityFromSchedule.test.ts @@ -4,10 +4,9 @@ import { expect, it, beforeAll, vi } from "vitest"; import dayjs from "@calcom/dayjs"; import { getAvailabilityFromSchedule } from "@calcom/lib/availability"; - beforeAll(() => { vi.setSystemTime(new Date("2021-06-20T11:59:59Z")); -}) +}); //parse "hh:mm-hh:mm" into object const parseWorkingHours = (workingHours: string) => { diff --git a/apps/web/test/lib/getSchedule.test.ts b/apps/web/test/lib/getSchedule.test.ts index 8866232d1b..efce574877 100644 --- a/apps/web/test/lib/getSchedule.test.ts +++ b/apps/web/test/lib/getSchedule.test.ts @@ -8,6 +8,7 @@ import prisma from "@calcom/prisma"; import type { BookingStatus } from "@calcom/prisma/enums"; import type { Slot } from "@calcom/trpc/server/routers/viewer/slots/types"; import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util"; + import { getDate, getGoogleCalendarCredential, createBookingScenario } from "../utils/bookingScenario"; // TODO: Mock properly @@ -16,7 +17,7 @@ prismaMock.user.findMany.mockResolvedValue([]); vi.mock("@calcom/lib/constants", () => ({ IS_PRODUCTION: true, - WEBAPP_URL: "http://localhost:3000" + WEBAPP_URL: "http://localhost:3000", })); declare global { @@ -143,7 +144,6 @@ const TestData = { }, }; - const cleanup = async () => { await prisma.eventType.deleteMany(); await prisma.user.deleteMany(); @@ -296,7 +296,7 @@ describe("getSchedule", () => { endTime: `${plus2DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); // getSchedule returns timeslots in GMT @@ -328,7 +328,7 @@ describe("getSchedule", () => { endTime: `${plus3DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); expect(scheduleForDayWithOneBooking).toHaveTimeSlots( @@ -393,7 +393,7 @@ describe("getSchedule", () => { endTime: `${plus2DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); expect(scheduleForEventWith30Length).toHaveTimeSlots( @@ -429,7 +429,7 @@ describe("getSchedule", () => { endTime: `${plus2DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); // `slotInterval` takes precedence over `length` // 4:30 is utc so it is 10:00 in IST @@ -493,7 +493,7 @@ describe("getSchedule", () => { endTime: `${todayDateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); expect(scheduleForEventWithBookingNotice13Hrs).toHaveTimeSlots( [ @@ -514,7 +514,7 @@ describe("getSchedule", () => { endTime: `${todayDateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); expect(scheduleForEventWithBookingNotice10Hrs).toHaveTimeSlots( [ @@ -578,7 +578,7 @@ describe("getSchedule", () => { endTime: `${plus3DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); expect(scheduleForEventOnADayWithNonCalBooking).toHaveTimeSlots( @@ -652,7 +652,7 @@ describe("getSchedule", () => { endTime: `${plus2DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); expect(scheduleForEventOnADayWithCalBooking).toHaveTimeSlots( @@ -710,7 +710,7 @@ describe("getSchedule", () => { endTime: `${plus2DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); expect(schedule).toHaveTimeSlots( @@ -774,7 +774,7 @@ describe("getSchedule", () => { endTime: `${plus2DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); expect(scheduleForEventOnADayWithDateOverride).toHaveTimeSlots( @@ -852,7 +852,7 @@ describe("getSchedule", () => { endTime: `${plus2DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: false, - } + }, }); expect(thisUserAvailability).toHaveTimeSlots( @@ -950,7 +950,7 @@ describe("getSchedule", () => { endTime: `${plus1DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: true, - } + }, }); expect(scheduleForTeamEventOnADayWithNoBooking).toHaveTimeSlots( @@ -980,7 +980,7 @@ describe("getSchedule", () => { endTime: `${plus2DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: true, - } + }, }); // 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`, timeZone: Timezones["+5:30"], isTeamEvent: true, - } + }, }); // A user with blocked time in another event, still affects Team Event availability expect(scheduleForTeamEventOnADayWithOneBookingForEachUserButOnDifferentTimeslots).toHaveTimeSlots( @@ -1116,7 +1116,7 @@ describe("getSchedule", () => { endTime: `${plus3DateString}T18:29:59.999Z`, timeZone: Timezones["+5:30"], isTeamEvent: true, - } + }, }); // A user with blocked time in another event, still affects Team Event availability expect(scheduleForTeamEventOnADayWithOneBookingForEachUserOnSameTimeSlot).toHaveTimeSlots( diff --git a/apps/web/test/lib/getWorkingHours.test.ts b/apps/web/test/lib/getWorkingHours.test.ts index 5d8ca1696f..f8c6a5a7a0 100644 --- a/apps/web/test/lib/getWorkingHours.test.ts +++ b/apps/web/test/lib/getWorkingHours.test.ts @@ -5,7 +5,7 @@ import { getWorkingHours } from "@calcom/lib/availability"; beforeAll(() => { vi.setSystemTime(new Date("2021-06-20T11:59:59Z")); -}) +}); it("correctly translates Availability (UTC+0) to UTC workingHours", async () => { expect( diff --git a/apps/web/test/lib/handleChildrenEventTypes.test.ts b/apps/web/test/lib/handleChildrenEventTypes.test.ts index 7684c7b399..cc6cd5850f 100644 --- a/apps/web/test/lib/handleChildrenEventTypes.test.ts +++ b/apps/web/test/lib/handleChildrenEventTypes.test.ts @@ -1,3 +1,5 @@ +import prismaMock from "../../../../tests/libs/__mocks__/prisma"; + import type { EventType } from "@prisma/client"; 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 { CompleteEventType, CompleteWorkflowsOnEventTypes } from "@calcom/prisma/zod"; -import prismaMock from "../../../../tests/libs/__mocks__/prisma"; - const mockFindFirstEventType = (data?: Partial) => { const eventType = buildEventType(data as Partial); prismaMock.eventType.findFirst.mockResolvedValue(eventType as EventType); @@ -97,11 +97,12 @@ describe("handleChildrenEventTypes", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // eslint-disable-next-line - const { schedulingType, id, teamId, timeZone, users,requiresBookerEmailVerification, ...evType } = mockFindFirstEventType({ - id: 123, - metadata: { managedEventConfig: {} }, - locations: [], - }); + const { schedulingType, id, teamId, timeZone, users, requiresBookerEmailVerification, ...evType } = + mockFindFirstEventType({ + id: 123, + metadata: { managedEventConfig: {} }, + locations: [], + }); const result = await updateChildrenEventTypes({ eventTypeId: 1, oldEventType: { children: [], team: { name: "" } }, @@ -133,11 +134,21 @@ describe("handleChildrenEventTypes", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // eslint-disable-next-line - const { schedulingType, id, teamId, timeZone, locations, parentId, userId, scheduleId,requiresBookerEmailVerification, ...evType } = - mockFindFirstEventType({ - metadata: { managedEventConfig: {} }, - locations: [], - }); + const { + schedulingType, + id, + teamId, + timeZone, + locations, + parentId, + userId, + scheduleId, + requiresBookerEmailVerification, + ...evType + } = mockFindFirstEventType({ + metadata: { managedEventConfig: {} }, + locations: [], + }); const result = await updateChildrenEventTypes({ eventTypeId: 1, oldEventType: { children: [{ userId: 4 }], team: { name: "" } }, @@ -218,11 +229,12 @@ describe("handleChildrenEventTypes", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // eslint-disable-next-line - const { schedulingType, id, teamId, timeZone, users,requiresBookerEmailVerification, ...evType } = mockFindFirstEventType({ - id: 123, - metadata: { managedEventConfig: {} }, - locations: [], - }); + const { schedulingType, id, teamId, timeZone, users, requiresBookerEmailVerification, ...evType } = + mockFindFirstEventType({ + id: 123, + metadata: { managedEventConfig: {} }, + locations: [], + }); prismaMock.eventType.deleteMany.mockResolvedValue([123] as unknown as Prisma.BatchPayload); const result = await updateChildrenEventTypes({ eventTypeId: 1, @@ -255,11 +267,20 @@ describe("handleChildrenEventTypes", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // eslint-disable-next-line - const { schedulingType, id, teamId, timeZone, users, locations, parentId, userId,requiresBookerEmailVerification, ...evType } = - mockFindFirstEventType({ - metadata: { managedEventConfig: {} }, - locations: [], - }); + const { + schedulingType, + id, + teamId, + timeZone, + locations, + parentId, + userId, + requiresBookerEmailVerification, + ...evType + } = mockFindFirstEventType({ + metadata: { managedEventConfig: {} }, + locations: [], + }); prismaMock.eventType.deleteMany.mockResolvedValue([123] as unknown as Prisma.BatchPayload); const result = await updateChildrenEventTypes({ eventTypeId: 1, diff --git a/apps/web/test/lib/next-config.test.ts b/apps/web/test/lib/next-config.test.ts index efa875c56d..8c70bb66d0 100644 --- a/apps/web/test/lib/next-config.test.ts +++ b/apps/web/test/lib/next-config.test.ts @@ -1,4 +1,5 @@ import { it, expect, describe, beforeAll } from "vitest"; + // eslint-disable-next-line @typescript-eslint/no-var-requires const { getSubdomainRegExp } = require("../../getSubdomainRegExp"); // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -30,67 +31,50 @@ beforeAll(async () => { describe("next.config.js - Org Rewrite", () => { 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(`^(?${subdomainRegExp})\\.(?!vercel\.app).*`); describe("Host matching based on NEXT_PUBLIC_WEBAPP_URL", () => { it("https://app.cal.com", () => { const subdomainRegExp = getSubdomainRegExp("https://app.cal.com"); expect(orgHostRegExp(subdomainRegExp).exec("app.cal.com")).toEqual(null); - expect( - orgHostRegExp(subdomainRegExp).exec("company.app.cal.com")?.groups - ?.orgSlug - ).toEqual("company"); - expect( - orgHostRegExp(subdomainRegExp).exec("org.cal.com")?.groups?.orgSlug - ).toEqual("org"); + expect(orgHostRegExp(subdomainRegExp).exec("company.app.cal.com")?.groups?.orgSlug).toEqual("company"); + expect(orgHostRegExp(subdomainRegExp).exec("org.cal.com")?.groups?.orgSlug).toEqual("org"); - expect( - orgHostRegExp(subdomainRegExp).exec("localhost:3000") - ).toEqual(null); + expect(orgHostRegExp(subdomainRegExp).exec("localhost:3000")).toEqual(null); }); it("app.cal.com", () => { const subdomainRegExp = getSubdomainRegExp("app.cal.com"); expect(orgHostRegExp(subdomainRegExp).exec("app.cal.com")).toEqual(null); - expect( - orgHostRegExp(subdomainRegExp).exec("company.app.cal.com")?.groups - ?.orgSlug - ).toEqual("company"); + expect(orgHostRegExp(subdomainRegExp).exec("company.app.cal.com")?.groups?.orgSlug).toEqual("company"); }); it("https://calcom.app.company.com", () => { - const subdomainRegExp = getSubdomainRegExp( - "https://calcom.app.company.com" + const subdomainRegExp = getSubdomainRegExp("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", () => { const subdomainRegExp = getSubdomainRegExp("https://calcom.example.com"); - expect(orgHostRegExp(subdomainRegExp).exec("calcom.example.com")).toEqual( - null - ); - expect( - orgHostRegExp(subdomainRegExp).exec("acme.calcom.example.com")?.groups - ?.orgSlug - ).toEqual("acme"); + expect(orgHostRegExp(subdomainRegExp).exec("calcom.example.com")).toEqual(null); + 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 - expect( - orgHostRegExp(subdomainRegExp).exec("some-other.company.com")?.groups - ?.orgSlug - ).toEqual("some-other"); + expect(orgHostRegExp(subdomainRegExp).exec("some-other.company.com")?.groups?.orgSlug).toEqual( + "some-other" + ); }); it("Should ignore Vercel preview URLs", () => { const subdomainRegExp = getSubdomainRegExp("https://cal-xxxxxxxx-cal.vercel.app"); - expect(orgHostRegExp(subdomainRegExp).exec("https://cal-xxxxxxxx-cal.vercel.app")).toMatchInlineSnapshot('null') - expect(orgHostRegExp(subdomainRegExp).exec("cal-xxxxxxxx-cal.vercel.app")).toMatchInlineSnapshot('null') + expect( + orgHostRegExp(subdomainRegExp).exec("https://cal-xxxxxxxx-cal.vercel.app") + ).toMatchInlineSnapshot("null"); + expect(orgHostRegExp(subdomainRegExp).exec("cal-xxxxxxxx-cal.vercel.app")).toMatchInlineSnapshot( + "null" + ); }); }); diff --git a/apps/web/test/lib/team-event-types.test.ts b/apps/web/test/lib/team-event-types.test.ts index 608fc151f4..2f4813fc23 100644 --- a/apps/web/test/lib/team-event-types.test.ts +++ b/apps/web/test/lib/team-event-types.test.ts @@ -1,7 +1,7 @@ -import { expect, it } from "vitest"; - import prismaMock from "../../../../tests/libs/__mocks__/prisma"; +import { expect, it } from "vitest"; + import { getLuckyUser } from "@calcom/lib/server"; import { buildUser } from "@calcom/lib/test/builder"; diff --git a/apps/web/test/utils/bookingScenario.ts b/apps/web/test/utils/bookingScenario.ts index 2dc3532257..c56400c1a6 100644 --- a/apps/web/test/utils/bookingScenario.ts +++ b/apps/web/test/utils/bookingScenario.ts @@ -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 { EventType as PrismaEventType, User as PrismaUser, @@ -17,10 +21,6 @@ import type { BookingStatus } from "@calcom/prisma/enums"; import type { EventBusyDate } from "@calcom/types/Calendar"; 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 = { slug: string; dirName: string; diff --git a/packages/config/prettier-preset.js b/packages/config/prettier-preset.js index 840c7c5cac..315e7e8d78 100644 --- a/packages/config/prettier-preset.js +++ b/packages/config/prettier-preset.js @@ -8,6 +8,9 @@ module.exports = { printWidth: 110, arrowParens: "always", importOrder: [ + // Mocks must be at the top as they contain vi.mock calls + "(.*)/__mocks__/(.*)", + "", "^@(calcom|ee)/(.*)$", "^@lib/(.*)$", "^@components/(.*)$",