Skip to content

Commit 3418a25

Browse files
eunjae-leedevin-ai-integration[bot]keithwillcode
authored
fix: seed script command (calcom#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 <hey@eunjae.dev> * fix: use correct path resolution in seed-all script Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: simplify database verification step in test workflow Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * 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 <hey@eunjae.dev> * 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 <keithwillcode@gmail.com>
1 parent 89cc175 commit 3418a25

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

apps/api/v1/test/lib/bookings/_get.integration-test.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createMocks } from "node-mocks-http";
44
import { describe, expect, it, beforeAll } from "vitest";
55
import { ZodError } from "zod";
66

7-
import prisma from "@calcom/prisma";
7+
import { prisma } from "@calcom/prisma";
88

99
import { handler } from "../../../pages/api/bookings/_get";
1010

@@ -217,6 +217,22 @@ describe("GET /api/bookings", async () => {
217217
describe("Expand feature to add relational data in return payload", () => {
218218
it("Returns only team data when expand=team is set", async () => {
219219
const adminUser = await prisma.user.findFirstOrThrow({ where: { email: "owner1-acme@example.com" } });
220+
221+
// Find a team booking and a non-team booking from seed data
222+
const team1 = await prisma.team.findFirst({ where: { slug: "team1" } });
223+
const teamEventType = await prisma.eventType.findFirst({
224+
where: { teamId: team1?.id },
225+
include: { bookings: true },
226+
});
227+
const teamBooking = teamEventType?.bookings[0];
228+
229+
const nonTeamBooking = await prisma.booking.findFirst({
230+
where: {
231+
eventType: { teamId: null },
232+
userId: proUser.id,
233+
},
234+
});
235+
220236
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
221237
method: "GET",
222238
query: {
@@ -229,14 +245,23 @@ describe("GET /api/bookings", async () => {
229245
req.isOrganizationOwnerOrAdmin = true;
230246

231247
const responseData = await handler(req);
232-
console.log("bookings=>", responseData.bookings);
233-
responseData.bookings.forEach((booking) => {
234-
if (booking.id === 31) expect(booking.eventType?.team?.slug).toBe("team1");
235-
if (booking.id === 19) {
236-
// The team field can be either null or undefined due to nullish() in the schema
237-
expect(booking.eventType?.team === null || booking.eventType?.team === undefined).toBe(true);
248+
249+
// Verify team booking has team data
250+
if (teamBooking) {
251+
const returnedTeamBooking = responseData.bookings.find((b) => b.id === teamBooking.id);
252+
expect(returnedTeamBooking?.eventType?.team?.slug).toBe("team1");
253+
}
254+
255+
// Verify non-team booking has null/undefined team
256+
if (nonTeamBooking) {
257+
const returnedNonTeamBooking = responseData.bookings.find((b) => b.id === nonTeamBooking.id);
258+
if (returnedNonTeamBooking) {
259+
expect(
260+
returnedNonTeamBooking.eventType?.team === null ||
261+
returnedNonTeamBooking.eventType?.team === undefined
262+
).toBe(true);
238263
}
239-
});
264+
}
240265
});
241266
});
242267

packages/features/insights/services/InsightsBookingService.integration-test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,11 @@ describe("InsightsBookingService Integration Tests", () => {
724724
});
725725

726726
const baseConditions = await service.getBaseConditions();
727-
const results = await prisma.$queryRaw<{ id: number }[]>`
727+
const query = Prisma.sql`
728728
SELECT id FROM "BookingTimeStatusDenormalized"
729729
WHERE ${baseConditions}
730730
`;
731+
const results = await prisma.$queryRaw<{ id: number }[]>(query);
731732

732733
// Should return the user booking since it matches both conditions
733734
expect(results).toEqual([

packages/prisma/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"post-install": "yarn generate-schemas",
1919
"seed-app-store": "ts-node --transpile-only ../../scripts/seed-app-store.ts",
2020
"delete-app": "ts-node --transpile-only ./delete-app.ts",
21+
"seed-basic": "ts-node --transpile-only ../../scripts/seed.ts",
2122
"seed-insights": "ts-node --transpile-only ../../scripts/seed-insights.ts",
2223
"seed-pbac": "ts-node --transpile-only ../../scripts/seed-pbac-organization.ts"
2324
},
@@ -45,6 +46,6 @@
4546
"zod-utils.ts"
4647
],
4748
"prisma": {
48-
"seed": "ts-node --transpile-only ../../scripts/seed.ts"
49+
"seed": "yarn seed-basic"
4950
}
5051
}

0 commit comments

Comments
 (0)