Skip to content

Commit 86b9aa5

Browse files
authored
fix: exclude AWAITING_HOST from seed-insights random status selection (calcom#25414)
## What does this PR do? Fixes a bug in the seed-insights script where `AWAITING_HOST` status was randomly assigned to bookings along with a `userId`, which violates the correct behavior of instant meetings. **Problem:** - The seed script randomly picked from all 5 booking statuses (including `AWAITING_HOST`) - When `AWAITING_HOST` was selected, the script still assigned a `userId` - Real instant meetings with `AWAITING_HOST` status should have `userId = NULL` until a host joins - This created incorrect test data that doesn't match production behavior **Solution:** - Filter out `AWAITING_HOST` from `BookingStatus` values using `Object.values(BookingStatus).filter()` - This approach is more maintainable than listing valid statuses explicitly - if new statuses are added in the future, they will automatically be included - Moved `validStatusesForSeed` to module level so it's calculated once at load time instead of on every shuffle call - Added comments explaining why this status requires special handling ## Mandatory Tasks (DO NOT REMOVE) - [x] I have self-reviewed the code (A decent size PR without self-review might be rejected). - [x] I have updated the developer docs in /docs if this PR makes changes that would require a [documentation change](https://cal.com/docs). N/A - seed script only. - [x] I confirm automated tests are in place that prove my fix is effective or that my feature works. N/A - this is a seed script for test data generation. ## How should this be tested? 1. Run the seed script: `yarn seed-insights` 2. Verify no `AWAITING_HOST` bookings are created with a `userId`: ```sql SELECT COUNT(*) FROM "Booking" WHERE status = 'awaiting_host' AND "userId" IS NOT NULL AND "createdAt" > NOW() - INTERVAL '1 day'; -- Should return 0 for newly seeded data ``` 3. Verify other statuses are still generated: ```sql SELECT status, COUNT(*) FROM "Booking" WHERE "createdAt" > NOW() - INTERVAL '1 day' GROUP BY status; -- Should show ACCEPTED, PENDING, CANCELLED, REJECTED (but not AWAITING_HOST) ``` ## Checklist - [x] I have read the [contributing guide](https://github.com/calcom/cal.com/blob/main/CONTRIBUTING.md) - [x] My code follows the style guidelines of this project - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have checked if my changes generate no new warnings --- > **Link to Devin run:** https://app.devin.ai/sessions/08f634e7210d415982d71c8f687b4468 > **Requested by:** eunjae@cal.com (@eunjae-lee)
1 parent b94f107 commit 86b9aa5

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

scripts/seed-insights.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ import { BookingStatus, AssignmentReasonEnum } from "@calcom/prisma/enums";
99

1010
import { seedAttributes, seedRoutingFormResponses, seedRoutingForms } from "./seed-utils";
1111

12+
// Valid statuses for seed data
13+
// AWAITING_HOST is excluded because it requires special handling:
14+
// - userId must be NULL (not assigned until host joins)
15+
// - Requires InstantMeetingToken to be created
16+
// - Only used for actual instant meetings via InstantBookingCreateService
17+
const VALID_STATUSES_FOR_SEED = Object.values(BookingStatus).filter(
18+
(status) => status !== BookingStatus.AWAITING_HOST
19+
);
20+
21+
function getRandomBookingStatus() {
22+
const randomStatusIndex = Math.floor(Math.random() * VALID_STATUSES_FOR_SEED.length);
23+
return VALID_STATUSES_FOR_SEED[randomStatusIndex];
24+
}
25+
1226
function getRandomRatingFeedback() {
1327
const feedbacks = [
1428
"Great chat!",
@@ -51,11 +65,7 @@ const shuffle = (
5165
booking.endTime = endTime.toISOString();
5266
booking.createdAt = startTime.subtract(1, "day").toISOString();
5367

54-
// Pick a random status
55-
const randomStatusIndex = Math.floor(Math.random() * Object.keys(BookingStatus).length);
56-
const statusKey = Object.keys(BookingStatus)[randomStatusIndex];
57-
58-
booking.status = BookingStatus[statusKey];
68+
booking.status = getRandomBookingStatus();
5969

6070
booking.rescheduled = Math.random() > 0.5 && Math.random() > 0.5 && Math.random() > 0.5;
6171

0 commit comments

Comments
 (0)