Repository navigation
chore: split chages testcases - #3960
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a reusable BaseSuite test scaffold for charges, refactors credit-purchase tests to embed it, and introduces a new InvoicableChargesTestSuite with end-to-end flat-fee + credit-realization invoice/payment flows. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip You can disable the changed files summary in the walkthrough.Disable the |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
openmeter/billing/charges/service/base_test.go (1)
112-130: ValidateservicePeriodin helper input for earlier and clearer failures.
createMockChargeIntentInput.Validate()currently skips period validation, so invalid ranges fail deeper with less actionable errors.Suggested patch
func (i *createMockChargeIntentInput) Validate() error { if i.price == nil { return errors.New("price is required") } @@ if i.currency == "" { return errors.New("currency is required") } + + if err := i.servicePeriod.Validate(); err != nil { + return err + } return nil }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/charges/service/base_test.go` around lines 112 - 130, The helper Validate method for createMockChargeIntentInput is missing checks for the servicePeriod; update createMockChargeIntentInput.Validate() to verify that servicePeriod is not nil, that servicePeriod.Start and servicePeriod.End are set (non-zero), and that Start is before End (or End is after Start), returning clear errors like "servicePeriod is required", "servicePeriod start is required", "servicePeriod end is required", or "servicePeriod start must be before end" to fail fast and produce actionable messages.openmeter/billing/charges/service/invoicable_test.go (1)
115-115: Please replace this TODO with concrete assertions (periods/price) in this flow.This scenario is the core invoicable path, so asserting only charge/link presence leaves a blind spot for regression on period and pricing mapping.
If you want, I can draft the exact assertions for service/billing/full period and price fields in this subtest.
As per coding guidelines: "**/*_test.go: Make sure the tests are comprehensive and cover the changes."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/charges/service/invoicable_test.go` at line 115, Replace the TODO with concrete assertions that validate the invoicable charge's period and pricing fields: locate the core invoicable subtest in invoicable_test.go and after you assert presence of charge and link, add assertions on charge.Period.Start and charge.Period.End (or the equivalent Start/End fields) to match the expected start/end timestamps for the full billing period, and assert pricing fields such as charge.Price.Amount (or UnitPrice/Total) and charge.Price.Currency equal the expected values; use the same test helpers/assert style present in the file (e.g., require.Equal or assert.Equal) so failures show exact mismatches for period and price.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openmeter/billing/charges/service/invoicable_test.go`:
- Around line 69-70: The test calls clock.SetTime(servicePeriod.From) which
mutates global clock state and is not restored; modify the test so it saves the
previous clock value before calling clock.SetTime and ensures restoration at
test end (e.g., defer restoring the saved time or invoking the package’s clock
reset helper) so global clock state is reset after the test; locate the mutation
by looking for clock.SetTime and servicePeriod.From in invoicable_test.go and
add the corresponding save+defer restore (or call the package reset) immediately
after setting the time.
---
Nitpick comments:
In `@openmeter/billing/charges/service/base_test.go`:
- Around line 112-130: The helper Validate method for
createMockChargeIntentInput is missing checks for the servicePeriod; update
createMockChargeIntentInput.Validate() to verify that servicePeriod is not nil,
that servicePeriod.Start and servicePeriod.End are set (non-zero), and that
Start is before End (or End is after Start), returning clear errors like
"servicePeriod is required", "servicePeriod start is required", "servicePeriod
end is required", or "servicePeriod start must be before end" to fail fast and
produce actionable messages.
In `@openmeter/billing/charges/service/invoicable_test.go`:
- Line 115: Replace the TODO with concrete assertions that validate the
invoicable charge's period and pricing fields: locate the core invoicable
subtest in invoicable_test.go and after you assert presence of charge and link,
add assertions on charge.Period.Start and charge.Period.End (or the equivalent
Start/End fields) to match the expected start/end timestamps for the full
billing period, and assert pricing fields such as charge.Price.Amount (or
UnitPrice/Total) and charge.Price.Currency equal the expected values; use the
same test helpers/assert style present in the file (e.g., require.Equal or
assert.Equal) so failures show exact mismatches for period and price.
🪄 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: a049301a-aec8-41a2-a0e3-03206a9b4ff6
📒 Files selected for processing (3)
openmeter/billing/charges/service/base_test.goopenmeter/billing/charges/service/creditpurchase_test.goopenmeter/billing/charges/service/invoicable_test.go
| clock.SetTime(servicePeriod.From) | ||
|
|
There was a problem hiding this comment.
Reset the test clock after mutation to avoid cross-test leakage.
clock.SetTime(...) mutates global state, but this test never restores it. That can make later tests flaky depending on execution order. Please add cleanup to restore the previous clock value (or use the package’s reset helper) at test end.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@openmeter/billing/charges/service/invoicable_test.go` around lines 69 - 70,
The test calls clock.SetTime(servicePeriod.From) which mutates global clock
state and is not restored; modify the test so it saves the previous clock value
before calling clock.SetTime and ensures restoration at test end (e.g., defer
restoring the saved time or invoking the package’s clock reset helper) so global
clock state is reset after the test; locate the mutation by looking for
clock.SetTime and servicePeriod.From in invoicable_test.go and add the
corresponding save+defer restore (or call the package reset) immediately after
setting the time.
Improves the categorization of the testcases.
4cd91e5 to
3462978
Compare
Overview
Improves the categorization of the testcases.
Notes for reviewer
Summary by CodeRabbit