Skip to content

fix(promos): guard stored discount percent - #87

Open
aiirvizionz wants to merge 1 commit into
profullstack:masterfrom
aiirvizionz:clientkit/safe-stored-promo-percent
Open

fix(promos): guard stored discount percent#87
aiirvizionz wants to merge 1 commit into
profullstack:masterfrom
aiirvizionz:clientkit/safe-stored-promo-percent

Conversation

@aiirvizionz

Copy link
Copy Markdown
Contributor

Summary

  • reuse the existing promo percent normalizer when reading stored promo rows
  • keep checkout quotes and admin lists from surfacing NaN when stored promo data is malformed
  • add regression coverage for numeric stored values and decimal-string fallback

Bug

quotePromo computed percentOff with Number(row.percent_off ?? 100) and clamped it directly. If a promo row is malformed or manually edited to a non-numeric value, Math.max(1, NaN) produces NaN, which makes finalUsd become NaN during checkout quoting instead of falling back to a safe discount value.

Validation

  • node "node_modules/.pnpm/vitest@3.2.7_@types+node@22.20.0_tsx@4.23.0/node_modules/vitest/vitest.mjs" run apps/web/lib/promo-form.test.ts passed 4 tests

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