Skip to content

fix(frontend): prevent checkout render loops when discounts are disabled - #987

Merged
khaira777 merged 4 commits into
mainfrom
codex/fix-checkout-discounts-disabled
Oct 7, 2026
Merged

khaira777 merged 4 commits into
mainfrom
codex/fix-checkout-discounts-disabled

Conversation

@khaira777

@khaira777 khaira777 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix full-build schema test failure and prevent infinite render loop at checkout when discounts are disabled

What Changed

  • Reconcile discount drafts when the mode changes to none across Orders, payment, and prepaid checkout so checkout stays usable.
  • Add Playwright coverage for disabled-discount checkout, delayed settings updates, bill changes, existing discounts, and enabled discount modes.
  • Update the schema upgrade assertion and migration docs to use the current MIGRATIONS registry instead of a pinned version or count.

Risk Assessment

✅ Low: The changes are scoped to discount-mode reconciliation across checkout surfaces, the latest-schema assertion, and behavioral E2E coverage; I found no remaining reachable defect.

Testing

Installed locked dependencies locally, built the backend and frontend, drove all six focused browser scenarios and the database migration integration test, and captured the live checkout UI; temporary build and browser files were removed and the worktree is clean.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Staff opens checkout with discounts disabled and can settle the full undiscounted balance. ✅ pass live Playwright: orders checkout with discounts disabled opens a payable screen instead of the recovery boundary; checkout screenshot
Staff opens a discount draft before settings resolve; the disabled mode removes the draft without a render loop or discount submission, and checkout remains payable. ✅ pass live Playwright: a late disabled-discount response drops an open checkout draft and still settles
Staff updates a bill while discounts remain disabled; checkout stays usable and settles. ✅ pass live Playwright: a bill update while discounts stay disabled keeps the checkout payable
Staff disables discounts after a bill already has a discount; the existing discount is preserved and the bill settles at its authoritative total. ✅ pass live Playwright: an already discounted bill settles on its authoritative total when discounts are disabled
Staff checks out with percentage, flat, and both discount modes; only allowed discount types appear and an allowed flat discount can be applied. ✅ pass live Playwright: enabled discount modes still expose only their allowed types
Staff places a prepaid order with discounts disabled; it completes at the undiscounted amount. ✅ pass live Playwright: prepaid checkout settles an undiscounted bill when discounts are disabled
A fresh database and a pre-v104 database upgrade reach the latest registered schema and retain the expected add-on inventory structure. ✅ pass live npm run test:addon-inventory-db

Live checkout with discounts disabled

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ frontend/e2e/checkout-discounts-disabled.spec.ts:146 - expect.poll(...).toBe('') succeeds on its first check while the error list is empty, so it does not observe the advertised 3-second window. The calls at lines 229, 285, 337, 382, 423, and 478 can therefore miss later errors. The waiter at line 221 can resolve on the Orders page’s settings request before the payment modal’s request, and the flat-mode apply path at lines 431-442 submits without waiting for the modal’s settings response, allowing it to use the initial percentage type. Wait for the modal’s settings response before assertions or submission, and use a real bounded observation if retaining the error-log check.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Staff opens checkout with discounts disabled and can settle the full undiscounted balance. ✅ pass live Playwright: orders checkout with discounts disabled opens a payable screen instead of the recovery boundary; checkout screenshot
Staff opens a discount draft before settings resolve; the disabled mode removes the draft without a render loop or discount submission, and checkout remains payable. ✅ pass live Playwright: a late disabled-discount response drops an open checkout draft and still settles
Staff updates a bill while discounts remain disabled; checkout stays usable and settles. ✅ pass live Playwright: a bill update while discounts stay disabled keeps the checkout payable
Staff disables discounts after a bill already has a discount; the existing discount is preserved and the bill settles at its authoritative total. ✅ pass live Playwright: an already discounted bill settles on its authoritative total when discounts are disabled
Staff checks out with percentage, flat, and both discount modes; only allowed discount types appear and an allowed flat discount can be applied. ✅ pass live Playwright: enabled discount modes still expose only their allowed types
Staff places a prepaid order with discounts disabled; it completes at the undiscounted amount. ✅ pass live Playwright: prepaid checkout settles an undiscounted bill when discounts are disabled
A fresh database and a pre-v104 database upgrade reach the latest registered schema and retain the expected add-on inventory structure. ✅ pass live npm run test:addon-inventory-db
  • npm ci in the repository root and frontend/
  • npm run build && npm run build:frontend
  • PLAYWRIGHT_BROWSERS_PATH=<worktree>/.cache/playwright npx playwright install chromium
  • PLAYWRIGHT_BROWSERS_PATH=&lt;worktree&gt;/.cache/playwright npx playwright test --config=playwright.config.ts --project=chromium e2e/checkout-discounts-disabled.spec.ts from frontend/
  • npm run test:addon-inventory-db
  • Manual Playwright checkout on the isolated E2E server: selected Cash, confirmed Pay ฿64.20 and no discount control, and captured the screenshot.
  • git diff --check for the target commit range
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ Lint checks could not complete: ESLint and markdownlint-cli2 are missing from the worktree. Dependency-free documentation link, index, and policy checks passed.
✅ **Push** - passed

✅ No issues found.

Summary by CodeRabbit

  • Bug Fixes

    • Checkout remains usable when discounts are disabled, with discount controls and draft values cleared appropriately.
    • Existing discounted bills retain their stored discount and total, while bills settled without discounts are calculated correctly.
    • Discount options now match the configured mode across checkout flows.
  • Tests

    • Added coverage for disabled discounts, changing settings, and payment flows.
  • Documentation

    • Migration documentation now reflects the current registry without fixed counts or version details.

…e path

The pre-v104 upgrade assertion pinned schema v104, which #986 made stale by
adding migrations v105 and v106. Full Cross-Platform Matrix runs `npm test`,
whose pretest chain includes this suite, so main went red on Linux and macOS
while the shard-based PR CI never executed it.
Mode `none` forbids every discount type, so the render-phase normalization in
PaymentModal, PrepaidCheckoutModal, and the Orders discount dialog kept
rescheduling an update that could never be satisfied. React aborted after 25
renders and checkout showed the recovery boundary instead of a payment screen.

Entering `none` now clears the draft once against the tracked previous mode, so
the render phase stays finite, while enabled modes keep normalizing an
incompatible draft type.
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a4b208c3-d378-47b8-b056-7f8d092157bd
📥 Commits

Reviewing files that changed from the base of the PR and between ed2a036 and e15aac0.

📒 Files selected for processing (6)
  • docs/architecture/data-and-migrations.md
  • frontend/e2e/checkout-discounts-disabled.spec.ts
  • frontend/src/app/(dashboard)/orders/page.tsx
  • frontend/src/components/pos/PaymentModal.tsx
  • frontend/src/components/pos/PrepaidCheckoutModal.tsx
  • tests/addon-inventory-db.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


Walkthrough

Checkout components now reconcile discount drafts when discount mode changes, with end-to-end coverage for disabled-discount payment flows. Migration documentation and an upgrade test now derive version references from the migration registry.

Changes

Discount-disabled checkout

Layer / File(s) Summary
Discount state reconciliation
frontend/src/app/(dashboard)/orders/page.tsx, frontend/src/components/pos/PaymentModal.tsx, frontend/src/components/pos/PrepaidCheckoutModal.tsx
When the discount mode changes to none, checkout components clear relevant discount draft and approval state. For other modes, they continue to normalize disallowed discount types.
Orders checkout scenarios
frontend/e2e/checkout-discounts-disabled.spec.ts
End-to-end tests cover disabled-discount checkout, delayed settings responses, bill updates, existing discounts, and permitted discount types.
Prepaid checkout coverage
frontend/e2e/checkout-discounts-disabled.spec.ts
An end-to-end test checks prepaid checkout with discounts disabled and verifies the resulting order, bill, and payment state.

Migration registry references

Layer / File(s) Summary
Registry version references
docs/architecture/data-and-migrations.md, tests/addon-inventory-db.test.ts
The documentation identifies the migration registry as the source for current counts, versions, and migration names. The upgrade test compares the current schema version with the last registered migration.

Priority: ➖ Normal

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to e15aa

No confirmed issue currently prevents merge; the Orders draft reopening behavior remains unverified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 5 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately describes the primary frontend fix for checkout render loops when discounts are disabled.
Description check ✅ Passed The description is detailed and on-topic. It explains the intent, changes, risk, testing commands and results, migration impact, user-visible behavior, and screenshot evidence. It does not use all tem…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 5 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

frontend/e2e/checkout-discounts-disabled.spec.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

frontend/src/app/(dashboard)/orders/page.tsx

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

frontend/src/components/pos/PaymentModal.tsx

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

  • 1 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@khaira777
khaira777 merged commit b7f6c22 into main Oct 7, 2026
16 checks passed
@khaira777
khaira777 deleted the codex/fix-checkout-discounts-disabled branch October 7, 2026 16:02
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