Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add test for booking cancelled webhook #14940

Merged

Conversation

Amit91848
Copy link
Contributor

@Amit91848 Amit91848 commented May 8, 2024

What does this PR do?

Fixes #14886
Fixes CAL-3641

Type of change

  • Tests (Unit/Integration/E2E or any other test)

How should this be tested?

yarn test cancel.test.ts

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

Copy link

vercel bot commented May 8, 2024

@Amit91848 is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot requested a review from a team May 8, 2024 10:56
@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label May 8, 2024
Copy link
Contributor

github-actions bot commented May 8, 2024

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link.

@github-actions github-actions bot added automated-tests area: unit tests, e2e tests, playwright webhooks area: webhooks, callback, webhook payload labels May 8, 2024
Copy link

graphite-app bot commented May 8, 2024

Graphite Automations

"Add community label" took an action on this PR • (05/08/24)

1 label was added to this PR based on Keith Williams's automation.

"Add consumer team as reviewer" took an action on this PR • (05/08/24)

1 reviewer was added to this PR based on Keith Williams's automation.

Copy link
Contributor

github-actions bot commented May 8, 2024

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@keithwillcode keithwillcode added this to the v4.1 milestone May 8, 2024
@dosubot dosubot bot modified the milestones: v4.1, v4.2 May 9, 2024
Copy link
Contributor

@Udit-takkar Udit-takkar left a comment

Choose a reason for hiding this comment

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

@Amit91848 we wanted unit tests here. one of the contributor created this function expectBookingCancelledWebhookToHaveBeenFired (https://github.com/calcom/cal.com/pull/14745/files) which we can use.

@Udit-takkar Udit-takkar added this to the v4.1 milestone May 10, 2024
@github-actions github-actions bot added the Medium priority Created by Linear-GitHub Sync label May 13, 2024
@@ -164,6 +164,121 @@ test.describe("BOOKING_CREATED", async () => {
});
});

test.describe("BOOKING_CANCELLED", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove this E2E test?

Comment on lines 97 to 98
const createdBooking = await handleNewBooking(mockCreateBookingReq);

Copy link
Contributor

Choose a reason for hiding this comment

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

you need to add some assertions to make sure booking was created successfully.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can check other unit test

@Amit91848
Copy link
Contributor Author

Unit test passes but there is an error thrown when cancelling scheduled jobs

When booking is created scheduledJobs is null
https://github.com/Amit91848/cal.com/blob/87a260eba39c059f2626d6257a0d2dcb79f05986/packages/features/bookings/lib/handleNewBooking/test/cancel.test.ts#L101

Screenshot 2024-05-14 at 12 37 10 PM

But when you fetch it from database it converts to an object?? Like here
https://github.com/Amit91848/cal.com/blob/87a260eba39c059f2626d6257a0d2dcb79f05986/packages/features/bookings/lib/handleNewBooking/test/cancel.test.ts#L112-L118
Screenshot 2024-05-14 at 12 38 28 PM

@dosubot dosubot bot modified the milestones: v4.1, v4.2 May 15, 2024
@Udit-takkar Udit-takkar self-assigned this May 17, 2024
Comment on lines +123 to +128
organizer: {
id: organizer.id,
username: organizer.username,
email: organizer.email,
name: organizer.name,
timeZone: organizer.timeZone,
Copy link
Contributor

Choose a reason for hiding this comment

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

I added this new test instead.

we just wanted to test booking cancelled so i just created a dummy booking using getScenarioData and also you skipped checking if organizer id is passed in payload which is the main thing that needs to be checked

@Udit-takkar Udit-takkar enabled auto-merge (squash) May 17, 2024 13:38
@Udit-takkar Udit-takkar merged commit ae4e0f8 into calcom:main May 17, 2024
32 of 39 checks passed
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 community Created by Linear-GitHub Sync Medium priority Created by Linear-GitHub Sync webhooks area: webhooks, callback, webhook payload
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-3641] Add test for booking cancelled webhook
3 participants