diff --git a/jest.config.ts b/jest.config.ts index 5bd35e14ed..9123946007 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -54,9 +54,15 @@ const config: Config = { displayName: "@calcom/api", roots: ["/apps/api"], testMatch: ["**/test/lib/**/*.(spec|test).(ts|tsx|js)"], + setupFilesAfterEnv: ["/tests/config/singleton.ts"], transform: { "^.+\\.ts?$": "ts-jest", }, + globals: { + "ts-jest": { + tsconfig: "/apps/api/tsconfig.json", + }, + }, transformIgnorePatterns: ["/node_modules/", "^.+\\.module\\.(css|sass|scss)$"], testEnvironment: "node", clearMocks: true, diff --git a/packages/lib/test/builder.ts b/packages/lib/test/builder.ts index b5647b0bca..c04b1522c8 100644 --- a/packages/lib/test/builder.ts +++ b/packages/lib/test/builder.ts @@ -1,5 +1,5 @@ import { faker } from "@faker-js/faker"; -import { Prisma, User, UserPlan } from "@prisma/client"; +import { Booking, BookingStatus, EventType, Prisma, UserPlan, Webhook } from "@prisma/client"; import { CalendarEvent, Person, VideoCallData } from "@calcom/types/Calendar"; @@ -28,6 +28,116 @@ export const buildPerson = (person?: Partial): Person => { }; }; +export const buildBooking = (booking?: Partial): Booking => { + return { + id: faker.datatype.number(), + uid: faker.datatype.uuid(), + userId: null, + eventTypeId: null, + title: faker.lorem.sentence(), + description: faker.lorem.paragraph(), + customInputs: null, + startTime: faker.date.future(), + endTime: faker.date.future(), + location: null, + createdAt: new Date(), + updatedAt: null, + status: BookingStatus.ACCEPTED, + paid: false, + destinationCalendarId: null, + cancellationReason: null, + rejectionReason: null, + dynamicEventSlugRef: null, + dynamicGroupSlugRef: null, + rescheduled: null, + fromReschedule: null, + recurringEventId: null, + smsReminderNumber: null, + scheduledJobs: [], + ...booking, + }; +}; + +export const buildEventType = (eventType?: Partial): EventType => { + return { + id: faker.datatype.number(), + title: faker.lorem.sentence(), + slug: faker.lorem.slug(), + description: faker.lorem.paragraph(), + position: 1, + locations: null, + length: 15, + hidden: false, + userId: null, + teamId: null, + eventName: faker.lorem.words(), + timeZone: null, + periodType: "UNLIMITED", + periodStartDate: null, + periodEndDate: null, + periodDays: null, + periodCountCalendarDays: null, + recurringEvent: null, + requiresConfirmation: false, + disableGuests: false, + hideCalendarNotes: false, + minimumBookingNotice: 120, + beforeEventBuffer: 0, + afterEventBuffer: 0, + seatsPerTimeSlot: null, + schedulingType: null, + scheduleId: null, + price: 0, + currency: "usd", + slotInterval: null, + metadata: null, + successRedirectUrl: null, + ...eventType, + }; +}; + +export const buildWebhook = (webhook?: Partial): Webhook => { + return { + id: faker.datatype.uuid(), + eventTypeId: faker.datatype.number(), + subscriberUrl: "http://mockedURL.com", + payloadTemplate: null, + createdAt: faker.datatype.datetime(), + appId: null, + userId: null, + secret: faker.lorem.slug(), + active: true, + eventTriggers: [], + ...webhook, + }; +}; + +export const buildSubscriberEvent = (booking?: Partial) => { + return { + type: booking?.title || "", + title: booking?.title, + description: "", + additionalNotes: "", + customInputs: {}, + startTime: booking?.startTime, + endTime: booking?.endTime, + organizer: { + name: "", + email: "", + timeZone: "", + language: { + locale: "en", + }, + }, + attendees: [], + location: "", + destinationCalendar: null, + hideCalendar: false, + uid: booking?.uid, + metadata: {}, + }; +}; + export const buildCalendarEvent = (event?: Partial): CalendarEvent => { return { uid: faker.datatype.uuid(),