From 3418a25a8511a57f7e399481484f27f411b7db53 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Tue, 28 Oct 2025 11:56:52 +0100 Subject: [PATCH] fix: seed script command (#24668) * feat: add seed-all command to run all seed scripts - Add seed-all command to packages/prisma/package.json - Create scripts/seed-all.ts to run seed.ts, seed-insights.ts, and seed-pbac-organization.ts in sequence - Update Prisma configuration to use seed-all as the default seed command - Add GitHub workflow to test seed-all command with a real PostgreSQL database Co-Authored-By: eunjae@cal.com * fix: use correct path resolution in seed-all script Co-Authored-By: eunjae@cal.com * fix: simplify database verification step in test workflow Co-Authored-By: eunjae@cal.com * refactor: use seed-all in cache-db action instead of separate workflow - Update cache-db action to use seed-all command - Remove test-seed-all.yml workflow as requested Co-Authored-By: eunjae@cal.com * fix error * change command name * fix integration tests * run basic seed by default --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Keith Williams --- .../lib/bookings/_get.integration-test.ts | 41 +++++++++++++++---- ...InsightsBookingService.integration-test.ts | 3 +- packages/prisma/package.json | 3 +- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/apps/api/v1/test/lib/bookings/_get.integration-test.ts b/apps/api/v1/test/lib/bookings/_get.integration-test.ts index c1ec9e7b29..2f2ba4f98e 100644 --- a/apps/api/v1/test/lib/bookings/_get.integration-test.ts +++ b/apps/api/v1/test/lib/bookings/_get.integration-test.ts @@ -4,7 +4,7 @@ import { createMocks } from "node-mocks-http"; import { describe, expect, it, beforeAll } from "vitest"; import { ZodError } from "zod"; -import prisma from "@calcom/prisma"; +import { prisma } from "@calcom/prisma"; import { handler } from "../../../pages/api/bookings/_get"; @@ -217,6 +217,22 @@ describe("GET /api/bookings", async () => { describe("Expand feature to add relational data in return payload", () => { it("Returns only team data when expand=team is set", async () => { const adminUser = await prisma.user.findFirstOrThrow({ where: { email: "owner1-acme@example.com" } }); + + // Find a team booking and a non-team booking from seed data + const team1 = await prisma.team.findFirst({ where: { slug: "team1" } }); + const teamEventType = await prisma.eventType.findFirst({ + where: { teamId: team1?.id }, + include: { bookings: true }, + }); + const teamBooking = teamEventType?.bookings[0]; + + const nonTeamBooking = await prisma.booking.findFirst({ + where: { + eventType: { teamId: null }, + userId: proUser.id, + }, + }); + const { req } = createMocks({ method: "GET", query: { @@ -229,14 +245,23 @@ describe("GET /api/bookings", async () => { req.isOrganizationOwnerOrAdmin = true; const responseData = await handler(req); - console.log("bookings=>", responseData.bookings); - responseData.bookings.forEach((booking) => { - if (booking.id === 31) expect(booking.eventType?.team?.slug).toBe("team1"); - if (booking.id === 19) { - // The team field can be either null or undefined due to nullish() in the schema - expect(booking.eventType?.team === null || booking.eventType?.team === undefined).toBe(true); + + // Verify team booking has team data + if (teamBooking) { + const returnedTeamBooking = responseData.bookings.find((b) => b.id === teamBooking.id); + expect(returnedTeamBooking?.eventType?.team?.slug).toBe("team1"); + } + + // Verify non-team booking has null/undefined team + if (nonTeamBooking) { + const returnedNonTeamBooking = responseData.bookings.find((b) => b.id === nonTeamBooking.id); + if (returnedNonTeamBooking) { + expect( + returnedNonTeamBooking.eventType?.team === null || + returnedNonTeamBooking.eventType?.team === undefined + ).toBe(true); } - }); + } }); }); diff --git a/packages/features/insights/services/InsightsBookingService.integration-test.ts b/packages/features/insights/services/InsightsBookingService.integration-test.ts index c0d0456601..55bb3bf6ea 100644 --- a/packages/features/insights/services/InsightsBookingService.integration-test.ts +++ b/packages/features/insights/services/InsightsBookingService.integration-test.ts @@ -724,10 +724,11 @@ describe("InsightsBookingService Integration Tests", () => { }); const baseConditions = await service.getBaseConditions(); - const results = await prisma.$queryRaw<{ id: number }[]>` + const query = Prisma.sql` SELECT id FROM "BookingTimeStatusDenormalized" WHERE ${baseConditions} `; + const results = await prisma.$queryRaw<{ id: number }[]>(query); // Should return the user booking since it matches both conditions expect(results).toEqual([ diff --git a/packages/prisma/package.json b/packages/prisma/package.json index c8254f5c4d..2ac0763853 100644 --- a/packages/prisma/package.json +++ b/packages/prisma/package.json @@ -18,6 +18,7 @@ "post-install": "yarn generate-schemas", "seed-app-store": "ts-node --transpile-only ../../scripts/seed-app-store.ts", "delete-app": "ts-node --transpile-only ./delete-app.ts", + "seed-basic": "ts-node --transpile-only ../../scripts/seed.ts", "seed-insights": "ts-node --transpile-only ../../scripts/seed-insights.ts", "seed-pbac": "ts-node --transpile-only ../../scripts/seed-pbac-organization.ts" }, @@ -45,6 +46,6 @@ "zod-utils.ts" ], "prisma": { - "seed": "ts-node --transpile-only ../../scripts/seed.ts" + "seed": "yarn seed-basic" } }