Testing web applications

How to test discounts, coupons and price rounding in an online store

A customer enters a coupon, changes the quantity and sees a different total at payment from the one in the cart. Errors like this occur when rules that work correctly on their own are combined. Testing an online store therefore needs to cover the calculation and how its result reaches the order. This approach is for store operators, developers and testers preparing new pricing rules or checking existing ones.

Decide what the store should calculate first

You cannot determine the expected price without agreed rules. A five-euro coupon might apply to the whole cart, selected products or the value remaining after an earlier discount. Shipping might count towards the minimum purchase value, or it might be excluded. The test must reflect a decision by the person responsible for the business rules.

Before preparing scenarios, record the order of discounts, permitted combinations, products excluded from the promotion and the amount used to assess the threshold. Define when the coupon becomes valid and expires. For an exact time, record the time zone and agree what happens to an order opened before the promotion ends but submitted afterwards.

Rounding needs the same attention. Specify the number of decimal places, rounding method and calculation step at which rounding should occur. Rounding each unit can produce a different result from rounding the whole line item. An appropriate specialist should define tax rules and document requirements. The tester then checks the approved specification.

A sample cart with a calculation you can check

The sample cart uses fictional final prices and agreed test rules. It does not prescribe tax rates or accounting procedures. Two units of product A cost €19.95 each, product B costs €12.50 and shipping costs €3.90. A sample 10% discount applies to both products. A €5.00 coupon is then deducted without reducing shipping. Amounts are rounded to cents, with exact halfway values rounded away from zero.

Step Calculation Expected amount
Products before discount 2 × 19.95 + 12.50 €52.40
Percentage discount 52.40 × 0.10 €5.24
Products after discount 52.40 − 5.24 €47.16
Products after coupon 47.16 − 5.00 €42.16
Total including shipping 42.16 + 3.90 €46.06

If the store followed different rules and deducted the coupon before the percentage discount, it would produce €46.56 including shipping. The €0.50 difference exposes an error in the order of operations. Do not generate the expected value by calling the same function you are testing. Prepare an independent calculation and check it with the person who approved the rules.

Displaying two decimal places correctly is not enough for money. The Python decimal documentation explains that some decimal numbers have no exact representation in ordinary binary arithmetic. The module supports decimal calculations and explicit rounding choices. Use suitable decimal arithmetic or the smallest currency units in tests, depending on the application’s design.

A separate boundary example uses three units costing €0.05 each with a sample 10% discount. Rounding each discounted price of €0.045 to €0.05 gives a total of €0.15. Calculating across all units produces a subtotal of €0.135 and a rounded result of €0.14. These amounts follow different rules. The test should confirm the approved rule rather than accept either result arbitrarily.

Build a scenario matrix before writing tests

A matrix records inputs and expected behaviour. It separates cases that can fail for different reasons. For a sample coupon requiring at least €40.00 of eligible products after the percentage discount, the initial matrix could look like this:

Situation Test input What to check
Below the threshold €39.99 The coupon is rejected and the customer sees why
Exact boundary €40.00 The coupon applies under the agreed inclusive threshold
Above the threshold €40.01 The same rule applies without shifting the threshold
Excluded product Eligible and excluded products The excluded amount does not enter the qualifying subtotal
Reduced quantity Value drops below the threshold after coupon acceptance Recalculation removes eligibility and the displayed discount
Expiry Just before, exactly at and after expiry The agreed time boundary determines the result
Second coupon Two valid codes entered in succession Combination or rejection follows the specification
Discount exceeds the base Small cart and large fixed coupon The agreed restriction applies without a negative total

Add product identifiers, currency, pricing rule and required result to each row. “The price is correct” is not a useful expectation. Record an exact amount or an unambiguous reason for rejection. With multiple currencies, also check supported decimal places and the behaviour of a coupon intended for another currency.

Do not try every combination indiscriminately. Start with promotions in use, boundaries and cases that change eligibility. Add guest and signed-in customer variants if their rules differ. Single-use coupons need dedicated test accounts or resettable data so that the outcome does not depend on a previous run.

Check recalculation after changes to the cart

A valid coupon may become invalid when a product is removed or the delivery address changes. Open the cart, apply the discount and then change the quantity, shipping method and sign-in state in turn. After each change, check line prices, the product subtotal, discounts and the final total. Check the coupon message too, so that a green confirmation does not remain after the discount has been removed.

Try returning from payment to the cart and opening the cart in a second window. If the price list changes during the purchase, the specification must define the expectation. The store might preserve the price temporarily or ask the customer to confirm the new amount. The test checks the chosen process, including the information shown to the customer.

Supplement browser checks with direct calls to the application programming interface, or API, through which the application sends requests to the server. OWASP recommends checking business data integrity because even hidden or non-editable fields can be changed in a request. In a test environment, try changing the price, discount amount or rule identifier. The server should assess the result using its own trusted data.

Compare the cart, payment and saved order

One correct screen does not confirm the entire purchase. Create an order from the sample cart and compare the amount in the final confirmation with the request sent to the test payment gateway. After completion, check the saved order and any document the tested process generates. The currency must match as well.

For a one-cent difference, find where the calculations diverge. Possible causes include premature rounding, a different allocation of the coupon between line items or a separate calculation in an export. Allocating a fixed discount across products needs an agreed rule, including treatment of the remaining cent. Allocated discounts must add up to the total discount.

Check partial returns too. The expected refund depends on discount allocation rules and whether the return changes the original eligibility for the promotion or shipping. Use the original order as the basis. Recalculating a refund from today’s price list can produce a different amount. The payment process itself is covered in the article on payment gateway testing.

What to automate and what still needs manual assessment

Calculation cases belong mainly in fast pricing logic tests. API tests cover server behaviour and order persistence. Keep representative purchases, recalculation after cart changes and clear coupon rejection messages in browser tests. The article on API tests alongside interface tests explains this division.

Automation confirms agreement with specified rules. It does not decide whether a promotion makes business sense or whether its legal wording is correct. Have the customer-facing terms checked for new campaigns as well. Regularly verify that test rules match the active price list.

Prepare repeatable test data

Each automated case needs its own cart and a known coupon state. If another test consumes the same discount, the failure says little about pricing logic. When preparing data, record the rules assigned to the customer and the applicable price list. After the test, remove or reset only the data created for that run.

Check time boundaries using controllable clocks if the test environment supports them. Changing the server’s actual time can affect other tests. A defect report should include the initial cart, rule identifier, expected intermediate totals and actual result. These details help correct the calculation step involved. A screenshot of the wrong final price alone may not reveal the cause.

The final coupon use and concurrent orders

A single-use coupon also needs server-side checks. OWASP recommends testing function-use limits, including returning to a discount already used. Hiding a button or rejecting a second entry in one browser does not itself establish that the limit is enforced.

Prepare model coupon LAST-TEST with one use remaining and two eligible test carts. Submit two distinct orders as close together as possible in separate sessions. Distinguish this deliberate overlap from accidental data sharing with other tests. Check the expected limit against final order state and the coupon counter.

Sequence What to check under the agreed rules
Two orders compete for the final use When both purchases meet the other conditions, exactly one completed order receives the discount. The other does not silently confirm the original discounted price.
The same order is submitted again Repeating the same business operation does not consume another coupon use.
Payment fails after coupon reservation The reservation is released or retained according to an explicit product rule. A cancelled purchase is not mistaken for successful redemption.
The customer returns to entering a discount Stale form state does not bypass the limit enforced by the server.

Define when a use is reserved and when it is definitively consumed. Displaying a discount in the cart need not mean it has been finally allocated. After losing a response, first check the original order’s state rather than creating another under a different identifier.

Reverse request order and repeat. Several successful repetitions do not cover every possible timing. For an uncertain result, retain both order references, reservation state and processing order. If preparation of one cart failed, the result does not yet establish safe handling of concurrent requests.

Start with one promotion and exact expectations

Scenarios with exact expectations make it easier to find differences between calculation and display. The team can identify the step where the mismatch occurs instead of comparing the whole purchase manually. The same matrix can be used for the next campaign change.

Choose one discount and coupon combination currently in use. Record its rules, calculate the sample cart independently and check validity boundaries and the saved order total. Then extend the suite to other promotions and currencies.

Related topics

You might also be interested in

Catch bugs before they reach users

End-to-end tests of key scenarios can run automatically in CI/CD to catch bugs before they reach customers.