The storefront's cart library is producing numbers customers are complaining about. Support has logged a growing list: totals that don't add up, shipping charges that appear and disappear at the wrong moments, discount c…
The storefront's cart library is producing numbers customers are complaining about. Support has logged a growing list: totals that don't add up, shipping charges that appear and disappear at the wrong moments, discount codes that take off more than they should, or combine in ways finance never approved.
The library handles cart contents, discounts, tax and shipping. A test suite exists and encodes the intended behavior. Several of its tests are failing right now.
Make the failing behavior correct. The suite in tests/visible/ shows a good part of the expected behavior, but it is not exhaustive. Think about the rules behind the failures, not just the specific assertions.
Constraints:
src/ (classes, functions, exports) stays as it is.SAVE10/SAVE20/HALF take a percentage off; FLAT5/FLAT10 take a fixed amount off. A fixed discount can never exceed the order subtotal.Adapted from DevStudio-AI/autonomous-software-debugging-benchmarks (evaluation set), upstream license: none declared, internal use pending permission.
Visible test command
npx --no-install jest --ci --coverage=false --testPathPattern=tests/visibleThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
fix-cart-totals
Changes under src/ are evaluated.