perf: handleChildrenEventType link old event-type with workflows using create/findMany (#25653)

* perf: link old event-type with workflows using create/findMany

* test: fix handleChildrenEventTypes test mocks for new workflow linking implementation

Update test to match the new implementation that uses findMany + createMany
instead of upsert for linking workflows to old event types.

- Add mock for workflowsOnEventTypes.findMany to return empty array
- Update assertion from upsert to findMany + createMany

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-12-08 13:11:21 +02:00
1 parent 4e68bcb021
commit a6578fdcd2
2 files changed
+61 -30

No files matched your search

@@ -553,6 +553,10 @@ describe("handleChildrenEventTypes", () => {
updatedAt: new Date(),
});
// Mock workflowsOnEventTypes.findMany to return empty array (no existing workflow links for old event types)
// This is needed because the new implementation uses findMany + createMany instead of upsert
prismaMock.workflowsOnEventTypes.findMany.mockResolvedValue([]);
await updateChildrenEventTypes({
eventTypeId: 1,
oldEventType: { children: [{ userId: 4 }], team: { name: "" } },
@@ -627,19 +631,23 @@ describe("handleChildrenEventTypes", () => {
},
},
});
// Verify workflowsOnEventTypes.upsert was called for existing users' workflows
expect(prismaMock.workflowsOnEventTypes.upsert).toHaveBeenCalledWith({
create: {
eventTypeId: 2,
workflowId: 11,
},
update: {},
// Verify workflowsOnEventTypes.findMany was called to check existing relationships
expect(prismaMock.workflowsOnEventTypes.findMany).toHaveBeenCalledWith({
where: {
workflowId_eventTypeId: {
eventTypeId: 2,
workflowId: 11,
},
workflowId: { in: [11] },
eventTypeId: { in: [2] },
},
select: {
workflowId: true,
eventTypeId: true,
},
});
// Verify workflowsOnEventTypes.createMany was called for existing users' workflows
// Since findMany returned empty array, all workflow-eventType pairs should be created
expect(prismaMock.workflowsOnEventTypes.createMany).toHaveBeenCalledWith({
data: [{ eventTypeId: 2, workflowId: 11 }],
skipDuplicates: false,
});
});
});