test: add totals integrity conformance module#64
Open
vishkaty wants to merge 1 commit into
Open
Conversation
Adds totals_test.py asserting the structural invariants of the totals[] array that the suite does not yet check (business_logic only checks arithmetic via existence lookups): - exactly one subtotal entry (totals.json contains/minContains/maxContains) - exactly one total entry - every entry carries both type and amount (total.json required) - additive well-known types (subtotal, fulfillment, tax, fee) are non-negative - subtractive well-known types (discount, items_discount) are negative Server-agnostic relative assertions read from the raw response, so any conformant business passes. Sub-line and per-entry-currency cases are omitted because the reference emits neither (they would be vacuous).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
totals_test.py, a conformance module for the structural invariants of thetotals[]array.business_logic_test.pychecks totals arithmetic (viaexistence lookups), but nothing asserts the cardinality and sign rules
the spec places on the array itself:
types/totals.json,types/total.json)test_single_subtotal_entrysubtotalentry (contains+minContains:1/maxContains:1)test_single_total_entrytotalentrytest_entries_have_type_and_amounttypeandamount(required)test_additive_entries_non_negativesubtotal,fulfillment,tax,fee) haveamount >= 0test_discount_entry_is_negativediscount,items_discount) haveamount < 0Why
Cardinality ("exactly one subtotal/total") and per-type sign are load-bearing
for any platform rendering a receipt, and the SDK model only enforces presence
of
type/amount, not these array-level invariants — so a server can regressthem and still pass. These cut across checkout, fulfillment, and discount
responses.
Design
Server-agnostic relative assertions read from the raw response (consistent with
the other modules).
test_entries_have_type_and_amountasserts on the raw wire(int
amount, non-emptytype) rather than the parsed model, so it catches whatthe model's lax coercion would mask. Sub-line (
lines[]) and per-entry-currencycases are intentionally omitted — the spec's totals
amountis a baresigned_amount(no currency), and the reference emits no sub-lines, so testingthem would be vacuous.
Verification
files, no regression).
pre-commit runclean (ruff, ruff-format, codespell).