Skip to content

fix: refactor pycon registration validation logic and add unit tests - #138

Merged
seangaaab merged 1 commit into
stagefrom
fix/update-register-validation-logic
Oct 3, 2026
Merged

seangaaab merged 1 commit into
stagefrom
fix/update-register-validation-logic

Conversation

@seangaaab

Copy link
Copy Markdown

Support Zero Price Registrations on Paid Events & Refactor PyCon Registration Flow

Context

When event.paidEvent is True, the backend previously required a verified transactionId unless a 100% discount code was applied. If an event offered a free ticket tier (price = 0) or temporarily waived ticket fees, the frontend skipped the payment gateway (total === 0), but the backend rejected the registration with a 400 Bad Request due to a missing/unverified transaction ID.

Key Changes

  • Server-Side Price Calculation: Dynamically computes the effective total (base_price * (1 - discount)) + sprint_day_price. If the total is <= 0, the registration is marked as free and payment transaction verification is bypassed.
  • Reordered Step Execution: Moved ticket type lookup and capacity checks before the payment check to resolve the base ticket price upfront.
  • Add-on Protection: Ensures registrations with a free base ticket but a paid Sprint Day (sprintDayPrice > 0) still require payment transaction verification.
  • Code Health & Maintainability:
    • Extracted clean private helpers: __resolve_ticket_type_and_price, __resolve_discount, and __validate_payment_transaction.
    • Removed a redundant duplicate database query for existing registrations.
  • Testing: Added unit test suite in tests/test_pycon_registration_usecase.py covering 0-dollar tickets, paid tickets, add-on sprint day fees, and 100% discounts.

@ASPactores ASPactores left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lgtm

@seangaaab
seangaaab merged commit 9dab5dd into stage Oct 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants