cal.pub0.org/packages/lib/test/builder.ts

219 lines
5.5 KiB
TypeScript
Raw Normal View History

import { faker } from "@faker-js/faker";
import type { Booking, EventType, Prisma, Webhook } from "@prisma/client";
import { BookingStatus } from "@prisma/client";
import type { CalendarEvent, Person, VideoCallData } from "@calcom/types/Calendar";
export const buildVideoCallData = (callData?: Partial<VideoCallData>): VideoCallData => {
return {
type: faker.helpers.arrayElement(["zoom_video", "stream_video"]),
id: faker.datatype.uuid(),
password: faker.internet.password(),
url: faker.internet.url(),
...callData,
};
};
export const buildPerson = (person?: Partial<Person>): Person => {
return {
name: faker.name.firstName(),
email: faker.internet.email(),
timeZone: faker.address.timeZone(),
username: faker.internet.userName(),
id: faker.datatype.number(),
language: {
locale: faker.random.locale(),
translate: (key: string) => key,
},
...person,
};
};
export const buildBooking = (booking?: Partial<Booking>): 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: [],
metadata: null,
Feature/ Manage Booking Questions (#6560) * WIP * Create Booking Questions builder * Renaming things * wip * wip * Implement Add Guests and other fixes * Fixes after testing * Fix wrong status code 404 * Fixes * Lint fixes * Self review comments addressed * More self review comments addressed * Feedback from zomars * BugFixes after testing * More fixes discovered during review * Update packages/lib/hooks/useHasPaidPlan.ts Co-authored-by: Omar López <zomars@me.com> * More fixes discovered during review * Update packages/ui/components/form/inputs/Input.tsx Co-authored-by: Omar López <zomars@me.com> * More fixes discovered during review * Update packages/features/bookings/lib/getBookingFields.ts Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> * More PR review fixes * Hide label using labelSrOnly * Fix Carinas feedback and implement 2 workflows thingy * Misc fixes * Fixes from Loom comments and PR * Fix a lint errr * Fix cancellation reason * Fix regression in edit due to name conflict check * Update packages/features/form-builder/FormBuilder.tsx Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Fix options not set when default value is used * Restoring reqBody to avoid uneeded conflicts with main * Type fix * Update apps/web/components/booking/pages/BookingPage.tsx Co-authored-by: Omar López <zomars@me.com> * Update packages/features/form-builder/FormBuilder.tsx Co-authored-by: Omar López <zomars@me.com> * Update apps/web/components/booking/pages/BookingPage.tsx Co-authored-by: Omar López <zomars@me.com> * Apply suggestions from code review Co-authored-by: Omar López <zomars@me.com> * Show fields but mark them disabled * Apply suggestions from code review Co-authored-by: Omar López <zomars@me.com> * More comments * Fix booking success page crash when a booking doesnt have newly added required fields response * Dark theme asterisk not visible * Make location required in zodSchema as was there in production * Linting * Remove _metadata.ts files for apps that have config.json * Revert "Remove _metadata.ts files for apps that have config.json" This reverts commit d79bdd336cf312a30a8943af94c059947bd91ccd. * Fix lint error * Fix missing condition for samlSPConfig * Delete unexpectedly added file * yarn.lock change not required * fix types * Make checkboxes rounded * Fix defaultLabel being stored as label due to SSR rendering * Shaved 16kb from booking page * Explicit types for profile * Show payment value only if price is greater than 0 * Fix type error * Add back inferred types as they are failing * Fix duplicate label on number --------- Co-authored-by: zomars <zomars@me.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: Efraín Rochín <roae.85@gmail.com>
2023-03-02 18:15:28 +00:00
responses: null,
...booking,
};
};
export const buildEventType = (eventType?: Partial<EventType>): 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,
seatsShowAttendees: null,
schedulingType: null,
scheduleId: null,
Feat Booking Limits (#4759) * Add db relevant stuff * Basic UI there still buggy * This UI is hard - some progress * Fix awful state mangament * Fix re-ordering * Working UI logic! * Partical working minMax function * Fix min max * bookingLImits api + tests * Moved checkBookingLimits to backend only code * Fix httperror import * Return busy times * Remove avaliablity calc * Working for everything but year * Remove redundant + fix async forloop * Add compatible type * Future proof with evenTypeId filter * Fix commonjson * Sorting + validation + tests + passing * Add empty test * Move validation check to backend * Add bookinglimits in trpc * Add test for undefined * Apply suggestions from code review Co-authored-by: Jeroen Reumkens <hello@jeroenreumkens.nl> * Update apps/web/components/v2/eventtype/EventLimitsTab.tsx Co-authored-by: Jeroen Reumkens <hello@jeroenreumkens.nl> * Rename value for eligiability * Rename keyof type * status code * Fix toggle not toggling off * Update apps/web/pages/v2/event-types/[type]/index.tsx Co-authored-by: Omar López <zomars@me.com> * Update apps/web/pages/v2/event-types/[type]/index.tsx Co-authored-by: Omar López <zomars@me.com> * Change back to undefined as it is working for sean. See if it fails on testapp * Fixing test builder Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Jeroen Reumkens <hello@jeroenreumkens.nl> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Leo Giovanetti <hello@leog.me>
2022-10-12 05:29:04 +00:00
bookingLimits: null,
durationLimits: null,
price: 0,
currency: "usd",
slotInterval: null,
metadata: null,
successRedirectUrl: null,
Feature/ Manage Booking Questions (#6560) * WIP * Create Booking Questions builder * Renaming things * wip * wip * Implement Add Guests and other fixes * Fixes after testing * Fix wrong status code 404 * Fixes * Lint fixes * Self review comments addressed * More self review comments addressed * Feedback from zomars * BugFixes after testing * More fixes discovered during review * Update packages/lib/hooks/useHasPaidPlan.ts Co-authored-by: Omar López <zomars@me.com> * More fixes discovered during review * Update packages/ui/components/form/inputs/Input.tsx Co-authored-by: Omar López <zomars@me.com> * More fixes discovered during review * Update packages/features/bookings/lib/getBookingFields.ts Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> * More PR review fixes * Hide label using labelSrOnly * Fix Carinas feedback and implement 2 workflows thingy * Misc fixes * Fixes from Loom comments and PR * Fix a lint errr * Fix cancellation reason * Fix regression in edit due to name conflict check * Update packages/features/form-builder/FormBuilder.tsx Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Fix options not set when default value is used * Restoring reqBody to avoid uneeded conflicts with main * Type fix * Update apps/web/components/booking/pages/BookingPage.tsx Co-authored-by: Omar López <zomars@me.com> * Update packages/features/form-builder/FormBuilder.tsx Co-authored-by: Omar López <zomars@me.com> * Update apps/web/components/booking/pages/BookingPage.tsx Co-authored-by: Omar López <zomars@me.com> * Apply suggestions from code review Co-authored-by: Omar López <zomars@me.com> * Show fields but mark them disabled * Apply suggestions from code review Co-authored-by: Omar López <zomars@me.com> * More comments * Fix booking success page crash when a booking doesnt have newly added required fields response * Dark theme asterisk not visible * Make location required in zodSchema as was there in production * Linting * Remove _metadata.ts files for apps that have config.json * Revert "Remove _metadata.ts files for apps that have config.json" This reverts commit d79bdd336cf312a30a8943af94c059947bd91ccd. * Fix lint error * Fix missing condition for samlSPConfig * Delete unexpectedly added file * yarn.lock change not required * fix types * Make checkboxes rounded * Fix defaultLabel being stored as label due to SSR rendering * Shaved 16kb from booking page * Explicit types for profile * Show payment value only if price is greater than 0 * Fix type error * Add back inferred types as they are failing * Fix duplicate label on number --------- Co-authored-by: zomars <zomars@me.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: Efraín Rochín <roae.85@gmail.com>
2023-03-02 18:15:28 +00:00
bookingFields: null,
...eventType,
};
};
export const buildWebhook = (webhook?: Partial<Webhook>): 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<Booking>) => {
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>): CalendarEvent => {
return {
uid: faker.datatype.uuid(),
type: faker.helpers.arrayElement(["event", "meeting"]),
title: faker.lorem.sentence(),
startTime: faker.date.future().toISOString(),
endTime: faker.date.future().toISOString(),
location: faker.address.city(),
description: faker.lorem.paragraph(),
attendees: [],
customInputs: {},
additionalNotes: faker.lorem.paragraph(),
organizer: buildPerson(),
videoCallData: buildVideoCallData(),
...event,
};
};
type UserPayload = Prisma.UserGetPayload<{
include: {
credentials: true;
destinationCalendar: true;
availability: true;
selectedCalendars: true;
schedules: true;
};
}>;
export const buildUser = <T extends Partial<UserPayload>>(user?: T): UserPayload => {
return {
name: faker.name.firstName(),
email: faker.internet.email(),
timeZone: faker.address.timeZone(),
username: faker.internet.userName(),
id: 0,
allowDynamicBooking: true,
availability: [],
avatar: "",
away: false,
bio: null,
brandColor: "#292929",
bufferTime: 0,
completedOnboarding: false,
createdDate: new Date(),
credentials: [],
darkBrandColor: "#fafafa",
defaultScheduleId: null,
destinationCalendar: null,
disableImpersonation: false,
emailVerified: null,
endTime: 0,
hideBranding: true,
identityProvider: "CAL",
identityProviderId: null,
invitedTo: null,
locale: "en",
metadata: null,
password: null,
role: "USER",
schedules: [],
selectedCalendars: [],
startTime: 0,
theme: null,
timeFormat: null,
trialEndsAt: null,
twoFactorEnabled: false,
twoFactorSecret: null,
verified: false,
weekStart: "",
...user,
};
};