fix: metadata is overwritten for child managed eventType when updating parent (#18059)

* fix: metadata is overwirten

* Update

* type error

* Update

* fix test

* fix type error
This commit is contained in:
Anik Dhabal Babu authored and GitHub committed 2024-12-24 21:21:43 +05:30
1 parent e6ef4e1988
commit 9036080fcf
2 files changed
+48 -9

No files matched your search

@@ -7,6 +7,7 @@ import { describe, expect, it, vi } from "vitest";
import updateChildrenEventTypes from "@calcom/features/ee/managed-event-types/lib/handleChildrenEventTypes";
import { buildEventType } from "@calcom/lib/test/builder";
import type { Prisma } from "@calcom/prisma/client";
import { SchedulingType } from "@calcom/prisma/enums";
import type { CompleteEventType, CompleteWorkflowsOnEventTypes } from "@calcom/prisma/zod";
const mockFindFirstEventType = (data?: Partial<CompleteEventType>) => {
@@ -401,7 +402,27 @@ describe("handleChildrenEventTypes", () => {
} as CompleteWorkflowsOnEventTypes,
],
});
prismaMock.$transaction.mockResolvedValue([{ id: 2 }]);
// Mock the event type that will be returned for existing users
const mockUpdatedEventType = {
id: 2,
userId: 4,
timeZone: "UTC",
teamId: 1,
autoTranslateDescriptionEnabled: false,
secondaryEmailId: null,
schedulingType: SchedulingType.MANAGED,
requiresBookerEmailVerification: false,
lockTimeZoneToggleOnBookingPage: false,
useEventTypeDestinationCalendarEmail: false,
workflows: [],
parentId: 1,
locations: [],
...evType,
};
prismaMock.eventType.update.mockResolvedValue(mockUpdatedEventType);
await updateChildrenEventTypes({
eventTypeId: 1,
oldEventType: { children: [{ userId: 4 }], team: { name: "" } },
@@ -430,11 +451,7 @@ describe("handleChildrenEventTypes", () => {
parentId: 1,
userId: 5,
users: {
connect: [
{
id: 5,
},
],
connect: [{ id: 5 }],
},
workflows: {
create: [{ workflowId: 11 }],