Skip to content

feat(test) Charge tax config carryover - #4287

Merged
mark-vass-konghq merged 1 commit into
mainfrom
feat/test-charge-tax-config-carryover
May 7, 2026
Merged

mark-vass-konghq merged 1 commit into
mainfrom
feat/test-charge-tax-config-carryover

Conversation

@mark-vass-konghq

@mark-vass-konghq mark-vass-konghq commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

@coderabbitai

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for tax configuration propagation in billing: verifies TaxConfig (Behavior, TaxCodeID, and resolved Stripe code/backfill) across credit-then-invoice and standard invoice flows for flat-fee and usage-based lines, including behavior-only and nil-TaxConfig cases.
    • Added integration-style tests ensuring TaxConfig propagates to gathering and standard invoice lines, and that ledger handlers receive TaxConfig after DB round-trips.
    • Added tests validating TaxConfig propagation for credit grants across invoice-funded, external-funded, and promotional grant scenarios.

@mark-vass-konghq mark-vass-konghq self-assigned this May 5, 2026
@mark-vass-konghq mark-vass-konghq added the release-note/feature Release note: Exciting New Features label May 5, 2026
@mark-vass-konghq
mark-vass-konghq requested a review from a team as a code owner May 5, 2026 09:39
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/test-charge-tax-config-carryover branch from 20d98a9 to 9d94088 Compare May 5, 2026 09:40
@coderabbitai

coderabbitai Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds new integration-style tests and an import to verify TaxCode/TaxCodeConfig propagation (Behavior, TaxCodeID) and Stripe.Code backfill across charge invoice/gathering flows and credit-grant flows. All edits are test additions and test imports; no production code changes in the diff.

Changes

TaxConfig propagation tests (single cohesive cohort)

Layer / File(s) Summary
Test imports / setup
openmeter/billing/charges/service/taxcode_test.go, test/credits/creditgrant_test.go
Added imports to support creating TaxCode and TaxCodeConfig in tests (notably productcatalog, taxcode, app, and datetime in the charges test).
Data / fixtures
openmeter/billing/charges/service/taxcode_test.go, test/credits/creditgrant_test.go
Creates test TaxCode entities (some with Stripe mapping) and TaxCodeConfig values used by new tests.
Charge-side tests — gathering & settlement
openmeter/billing/charges/service/taxcode_test.go
Adds tests verifying propagation of full TaxCodeConfig (Behavior + TaxCodeID) to gathering invoice lines and standard invoice lines for flat-fee and usage-based CreditThenInvoice flows; verifies nil TaxConfig stays nil; verifies behavior-only TaxCodeConfig propagates only Behavior; asserts Stripe.Code is backfilled from TaxCode mapping where applicable. (Six new tests added.)
Credit-grant tests
test/credits/creditgrant_test.go
Adds tests for credit grants: invoice-funded grants propagate TaxConfig to standard invoice lines with Stripe.Code backfill; invoice-funded without TaxConfig yields nil invoice line TaxConfig; external and promotional grants persist Intent.TaxConfig on the grant. (Four new tests added.)
Test-only wiring / assertions
openmeter/billing/charges/service/taxcode_test.go, test/credits/creditgrant_test.go
Callbacks, handlers, and invoice flow steps in tests are wired to drive invoice creation, approval, payment triggers, and to capture handler inputs for assertion. All changes live in tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • tothandras
  • turip
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(test) Charge tax config carryover' clearly and concisely summarizes the main change: adding comprehensive tests that verify tax config propagation across charge types and settlement flows.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/test-charge-tax-config-carryover

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 892-1315: The file contains unresolved git conflict markers
(<<<<<<< HEAD, =======, >>>>>>>) surrounding several test functions such as
TestFlatFeeInvoiceSettlementPropagatesTaxConfigToGatheringLine,
TestFlatFeeInvoiceSettlementNilTaxConfigDoesNotPropagateToGatheringLine,
TestUsageBasedCreditThenInvoicePropagatesTaxConfigToGatheringLine, etc.; remove
the three marker lines and keep the intended test bodies (the content between
<<<<<<< HEAD and =======) so the file compiles—ensure no leftover markers remain
and run go vet/go test to verify.

In `@test/credits/creditgrant_test.go`:
- Line 273: The tests create a ctx using context.Background(), which prevents
test cancellation propagation; replace each occurrence of "ctx :=
context.Background()" in the newly added test functions with "ctx :=
s.T().Context()" so the test harness controls cancellation and lifecycle (look
for the ctx binding in the new tests in creditgrant_test.go and update the
assignment to use s.T().Context()).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a8f1b31d-4255-4a4c-b5f7-1d188354baa6

📥 Commits

Reviewing files that changed from the base of the PR and between 211d41c and 9d94088.

📒 Files selected for processing (2)
  • openmeter/billing/charges/service/taxcode_test.go
  • test/credits/creditgrant_test.go

Comment thread test/credits/creditgrant_test.go Resolved
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/test-charge-tax-config-carryover branch from 9d94088 to 2c60995 Compare May 5, 2026 09:55
@mark-vass-konghq mark-vass-konghq changed the title feat(text) Charge tax config carryover feat(test) Charge tax config carryover May 5, 2026
@mark-vass-konghq
mark-vass-konghq marked this pull request as ready for review May 5, 2026 11:40
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/add-tax_id-and-tax-behavior-to-charges-list-api branch from 211d41c to b7f8ad8 Compare May 5, 2026 13:21
Base automatically changed from feat/add-tax_id-and-tax-behavior-to-charges-list-api to main May 5, 2026 14:36
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/test-charge-tax-config-carryover branch from 2c60995 to c891cbb Compare May 5, 2026 15:03
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/test-charge-tax-config-carryover branch from c891cbb to d2c1156 Compare May 5, 2026 15:04
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/test-charge-tax-config-carryover branch from d2c1156 to 2ba4722 Compare May 5, 2026 15:06
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/test-charge-tax-config-carryover branch from 2ba4722 to 74be3f7 Compare May 5, 2026 15:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
openmeter/billing/charges/service/taxcode_test.go (1)

450-454: 💤 Low value

Consider adding Behavior assertions to standard invoice line checks for consistency

TestUsageBasedInvoiceSettlementPopulatesStripeCodeOnStandardInvoice asserts line.TaxConfig.Behavior on the standard invoice (line 1185), but the two analogous tests (TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLine at lines 450–454 and TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice at lines 757–761) skip it. A targeted regression on Behavior propagation to the standard invoice would slip through unnoticed in those two tests.

🔧 Optional additions to bring the assertions in line

For TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLine (after line 451):

 s.Require().NotNil(line.TaxConfig, "standard invoice line must have TaxConfig")
+s.Require().NotNil(line.TaxConfig.Behavior, "TaxBehavior must be on standard invoice line")
+s.Equal(productcatalog.ExclusiveTaxBehavior, *line.TaxConfig.Behavior)
 s.Require().NotNil(line.TaxConfig.TaxCodeID, "TaxCodeID must be on standard invoice line")

For TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice (after line 757):

 s.Require().NotNil(line.TaxConfig, "standard invoice line must have TaxConfig")
+s.Require().NotNil(line.TaxConfig.Behavior, "TaxBehavior must be on standard invoice line")
+s.Equal(productcatalog.ExclusiveTaxBehavior, *line.TaxConfig.Behavior)
 s.Require().NotNil(line.TaxConfig.TaxCodeID, "TaxCodeID must be on standard invoice line")

Also applies to: 757-761

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 450 - 454,
Add an assertion to check TaxConfig.Behavior on the standard invoice line in the
two tests that currently omit it: in
TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLine and
TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice, after the
existing TaxCode/Stripe assertions (the block referencing line.TaxConfig and
stripeCode), add a check asserting line.TaxConfig.Behavior equals the expected
behavior (use the test's TaxCode variable, e.g., tc.Behavior or the same
expectedBehavior value used in
TestUsageBasedInvoiceSettlementPopulatesStripeCodeOnStandardInvoice) to ensure
Behavior propagation is verified.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 450-454: Add an assertion to check TaxConfig.Behavior on the
standard invoice line in the two tests that currently omit it: in
TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLine and
TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice, after the
existing TaxCode/Stripe assertions (the block referencing line.TaxConfig and
stripeCode), add a check asserting line.TaxConfig.Behavior equals the expected
behavior (use the test's TaxCode variable, e.g., tc.Behavior or the same
expectedBehavior value used in
TestUsageBasedInvoiceSettlementPopulatesStripeCodeOnStandardInvoice) to ensure
Behavior propagation is verified.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 157aa966-5aeb-4cc5-ba80-977caaa7faf4

📥 Commits

Reviewing files that changed from the base of the PR and between 2c60995 and 74be3f7.

📒 Files selected for processing (2)
  • openmeter/billing/charges/service/taxcode_test.go
  • test/credits/creditgrant_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/credits/creditgrant_test.go

@mark-vass-konghq
mark-vass-konghq force-pushed the feat/test-charge-tax-config-carryover branch from 74be3f7 to d7e9f27 Compare May 6, 2026 07:32

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
openmeter/billing/charges/service/taxcode_test.go (2)

1196-1251: 💤 Low value

Behavior-only tests pull in SetupCustomInvoicing + manual approval but never invoice — could simplify.

Both TestFlatFeeBehaviorOnlyTaxConfigPropagatesToGatheringLine and TestUsageBasedBehaviorOnlyTaxConfigPropagatesToGatheringLine only assert on the gathering line and never advance to invoicing or payment, yet they wire up the custom invoicing app with billingtest.WithManualApproval(). The nil-tax-config sibling at lines 965–1011 uses the lighter InstallSandboxApp for the equivalent gathering-only assertion. Switching these two to the same sandbox setup would shave noise and make the intent clearer.

♻️ Example diff for the flat-fee variant
-	customInvoicing := s.SetupCustomInvoicing(ns)
-	_ = s.ProvisionBillingProfile(ctx, ns, customInvoicing.App.GetID(),
-		billingtest.WithManualApproval(),
-	)
+	sandboxApp := s.InstallSandboxApp(s.T(), ns)
+	_ = s.ProvisionBillingProfile(ctx, ns, sandboxApp.GetID())

Also applies to: 1256-1311

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 1196 - 1251,
The test TestFlatFeeBehaviorOnlyTaxConfigPropagatesToGatheringLine currently
calls SetupCustomInvoicing and ProvisionBillingProfile(...,
billingtest.WithManualApproval()) even though it only asserts gathering-line
behavior; change the setup to the lighter sandbox flow used by the
nil-tax-config sibling: replace SetupCustomInvoicing +
ProvisionBillingProfile(...) with InstallSandboxApp (or the equivalent sandbox
installer used in the other test) and remove the manual approval provisioning
call so the test only installs the sandbox app and proceeds to create the charge
and assert gathering line behavior; apply the same change to
TestUsageBasedBehaviorOnlyTaxConfigPropagatesToGatheringLine (the other test
referenced).

1139-1139: ⚡ Quick win

Consider explicit StoredAt for the late-arriving usage event.

AddSimpleEvent here injects usage at 2026-01-15 while the clock is still at 2025-12-01, and the event needs to be visible during finalization at servicePeriod.To. Per the repo guideline on usage-based finalization tests, using MockStreamingConnector with explicit StoredAt (or SetSimpleEvents) exercises the real stored-at cutoff logic instead of relying on the implicit default. Worth adopting here so the test stays robust if cutoff handling tightens.

The flat-fee TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice doesn't have this concern since it doesn't depend on streamed usage, so this is the only spot.

As per coding guidelines: "use MockStreamingConnector events with explicit StoredAt values (or SetSimpleEvents) to exercise real stored-at cutoff logic in finalization when modeling late-arriving or newly visible usage."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/billing/charges/service/taxcode_test.go` at line 1139, The test
injects a late-arriving usage event via
MockStreamingConnector.AddSimpleEvent(meterSlug, 5, time.Date(2026, 1, 15...))
while the test clock is at 2025-12-01, but it does not set an explicit StoredAt
so the stored-at cutoff logic isn't exercised; update the test
TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice (or the
surrounding test) to create the streamed event with an explicit StoredAt (or use
MockStreamingConnector.SetSimpleEvents) so the event's StoredAt is set to a
timestamp that makes it visible at finalization (servicePeriod.To) and thus
exercises the real stored-at cutoff logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 1196-1251: The test
TestFlatFeeBehaviorOnlyTaxConfigPropagatesToGatheringLine currently calls
SetupCustomInvoicing and ProvisionBillingProfile(...,
billingtest.WithManualApproval()) even though it only asserts gathering-line
behavior; change the setup to the lighter sandbox flow used by the
nil-tax-config sibling: replace SetupCustomInvoicing +
ProvisionBillingProfile(...) with InstallSandboxApp (or the equivalent sandbox
installer used in the other test) and remove the manual approval provisioning
call so the test only installs the sandbox app and proceeds to create the charge
and assert gathering line behavior; apply the same change to
TestUsageBasedBehaviorOnlyTaxConfigPropagatesToGatheringLine (the other test
referenced).
- Line 1139: The test injects a late-arriving usage event via
MockStreamingConnector.AddSimpleEvent(meterSlug, 5, time.Date(2026, 1, 15...))
while the test clock is at 2025-12-01, but it does not set an explicit StoredAt
so the stored-at cutoff logic isn't exercised; update the test
TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice (or the
surrounding test) to create the streamed event with an explicit StoredAt (or use
MockStreamingConnector.SetSimpleEvents) so the event's StoredAt is set to a
timestamp that makes it visible at finalization (servicePeriod.To) and thus
exercises the real stored-at cutoff logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cf3e3ba9-8ceb-4d52-ac3e-7bf83edb3766

📥 Commits

Reviewing files that changed from the base of the PR and between 74be3f7 and d7e9f27.

📒 Files selected for processing (2)
  • openmeter/billing/charges/service/taxcode_test.go
  • test/credits/creditgrant_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/credits/creditgrant_test.go

@mark-vass-konghq
mark-vass-konghq force-pushed the feat/test-charge-tax-config-carryover branch from d7e9f27 to 32eb5f8 Compare May 6, 2026 14:56
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/test-charge-tax-config-carryover branch from 32eb5f8 to 3bef920 Compare May 6, 2026 15:51

This branch was previously deployed

1 inactive deployment
dev — 3bef9203 Deployed May 6, 2026 by mark-vass-konghq via Migration Checks #14167
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants