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

feat: booking no show webhook #15502

Merged
merged 20 commits into from
Jun 27, 2024
Merged

Conversation

zomars
Copy link
Member

@zomars zomars commented Jun 19, 2024

What does this PR do?

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected)
  • I have added a Docs issue here if this PR makes changes that would require a documentation change
  • I have added or modified automated tests that prove my fix is effective or that my feature works (PRs might be rejected if logical changes are not properly tested)

How should this be tested?

  • Set up a webhook for no-shows
  • Change the no-show on a booking

Signed-off-by: zomars <[email protected]>
Copy link

linear bot commented Jun 19, 2024

Copy link
Contributor

github-actions bot commented Jun 19, 2024

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:

Unknown release type "WIP" found in pull request title "WIP: booking no show webhook". 

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

@github-actions github-actions bot added the ❗️ migrations contains migration files label Jun 19, 2024
@keithwillcode keithwillcode added core area: core, team members only foundation labels Jun 19, 2024
Copy link

vercel bot commented Jun 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2024 7:46pm
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Jun 27, 2024 7:46pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Jun 27, 2024 7:46pm

Signed-off-by: zomars <[email protected]>
@github-actions github-actions bot added High priority Created by Linear-GitHub Sync webhooks area: webhooks, callback, webhook payload ✨ feature New feature or request labels Jun 19, 2024
Signed-off-by: zomars <[email protected]>
@zomars zomars requested a review from a team June 19, 2024 23:14
@zomars zomars changed the title WIP: booking no show webhook feat: booking no show webhook Jun 19, 2024
@zomars zomars marked this pull request as ready for review June 19, 2024 23:14
@dosubot dosubot bot added the bookings area: bookings, availability, timezones, double booking label Jun 19, 2024
@dosubot dosubot bot added this to the v4.2 milestone Jun 19, 2024
Copy link
Member Author

@zomars zomars left a comment

Choose a reason for hiding this comment

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

Self review done

Comment on lines 98 to 114
await webhookReceiver.waitForRequestCount(1);
const [request] = webhookReceiver.requestList;
const body = request.body;
// remove dynamic properties that differs depending on where you run the tests
const dynamic = "[redacted/dynamic]";
// @ts-expect-error we are modifying the object
body.createdAt = dynamic;
expect(body).toMatchObject({
triggerEvent: "BOOKING_NO_SHOW_UPDATED",
createdAt: "[redacted/dynamic]",
payload: {
message: "x_marked_as_no_show",
attendees: [{ email: "[email protected]", noShow: true, utcOffset: null }],
bookingUid: bookingWhereFirstUserIsOrganizer?.uid,
},
});
webhookReceiver.close();
Copy link
Member Author

Choose a reason for hiding this comment

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

Decided to add the test in here instead of webhooks to avoid repeating the whole logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Extracted this reused logic into a fixture.

Copy link
Member Author

Choose a reason for hiding this comment

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

New webhooks fixture

Copy link
Member Author

Choose a reason for hiding this comment

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

This file is mostly refactor using the new fixture.


const log = logger.getSubLogger({ prefix: ["[WebhookService] "] });

/** This is a WIP. With minimal methods until the API matures and stabilizes */
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a POC to simplify handling webhooks in future code.

Comment on lines +66 to +81
const booking = await prisma.booking.findUnique({
where: { uid: bookingUid },
select: {
eventType: {
select: {
id: true,
teamId: true,
userId: true,
},
},
},
});
const orgId = await getOrgIdFromMemberOrTeamId({
memberId: booking?.eventType?.userId,
teamId: booking?.eventType?.teamId,
});
Copy link
Member Author

Choose a reason for hiding this comment

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

These are required payloads for Webhooks service. Would like to simplify even more.

"success"
);
onSuccess: async (data) => {
showToast(t(data.message, { x: name || email }), "success");
Copy link
Member Author

Choose a reason for hiding this comment

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

We get the message from server instead

export type WebhookDataType = CalendarEvent &
// BookingNoShowUpdatedPayload & // This breaks all other webhooks
Copy link
Member Author

Choose a reason for hiding this comment

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

To be fixed

Comment on lines 89 to 90
// @ts-expect-error payload is too booking specific, we need to refactor this
await webhooks.sendPayload({ ...payload, bookingUid });
Copy link
Member Author

Choose a reason for hiding this comment

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

Added explainer here.

@keithwillcode keithwillcode added this pull request to the merge queue Jun 26, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 26, 2024
@keithwillcode keithwillcode added this pull request to the merge queue Jun 27, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 27, 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.

@zomars E2E test "on submitting user form, triggers user webhook" is failing locally because of createReceiver (in createWebhookPageFixture).

Udit-takkar
Udit-takkar previously approved these changes Jun 27, 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.

Fixed the test. Re approving the PR

@Udit-takkar Udit-takkar added this pull request to the merge queue Jun 27, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 27, 2024
@Udit-takkar Udit-takkar added this pull request to the merge queue Jun 27, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 27, 2024
@zomars zomars added this pull request to the merge queue Jun 27, 2024
Merged via the queue into main with commit 3948b8d Jun 27, 2024
34 of 35 checks passed
@zomars zomars deleted the zomars/cal-3945-no-show-webhook-event branch June 27, 2024 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bookings area: bookings, availability, timezones, double booking core area: core, team members only ✨ feature New feature or request foundation High priority Created by Linear-GitHub Sync ❗️ migrations contains migration files ready-for-e2e webhooks area: webhooks, callback, webhook payload
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-3945] No-show webhook event
5 participants