Skip to content

Commit d6b17b7

Browse files
joeauyeungdevin-ai-integration[bot]alishaz-polymathemrysal
authored
test: add comprehensive unit tests for no-show fee payment functions (calcom#23626)
* feat: add time-based cancellation fees for no-show fee events - Add configurable time threshold (minutes/hours/days) for cancellation fees - Show warnings during booking submission and cancellation - Automatically charge fees when bookings cancelled within threshold - Exempt organizer/admin cancellations from fees - Extend existing no-show fee infrastructure Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: replace any type with proper type guards for metadata - Use Record<string, unknown> instead of any for metadata type - Add proper type assertions for nested metadata properties - Maintain type safety while avoiding ESLint no-explicit-any warning Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: handle JsonValue type compatibility in shouldChargeCancellationFee - Add proper type guard for metadata JsonValue from Prisma - Ensure metadata is object before casting to Record<string, unknown> - Fixes TypeScript error on line 390 in handleCancelBooking.ts Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * Refactor Devin changes to Stripe options * Undo Devin changes to advanced tab * Add translations * Pass props to CancelBooking * Display no show fee charge for attendee * WIP * Anstract shouldChargeNoSHowCancellationFee * Abstract `handleNoShowFee` * Add to * Refactor `chargeCard.handler` * Remove Devin code * Type fix in `shouldChargeNoShowCancellationFee` * Create `processNoSHowFeeOnCancellation` * Process no show fee on cancellation * Type fix * Skip processing no show fee if organizer or admin is cancelling * Add translation * Dynamically get and in * Remove unused translations * Undo dev change * Refactor logic * Type fix * remove any * revert WEBAPP_URL_FOR_OAUTH * Clean up console.log remnants * test: add comprehensive tests for time-based cancellation fees - Add unit tests for shouldChargeCancellationFee function with time thresholds and role exemptions - Add handleCancelBooking integration tests for organizer/team admin exemptions - Add handleCancelBooking test for attendee fee charging within time threshold - Add UI component tests for cancellation fee warning display - Add E2E test for cancellation fee warning during booking flow All 23 new tests pass successfully, covering: - Time-based logic with different units (minutes, hours, days) - Role-based exemptions (organizer, team admin vs regular attendee) - Payment charging integration with HOLD payment option - UI warning display during booking submission and cancellation - Edge cases like invalid metadata and past bookings Fixed lint issues: - Replaced 'any' types with proper Record<string, unknown> - Fixed Playwright test.skip() usage with ESLint disable comments Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * test: add comprehensive tests for time-based cancellation fees - Add unit tests for shouldChargeCancellationFee function with time thresholds and role exemptions - Add handleCancelBooking integration tests for organizer/team admin exemptions - Add handleCancelBooking test for attendee fee charging within time threshold - Add UI component tests for cancellation fee warning display - Add E2E test for cancellation fee warning during booking flow All unit and integration tests pass successfully. E2E test implementation complete. Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * test: add comprehensive tests for time-based cancellation fees - Add unit tests for shouldChargeCancellationFee function with time thresholds and role exemptions - Add handleCancelBooking integration tests for organizer/team admin exemptions - Add handleCancelBooking test for attendee fee charging within time threshold - Add UI component tests for cancellation fee warning display - Add E2E test for cancellation fee warning during booking flow - Fix TypeScript issues and prettier formatting - All tests follow existing Cal.com patterns and pass locally Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * test: add comprehensive unit and E2E tests for time-based cancellation fees - Add unit tests for shouldChargeCancellationFee function with time thresholds and role exemptions - Add handleCancelBooking integration tests for organizer/team admin exemptions and attendee fee charging - Add UI component tests for cancellation fee warning display in CancelBooking component - Add E2E test for cancellation fee warning during booking flow - Fix TypeScript errors in CancelBooking.tsx with proper type annotations - All tests follow existing Cal.com patterns and use proper mocking/test utilities Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * Revert dev change * Add missing translation * Remove Devin code * Revert Devin changes * test: fix attendee cancellation test logic and ensure comprehensive test coverage - Fix userId in attendee cancellation test to properly test fee charging - Ensure all test files follow Cal.com patterns with proper mocking - Add comprehensive coverage for time thresholds, role exemptions, and UI warnings - All tests pass locally with proper timezone handling Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * Fix tests * test: add comprehensive unit tests for no-show fee payment functions - Add unit tests for handleNoShowFee.ts covering successful scenarios, error handling, and edge cases - Add unit tests for processNoShowFeeOnCancellation.ts covering cancellation logic and payment conditions - Tests include proper mocking of dependencies and comprehensive coverage of all code paths - All tests pass with TZ=UTC yarn test and type checking passes Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * Don't block cancel flow for failed payment processing * Await single attendee getTranslation in `handleNoShowFee` * Add missing data * Undo old strings * Type fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Co-authored-by: Alex van Andel <me@alexvanandel.com>
1 parent c42e803 commit d6b17b7

5 files changed

Lines changed: 993 additions & 28 deletions

File tree

packages/features/bookings/lib/handleCancelBooking.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,24 @@ async function handler(input: CancelBookingInput) {
456456
updatedBookings.push(updatedBooking);
457457

458458
if (bookingToDelete.payment.some((payment) => payment.paymentOption === "ON_BOOKING")) {
459-
await processPaymentRefund({
460-
booking: bookingToDelete,
461-
teamId,
462-
});
459+
try {
460+
await processPaymentRefund({
461+
booking: bookingToDelete,
462+
teamId,
463+
});
464+
} catch (error) {
465+
log.error(`Error processing payment refund for booking ${bookingToDelete.uid}:`, error);
466+
}
463467
} else if (bookingToDelete.payment.some((payment) => payment.paymentOption === "HOLD")) {
464-
await processNoShowFeeOnCancellation({
465-
booking: bookingToDelete,
466-
payments: bookingToDelete.payment,
467-
cancelledByUserId: userId,
468-
});
468+
try {
469+
await processNoShowFeeOnCancellation({
470+
booking: bookingToDelete,
471+
payments: bookingToDelete.payment,
472+
cancelledByUserId: userId,
473+
});
474+
} catch (error) {
475+
log.error(`Error processing no-show fee for booking ${bookingToDelete.uid}:`, error);
476+
}
469477
}
470478
}
471479

0 commit comments

Comments
 (0)