Skip to content

Commit

Permalink
refactor: allow managed event tests parallel runs
Browse files Browse the repository at this point in the history
  • Loading branch information
zomars committed Aug 8, 2024
1 parent da5df71 commit 7c0ef77
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 166 deletions.
46 changes: 45 additions & 1 deletion apps/web/playwright/fixtures/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { hashSync as hash } from "bcryptjs";
import { uuid } from "short-uuid";
import { v4 } from "uuid";

import updateChildrenEventTypes from "@calcom/features/ee/managed-event-types/lib/handleChildrenEventTypes";
import stripe from "@calcom/features/ee/payments/server/stripe";
import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability";
import { WEBAPP_URL } from "@calcom/lib/constants";
Expand Down Expand Up @@ -92,6 +93,7 @@ const createTeamEventType = async (
teamEventSlug?: string;
teamEventLength?: number;
seatsPerTimeSlot?: number;
managedEventUnlockedFields?: Record<string, boolean>;
}
) => {
return await prisma.eventType.create({
Expand Down Expand Up @@ -122,6 +124,20 @@ const createTeamEventType = async (
slug: scenario?.teamEventSlug ?? `${teamEventSlug}-team-id-${team.id}`,
length: scenario?.teamEventLength ?? 30,
seatsPerTimeSlot: scenario?.seatsPerTimeSlot,
locations: [{ type: "integrations:daily" }],
metadata:
scenario?.schedulingType === SchedulingType.MANAGED
? {
managedEventConfig: {
unlockedFields: {
locations: true,
scheduleId: true,
destinationCalendar: true,
...scenario?.managedEventUnlockedFields,
},
},
}
: undefined,
},
});
};
Expand Down Expand Up @@ -256,6 +272,8 @@ export const createUsersFixture = (
hasSubteam?: true;
isUnpublished?: true;
seatsPerTimeSlot?: number;
addManagedEventToTeamMates?: boolean;
managedEventUnlockedFields?: Record<string, boolean>;
} = {}
) => {
const _user = await prisma.user.create({
Expand Down Expand Up @@ -475,6 +493,31 @@ export const createUsersFixture = (
teamMates.push(teamUser);
store.users.push(teammateFixture);
}
// If the teamEvent is a managed one, we add the team mates to it.
if (scenario.schedulingType === SchedulingType.MANAGED && scenario.addManagedEventToTeamMates) {
await updateChildrenEventTypes({
eventTypeId: teamEvent.id,
currentUserId: user.id,
hashedLink: null,
connectedLink: null,
oldEventType: {
team: null,
},
updatedEventType: teamEvent,
children: teamMates.map((tm) => ({
hidden: false,
owner: {
id: tm.id,
name: tm.name || tm.username || "Nameless",
email: tm.email,
eventTypeSlugs: [],
},
})),
profileId: null,
prisma,
updatedValues: {},
});
}
// Add Teammates to OrgUsers
if (scenario.isOrg) {
const orgProfilesCreate = teamMates
Expand Down Expand Up @@ -684,10 +727,11 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => {
userId: user.id,
},
}),
getFirstTeamEvent: async (teamId: number) => {
getFirstTeamEvent: async (teamId: number, schedulingType?: SchedulingType) => {
return prisma.eventType.findFirstOrThrow({
where: {
teamId,
schedulingType,
},
});
},
Expand Down
Loading

0 comments on commit 7c0ef77

Please sign in to comment.