Skip to content

Add direct tests for payment pricing - #1900

Merged
stefan-burke merged 1 commit into
mainfrom
split/payment-pricing-tests
Jul 23, 2026
Merged

Add direct tests for payment pricing#1900
stefan-burke merged 1 commit into
mainfrom
split/payment-pricing-tests

Conversation

@stefan-burke

@stefan-burke stefan-burke commented Jul 23, 2026

Copy link
Copy Markdown
Member

What changed

Added a standalone test file for payment pricing (test/features/api/payment-processing/pricing.test.ts) that calls the real production code directly — no server, no Stripe, no database.

The production file src/features/api/payment-processing/pricing.ts got one small change: checkoutIntentForSession now reuses the existing contactFields helper (from src/shared/db/attendees/pii.ts) instead of copying the contact fields by hand. This is the same helper the final split branch uses, and it stays behaviour-preserving because:

  • the helper returns the same five fields (address, email, name, phone, special_instructions) the old inline copy did;
  • contactFields already has current production callers (committed-entries.ts, attendees/create.ts, attendees/pii.ts);
  • no refund behavior, orderLineTotal, or staged-checkout types were touched.

Why

The pricing module is the last gate before a signed order is honoured: it re-prices the order and decides whether today's prices still match what the buyer was charged. That logic (contact fields, signed totals, item totals, deposits, modifiers, pay-more bounds, and the failure paths that refund when a price drifted mid-checkout) deserves a fast, focused unit suite instead of only being exercised through full webhook integration tests.

What the tests cover

  • Contact fields: every signed field (name, email, phone, address, special instructions) is copied onto the checkout intent, including package group, day count, and reservation data when present — and omitted when absent.
  • Package vs group edge: a k: "p" line becomes a packageGroupId, a k: "g" line does not.
  • Item totals (orderLineTotal): split deposit lines are summed, modifier extras are excluded.
  • Per-item totals (paidByItem): split lines for the same item add up; two booking paths for one listing stay separate.
  • Signed totals (paidPricingRefund): an unchanged fixed-price order passes; a deposit is accepted while the full item price is still checked; an unchanged modifier total passes; a changed re-derived total refunds with the exact detail string.
  • Failure boundaries: a package member no longer in its package fails closed; fixed-price mismatches both below and above; pay-more boundaries (min and max) pass and out-of-range values refund; a free item whose current price turned positive refunds.
  • Mutation testing: 100% kill rate (34/34 killed, one ?? → || fallback recorded as a proven equivalent).

Verification

  • deno task test:files test/features/api/payment-processing/pricing.test.ts — 21 tests pass
  • deno task test:quality-audit — no findings in the new file
  • deno task mutation src/features/api/payment-processing/pricing.ts test/features/api/payment-processing/pricing.test.ts — 100% (34 killed, 1 suppressed equivalent)
  • deno task precommit — green

Notes

  • Production code changed (one helper reuse in pricing.ts), behaviour-preserving.
  • No refund behavior, orderLineTotal, or staged types were changed.
  • No PR created — this IS the PR.

Summary by CodeRabbit

  • Improvements

    • Checkout intents now consistently include available contact information and signed pricing details.
    • Payment totals are calculated more reliably across deposits, modifiers, packages, and multiple charged lines.
    • Refund validation now better handles pricing changes and prevents refunds when finalized totals no longer match.
  • Tests

    • Expanded coverage for checkout details, payment aggregation, package pricing, deposits, modifiers, and refund scenarios.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1afeefe3-eacd-4a30-a4db-17540acf275e

📥 Commits

Reviewing files that changed from the base of the PR and between e6d32a7 and e002000.

📒 Files selected for processing (3)
  • scripts/mutation/equivalent-mutants.txt
  • src/features/api/payment-processing/pricing.ts
  • test/features/api/payment-processing/pricing.test.ts

📝 Walkthrough

Walkthrough

checkoutIntentForSession now uses shared contact-field extraction, while payment totals and refund validation receive extensive test coverage. A mutation-equivalence entry documents the charged-total fallback behavior.

Changes

Payment pricing behavior

Layer / File(s) Summary
Checkout intent contact propagation
src/features/api/payment-processing/pricing.ts, test/features/api/payment-processing/pricing.test.ts
Checkout intent construction spreads shared contact fields, and tests cover contact serialization, signed pricing, optional fields, and group-edge handling.
Payment totals and refund validation
test/features/api/payment-processing/pricing.test.ts, scripts/mutation/equivalent-mutants.txt
Tests cover charged-line aggregation, package and standalone totals, accepted and rejected refund scenarios, and a documented equivalent `?? →

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding direct tests for payment pricing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split/payment-pricing-tests
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch split/payment-pricing-tests

Comment @coderabbitai help to get the list of available commands.

@stefan-burke
stefan-burke added this pull request to the merge queue Jul 23, 2026
Merged via the queue into main with commit 6f8e6b1 Jul 23, 2026
3 checks passed
@stefan-burke
stefan-burke deleted the split/payment-pricing-tests branch July 23, 2026 18:03
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.

1 participant