Skip to content

Comments

test: [Booking Refactor - Preparation - 1] Make all test files import handleNewBooking from a single place#23741

Merged
hariombalhara merged 1 commit intomainfrom
handleNewBooking-tests-import-from-getNewBookingHandler
Sep 11, 2025
Merged

test: [Booking Refactor - Preparation - 1] Make all test files import handleNewBooking from a single place#23741
hariombalhara merged 1 commit intomainfrom
handleNewBooking-tests-import-from-getNewBookingHandler

Conversation

@hariombalhara
Copy link
Member

@hariombalhara hariombalhara commented Sep 10, 2025

What does this PR do?

Replace scattered handleNewBooking imports in test files to use getNewBookingHandler import. It allows us to easily replace the logic to start using RegularBookingService in the followup PR here - #23156

These are changes in just the test files which are verified automatically by the unit tests and thus is safe to merge.

@vercel
Copy link

vercel bot commented Sep 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 11, 2025 4:11am
cal-eu Ignored Ignored Sep 11, 2025 4:11am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 10, 2025

Walkthrough

Introduces a new test helper module packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts that exports getNewBookingHandler(), which returns a function that dynamically imports the handleNewBooking default export at call time. Updates numerous test files under packages/features/bookings/lib/handleNewBooking/test/ (including booking-limits, complex-schedules, date-overrides, delegation-credential, dynamic-group-booking, fresh-booking, reschedule, round-robin-no-hosts, workflow-notifications, and team-bookings subfolder tests) and packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts to replace direct dynamic imports with const handleNewBooking = getNewBookingHandler(). Test logic and assertions remain unchanged; changes are constrained to test setup.

Possibly related PRs

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely summarizes the primary change — consolidating test imports so all test files import handleNewBooking from a single place — and matches the provided file-level summaries showing tests switching to getNewBookingHandler; it is a single sentence, specific, and free of extraneous noise.
Description Check ✅ Passed The PR description directly describes consolidating handleNewBooking imports in test files to use getNewBookingHandler and states the changes are test-only and safe to merge; this aligns with the provided raw_summary showing widespread replacement of dynamic imports with the new test helper across multiple test files.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch handleNewBooking-tests-import-from-getNewBookingHandler

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "All handleNewBooking tests import from getNewBookingHandler". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

Copy link
Member Author

hariombalhara commented Sep 10, 2025

@hariombalhara hariombalhara changed the title All handleNewBooking tests import from getNewBookingHandler test: [Booking Refactor - Preparation - 1] Make all test files import handleNewBooking from a single place Sep 10, 2025
@hariombalhara hariombalhara force-pushed the handleNewBooking-tests-import-from-getNewBookingHandler branch 2 times, most recently from 4cfef3f to e7905d5 Compare September 10, 2025 12:12
@hariombalhara hariombalhara changed the base branch from move-modules-moduleLoader-pattern-for-RegularBookingService to graphite-base/23741 September 10, 2025 12:13
@hariombalhara hariombalhara force-pushed the handleNewBooking-tests-import-from-getNewBookingHandler branch from e7905d5 to e04fc84 Compare September 10, 2025 12:13
@hariombalhara hariombalhara changed the base branch from graphite-base/23741 to main September 10, 2025 12:13
@hariombalhara hariombalhara marked this pull request as ready for review September 10, 2025 12:13
@hariombalhara hariombalhara requested a review from a team as a code owner September 10, 2025 12:13
@graphite-app graphite-app bot requested a review from a team September 10, 2025 12:13
@dosubot dosubot bot added automated-tests area: unit tests, e2e tests, playwright bookings area: bookings, availability, timezones, double booking labels Sep 10, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (10)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)

1-8: Type the helper and cache the imported handler (optional).

Gives safer call sites and avoids repeated import() plumbing while preserving lazy load.

+type HandleNewBooking = typeof import("@calcom/features/bookings/lib/handleNewBooking").default;
+
+let cached: HandleNewBooking | null = null;
-async function handler(input: any) {
-  const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
-  return handleNewBooking(input);
-}
+async function handler(input: Parameters<HandleNewBooking>[0]) {
+  if (!cached) {
+    cached = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
+  }
+  return cached(input);
+}
 
-export function getNewBookingHandler() {
-  return handler;
-}
+export function getNewBookingHandler(): HandleNewBooking {
+  return handler as HandleNewBooking;
+}
packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts (1)

37-37: Align mock path with actual import in handleSeats.test.ts
Change vi.mock("./handleSeats") to vi.mock("../handleSeats") so the mocked module matches the import * as handleSeatsModule from "../handleSeats" at line 29.

packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts (1)

46-46: Ensure helper returns a fresh, correctly-typed handler.

Calling getNewBookingHandler() per test is good. Please verify the helper lazily imports the module (not a cached top-level reference) and preserves the production signature (some tests pass extra args like userId). If it currently returns a pre-imported handler, consider this tweak in getNewBookingHandler.ts:

-export function getNewBookingHandler() {
-  return handler;
-}
+type HandleNewBooking = typeof import("@calcom/features/bookings/lib/handleNewBooking").default;
+export function getNewBookingHandler(): HandleNewBooking {
+  // Lazy import to avoid stale state leakage and keep types intact
+  return (async (...args: Parameters<HandleNewBooking>) => {
+    const mod = await import("@calcom/features/bookings/lib/handleNewBooking");
+    return (mod.default as HandleNewBooking)(...args);
+  }) as HandleNewBooking;
+}

Also applies to: 142-142, 222-222

packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts (1)

48-48: Wide adoption of getNewBookingHandler — approved; watch for handler arg shape.

Many tests here pass extra properties (e.g., userId). Please ensure getNewBookingHandler’s return type matches the production default export so such calls remain type-safe.

Also applies to: 70-70, 309-309, 515-515, 703-703, 909-909, 1152-1152, 1393-1393, 1603-1603, 1861-1861, 2013-2013, 2173-2173, 2321-2321, 2521-2521, 2678-2678, 2837-2837, 2966-2966

packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts (1)

25-25: Round-robin tests updated to shared helper — approved.

Import path "../getNewBookingHandler" is correct from this subfolder; repeated per-test retrieval is fine for isolation.

Also applies to: 33-33, 214-214, 375-375, 506-506, 654-654, 785-785

packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts (2)

56-58: Initialize handler in beforeEach to remove duplication below

Create the handler once per test via beforeEach; it reduces repetition and keeps handler lifecycle explicit.

Apply:

- beforeEach(() => {
-   resetTestSMS();
- });
+ let handleNewBooking: ReturnType<typeof getNewBookingHandler>;
+ beforeEach(() => {
+   resetTestSMS();
+   handleNewBooking = getNewBookingHandler();
+ });

68-68: Remove per-test handler declarations after moving to beforeEach

Once the handler is initialized in beforeEach, drop these local declarations.

Example for the first occurrence:

- const handleNewBooking = getNewBookingHandler();

Repeat for the other listed lines.

Also applies to: 250-250, 376-376, 549-549, 782-782, 1019-1019, 1219-1219, 1334-1334, 1514-1514, 1715-1715, 1908-1908, 2102-2102

packages/features/bookings/lib/handleNewBooking/test/handleNewRecurringBooking.test.ts (3)

156-163: Avoid magic “-1” userId

Consider a named constant to document intent (anonymous user) and prevent drift across tests.

+ const ANONYMOUS_USER_ID = -1;
  const recurringBookingService = getRecurringBookingService();
  const createdBookings = await recurringBookingService.createBooking({
    bookingData: bookingDataArray,
    bookingMeta: {
-     userId: -1, // Simulating anonymous user like in the API test
+     userId: ANONYMOUS_USER_ID, // Simulating anonymous user like in the API test
    },
  });

376-385: Fix rejects assertion style for async calls (when unskipping)

Use expect(promise).rejects…, not expect(async () => …).rejects…, which treats the function as a value and can yield false positives.

- await expect(
-   async () =>
-     await recurringBookingService.createBooking({
-       bookingData: bookingDataArray,
-       bookingMeta: { userId: -1 },
-     })
- ).rejects.toThrow(ErrorCode.NoAvailableUsersFound);
+ await expect(
+   recurringBookingService.createBooking({
+     bookingData: bookingDataArray,
+     bookingMeta: { userId: -1 },
+   })
+ ).rejects.toThrow(ErrorCode.NoAvailableUsersFound);

Also applies to: 551-559


40-40: Rename describe to match the new API surface (nit)

Since tests exercise RecurringBookingService, consider renaming for clarity.

- describe("handleNewRecurringBooking", () => {
+ describe("RecurringBookingService.createBooking", () => {
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2e96600 and e04fc84.

📒 Files selected for processing (16)
  • packages/features/bookings/lib/handleNewBooking/global-booking-limits.test.ts (5 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts (10 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/complex-schedules.test.ts (2 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts (3 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/delegation-credential.test.ts (7 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts (4 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts (36 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/handleNewRecurringBooking.test.ts (4 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts (17 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/round-robin-no-hosts.test.ts (3 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-reschedule-destination-calendar.test.ts (2 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts (13 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts (6 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/workflow-notifications.test.ts (7 hunks)
  • packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts (16 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/features/bookings/lib/handleNewBooking/test/round-robin-no-hosts.test.ts
  • packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts
  • packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/complex-schedules.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-reschedule-destination-calendar.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/delegation-credential.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/workflow-notifications.test.ts
  • packages/features/bookings/lib/handleNewBooking/global-booking-limits.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/handleNewRecurringBooking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/features/bookings/lib/handleNewBooking/test/round-robin-no-hosts.test.ts
  • packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts
  • packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/complex-schedules.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-reschedule-destination-calendar.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/delegation-credential.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/workflow-notifications.test.ts
  • packages/features/bookings/lib/handleNewBooking/global-booking-limits.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/handleNewRecurringBooking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/features/bookings/lib/handleNewBooking/test/round-robin-no-hosts.test.ts
  • packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts
  • packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/complex-schedules.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-reschedule-destination-calendar.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/delegation-credential.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/workflow-notifications.test.ts
  • packages/features/bookings/lib/handleNewBooking/global-booking-limits.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/handleNewRecurringBooking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: hariombalhara
PR: calcom/cal.com#23541
File: packages/features/bookings/lib/di/modules/RegularBookingServiceModule.ts:22-28
Timestamp: 2025-09-03T09:52:51.182Z
Learning: The IBookingServiceDependencies interface in packages/features/bookings/lib/handleNewBooking.ts contains 6 properties: cacheService, checkBookingAndDurationLimitsService, prismaClient, bookingRepository, featuresRepository, and checkBookingLimitsService. This interface is used by RegularBookingService and matches the depsMap structure in RegularBookingServiceModule.
📚 Learning: 2025-07-22T11:42:47.623Z
Learnt from: CarinaWolli
PR: calcom/cal.com#22296
File: packages/lib/bookings/filterHostsBySameRoundRobinHost.ts:41-42
Timestamp: 2025-07-22T11:42:47.623Z
Learning: The filterHostsBySameRoundRobinHost function in packages/lib/bookings/filterHostsBySameRoundRobinHost.ts has a known limitation where it doesn't work correctly with fixed hosts or round robin groups. This is pre-existing technical debt that was already broken before the round robin groups feature. CarinaWolli has documented this in Linear issue CAL-6134 for future fix.

Applied to files:

  • packages/features/bookings/lib/handleNewBooking/test/round-robin-no-hosts.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts
📚 Learning: 2025-08-27T13:32:46.887Z
Learnt from: supalarry
PR: calcom/cal.com#23364
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/internal-to-api/internal-to-api.spec.ts:295-296
Timestamp: 2025-08-27T13:32:46.887Z
Learning: In calcom/cal.com, when transforming booking fields from internal to API format, tests in organizations-event-types.e2e-spec.ts already expect name field label and placeholder to be empty strings ("") rather than undefined. PR changes that set these to explicit empty strings are typically fixing implementation to match existing test expectations rather than breaking changes.

Applied to files:

  • packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-reschedule-destination-calendar.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/handleNewRecurringBooking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts
📚 Learning: 2025-09-03T09:52:51.182Z
Learnt from: hariombalhara
PR: calcom/cal.com#23541
File: packages/features/bookings/lib/di/modules/RegularBookingServiceModule.ts:22-28
Timestamp: 2025-09-03T09:52:51.182Z
Learning: The IBookingServiceDependencies interface in packages/features/bookings/lib/handleNewBooking.ts contains 6 properties: cacheService, checkBookingAndDurationLimitsService, prismaClient, bookingRepository, featuresRepository, and checkBookingLimitsService. This interface is used by RegularBookingService and matches the depsMap structure in RegularBookingServiceModule.

Applied to files:

  • packages/features/bookings/lib/handleNewBooking/test/handleNewRecurringBooking.test.ts
🧬 Code graph analysis (16)
packages/features/bookings/lib/handleNewBooking/test/round-robin-no-hosts.test.ts (1)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts (2)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts (2)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/complex-schedules.test.ts (2)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts (2)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-reschedule-destination-calendar.test.ts (2)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts (2)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts (1)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts (2)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/delegation-credential.test.ts (1)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/workflow-notifications.test.ts (1)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/global-booking-limits.test.ts (1)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts (2)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
packages/features/bookings/lib/handleNewBooking/test/handleNewRecurringBooking.test.ts (1)
packages/lib/di/bookings/containers/RecurringBookingService.container.ts (1)
  • getRecurringBookingService (27-29)
packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts (1)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: team-labels
🔇 Additional comments (17)
packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-reschedule-destination-calendar.test.ts (2)

27-28: Consolidated handler import looks good.

Switching to the shared helper improves consistency across tests.


51-51: LGTM: use of getNewBookingHandler() per-test.

Keeps lazy load semantics without duplicating dynamic import code.

packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts (1)

31-32: Refactor to shared handler helper is correct.

Import path and per-test retrieval are consistent with the PR objective.

Also applies to: 53-53, 215-215

packages/features/bookings/lib/handleNewBooking/test/complex-schedules.test.ts (1)

31-32: LGTM: centralized handler retrieval.

Keeps tests uniform and avoids repeated dynamic import boilerplate.

Also applies to: 53-53

packages/features/bookings/lib/handleNewBooking/test/round-robin-no-hosts.test.ts (1)

21-22: Consistent switch to getNewBookingHandler().

Paths and usage look correct.

Also applies to: 31-31, 145-145

packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts (2)

28-28: Importing the shared handler helper from handleNewBooking tests is correct.

The relative path is right from handleSeats/test to handleNewBooking/test.


37-37: Per-test handler acquisition: OK.

All call sites correctly switch to const handleNewBooking = getNewBookingHandler();.

Also applies to: 100-100, 245-245, 387-387, 515-515, 640-640, 749-749, 871-871, 1050-1050, 1253-1253, 1413-1413, 151-151, 171-171, 1846-1846, 2005-2005, 2121-2121, 2388-2388

packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts (1)

33-33: LGTM: migrated all usages to the shared helper.

Consistent with intent; lazy loading preserved.

Also applies to: 55-55, 173-173, 302-302, 383-383, 472-472, 566-566, 632-632, 701-701, 776-776

packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts (2)

66-66: Single-source import adopted.

Matches the consolidation goal.


86-86: All call sites now use getNewBookingHandler(): good.

Uniform, readable, and maintains previous behavior.

Also applies to: 268-268, 427-427, 583-583, 704-704, 869-869, 1027-1027, 1119-1119, 1203-1203, 1297-1297, 1384-1384, 1478-1478, 1538-1538, 1624-1624, 1705-1705, 1776-1776, 1861-1861, 1945-1945, 2025-2025, 2123-2123, 2261-2261, 2386-2386, 2522-2522, 2653-2653, 2721-2721, 2846-2846, 3030-3030, 3207-3207, 3355-3355, 3473-3473, 3530-3530, 3593-3593, 3647-3647, 3710-3710, 3771-3771

packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts (1)

32-32: Centralized handler import — LGTM.

Switching to a single source of truth via getNewBookingHandler improves consistency across tests.

packages/features/bookings/lib/handleNewBooking/test/workflow-notifications.test.ts (1)

29-29: Refactor to shared handler helper — looks good.

Imports and per-test retrieval via getNewBookingHandler are consistent and readable. Confirm the helper’s type preserves optional args (e.g., userId) passed by some tests.

Also applies to: 54-54, 165-165, 258-258, 406-406, 545-545, 658-658

packages/features/bookings/lib/handleNewBooking/global-booking-limits.test.ts (1)

20-20: Import path and usage are correct.

Using "./test/getNewBookingHandler" from the parent directory is appropriate; handler retrieval per test aligns with the PR goal.

Also applies to: 73-73, 211-211, 299-299, 431-431

packages/features/bookings/lib/handleNewBooking/test/delegation-credential.test.ts (1)

48-48: Consolidated handler acquisition — approved.

Pattern is consistent across tests and improves maintainability. No functional changes in assertions.

Also applies to: 166-166, 345-345, 521-521, 714-714, 883-883, 1036-1036

packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts (2)

46-47: Centralized handler import — LGTM

Importing from a single helper aligns with the PR objective and improves test consistency.


46-46: Stateless handler confirmed—no action required
getNewBookingHandler() always returns the same handler function, which merely delegates to the imported handleNewBooking implementation. All stateful dependencies are reset in each test via setupAndTeardown(), so there’s no residual state between tests.

packages/features/bookings/lib/handleNewBooking/test/handleNewRecurringBooking.test.ts (1)

26-27: Switch to DI container service — LGTM

Using getRecurringBookingService() improves realism and aligns tests with production wiring.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 10, 2025

E2E results are ready!

@hariombalhara hariombalhara force-pushed the handleNewBooking-tests-import-from-getNewBookingHandler branch from 89db3d7 to b9e818c Compare September 11, 2025 04:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts (3)

46-46: Defer handler acquisition until right before use to avoid premature module import vs. mocks.

If getNewBookingHandler() captures the real module at creation time, calling it this early could import before mockCalendar/scenario setup. Safer to move it immediately before the first invocation.

Apply within this test:

-        const handleNewBooking = getNewBookingHandler();
         // ...
-        const createdBooking = await handleNewBooking({
+        const handleNewBooking = getNewBookingHandler(); // moved near invocation
+        const createdBooking = await handleNewBooking({
           bookingData: mockBookingData,
         });

142-142: Same here: acquire handler just before the expect block.

Keeps import timing aligned with mocks/fixtures established above.

-          const handleNewBooking = getNewBookingHandler();
           // ...
-          await expect(
+          const handleNewBooking = getNewBookingHandler(); // moved closer to use
+          await expect(
             async () =>
               await handleNewBooking({
                 bookingData: mockBookingData,
               })
           ).rejects.toThrowError(ErrorCode.FixedHostsUnavailableForBooking);

222-222: Repeat: move handler acquisition closer to invocation.

Prevents any accidental early module initialization relative to test setup.

-          const handleNewBooking = getNewBookingHandler();
           // ...
-          await expect(
+          const handleNewBooking = getNewBookingHandler(); // moved closer to use
+          await expect(
             async () =>
               await handleNewBooking({
                 bookingData: mockBookingData,
               })
           ).rejects.toThrowError(ErrorCode.FixedHostsUnavailableForBooking);
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e04fc84 and b9e818c.

📒 Files selected for processing (15)
  • packages/features/bookings/lib/handleNewBooking/global-booking-limits.test.ts (5 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts (10 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/complex-schedules.test.ts (2 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts (3 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/delegation-credential.test.ts (7 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts (4 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts (36 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts (17 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/round-robin-no-hosts.test.ts (3 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-reschedule-destination-calendar.test.ts (2 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts (13 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts (6 hunks)
  • packages/features/bookings/lib/handleNewBooking/test/workflow-notifications.test.ts (7 hunks)
  • packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts (16 hunks)
🚧 Files skipped from review as they are similar to previous changes (14)
  • packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts
  • packages/features/bookings/lib/handleNewBooking/global-booking-limits.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/workflow-notifications.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/delegation-credential.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/round-robin-no-hosts.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/round-robin.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/complex-schedules.test.ts
  • packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-reschedule-destination-calendar.test.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts
🧬 Code graph analysis (1)
packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts (2)
packages/platform/libraries/index.ts (1)
  • handleNewBooking (45-45)
packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts (1)
  • getNewBookingHandler (6-8)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Install dependencies / Yarn install & cache
🔇 Additional comments (1)
packages/features/bookings/lib/handleNewBooking/test/dynamic-group-booking.test.ts (1)

32-32: Approve — centralized test import verified. Repo-wide search found no tests that directly import or dynamic-import the handleNewBooking default. All handler usage goes through getNewBookingHandler (packages/features/bookings/lib/handleNewBooking/test/getNewBookingHandler.ts dynamically imports the module). A couple tests still import named helpers from ../../handleNewBooking (buildEventForTeamEventType, buildDryRunBooking) — expected for unit testing.

Comment on lines +2 to +3
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
return handleNewBooking(input);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In followup PR. I replace this logic to get the RegularBookingService from the container

Copy link
Member

@alishaz-polymath alishaz-polymath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hariombalhara hariombalhara enabled auto-merge (squash) September 11, 2025 07:33
@hariombalhara hariombalhara merged commit 92005b9 into main Sep 11, 2025
69 of 71 checks passed
@hariombalhara hariombalhara deleted the handleNewBooking-tests-import-from-getNewBookingHandler branch September 11, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-tests area: unit tests, e2e tests, playwright bookings area: bookings, availability, timezones, double booking core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO ready-for-e2e size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants