WOOTAX-25 - Add regression test for zero-amount tax calculations - #2966
Merged
Conversation
A subscription switch, or a free-trial subscription whose initial cart total is $0, produces a TaxJar response with a zeroed top-level rate while the real per-jurisdiction rates remain in breakdown.line_items. The itemized rate builder (get_itemized_tax_rates) already persists those real rates and never writes the zeroed top-level rate, so the historical "tax rate set to 0.0000%" / "no tax on renewal" behaviour no longer occurs. This locks that in: the test feeds the exact zero-amount response captured in WOOTAX-18 into get_itemized_tax_rates and asserts the real per-jurisdiction rates (city 1.5%, county 1.25%, state 4.225%) are persisted and the combined rate is 6.975%, not 0. Verified the test fails if the builder is reverted to writing the top-level rate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Abdalsalaam
force-pushed
the
fix/WOOTAX-25
branch
from
June 18, 2026 10:51
48cfc37 to
95cc3a9
Compare
Abdalsalaam
marked this pull request as ready for review
June 18, 2026 10:53
bartech
approved these changes
Jun 19, 2026
bartech
left a comment
Collaborator
There was a problem hiding this comment.
✅ LGTM — approving.
The regression test correctly locks in the zero-amount tax fix (WOOTAX-25): I traced the path and it genuinely fails if production regresses to writing the top-level shared tax_rate = 0, and CI is green across the PHP/WP/WC matrix.
A couple of optional, non-blocking hardening ideas:
- Consider also asserting
$result['tax_rate']is0.0— that's the field actually carrying the zeroed shared rate, and it's currently unasserted (the other half of the contract). - A one-line comment on why
assertCount( 4, … )is load-bearing would help future readers.
Nice, well-scoped test.
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.
Description
When a subscription is switched, or when a free-trial subscription's initial cart total is
$0, TaxJar returns a response whose top-levelrate(andamount_to_collect) is0becausetaxable_amountis0— while the real per-jurisdiction rates are still present insidebreakdown.line_items. Historically the rate builder wrote the zeroed top-level rate into the shared WooCommerce tax-rate row, which set an existing rate to0.0000%(WOOTAX-18) and left subscription renewals with no tax (WOOTAX-25).The current
get_itemized_tax_rates()already persists the real per-jurisdiction rates frombreakdown.line_itemsand never writes the zeroed top-level rate (fixed by the itemized-tax-rate refactor). This PR is a test-only change that locks that behaviour in with a regression test, so the zeroing-out cannot silently come back.The test feeds the exact zero-amount response captured in WOOTAX-18 into
get_itemized_tax_rates()and asserts the real per-jurisdiction rates (city 1.5%, county 1.25%, state 4.225%) are persisted and the combined rate is 6.975%, never 0. It was verified to fail if the builder is reverted to writing the top-level rate.Related issue(s)
Linear: WOOTAX-25 (same root cause as WOOTAX-18 / #2826).
Steps to reproduce & screenshots/GIFs
Original bug (no longer reproducible on trunk):
Verifying the guard:
./vendor/bin/phpunit --filter test_zero_amount_response_persists_real_itemized_rates— passes on trunk.get_itemized_tax_rates()to write the top-level rate — the test fails, confirming it catches the regression.N/A - test-only change, no visual changes.
Checklist
changelog.txtentry added — N/A: test-only change, no user-facing impact.readme.txtentry added — N/A: test-only change, no user-facing impact.