-
Notifications
You must be signed in to change notification settings - Fork 152
chore: remove flat fee line constructor #3510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This patch makes sure that we are always using the usagebased wrapped fee lines in tests. This is required as even thru the previous version is still working it is not something worth testing for: we should validate using the new format of the lines.
📝 WalkthroughWalkthroughRenames and repurposes the billing constructor: NewUsageBasedFlatFeeLine is removed and its usage replaced with NewFlatFeeLine. NewFlatFeeLine now builds a usage-based invoice line with optional featureKey. Tests and call sites are updated accordingly, including changes in expected line fields and type constants. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
openmeter/billing/invoiceline.go (1)
630-674: Update docstring to reflect UsageBased wrapper; consider a temporary shim for backward compatibility.
- The function now constructs a usage-based line backed by a flat price, but the comment still says “invoice-level flat fee line.” Please update to avoid confusion.
- Optional: add a deprecated alias for the removed NewUsageBasedFlatFeeLine to reduce breakage for external users for one release.
Example docstring change:
-// NewFlatFeeLine creates a new invoice-level flat fee line. +// NewFlatFeeLine creates a usage-based invoice line backed by a flat price (UBP flat-fee wrapper). +// Use WithFeatureKey(...) to associate a feature when needed.Optional shim:
+// Deprecated: use NewFlatFeeLine. Will be removed in a future release. +func NewUsageBasedFlatFeeLine(input NewFlatFeeLineInput, opts ...usageBasedLineOption) *Line { + return NewFlatFeeLine(input, opts...) +}test/billing/invoice_test.go (1)
48-48: Prefer pkg/clock for deterministic tests.Use clock.Now() instead of time.Now() to keep tests stable and consistent with the suite’s time control.
-now := time.Now().Truncate(time.Second).In(time.UTC) +now := clock.Now().Truncate(time.Second).In(time.UTC)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
openmeter/billing/httpdriver/invoice_test.go(1 hunks)openmeter/billing/invoiceline.go(1 hunks)openmeter/notification/internal/rule.go(1 hunks)test/app/stripe/invoice_test.go(1 hunks)test/billing/collection_test.go(1 hunks)test/billing/invoice_test.go(10 hunks)test/billing/ubpflatfee_test.go(4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-04-21T08:32:31.689Z
Learnt from: chrisgacsal
PR: openmeterio/openmeter#2699
File: openmeter/productcatalog/planaddon/service/service_test.go:210-211
Timestamp: 2025-04-21T08:32:31.689Z
Learning: In `productcatalog.UsageBasedRateCard`, the `BillingCadence` field is a non-pointer `isodate.Period`, while in `productcatalog.FlatFeeRateCard`, `BillingCadence` is a pointer type (`*isodate.Period`). This means `MonthPeriod` should be used directly for `UsageBasedRateCard` (not `&MonthPeriod`).
Applied to files:
test/billing/ubpflatfee_test.gotest/billing/invoice_test.goopenmeter/billing/httpdriver/invoice_test.go
🧬 Code graph analysis (7)
test/billing/ubpflatfee_test.go (1)
openmeter/billing/invoiceline.go (2)
NewFlatFeeLine(631-673)NewFlatFeeLineInput(592-616)
openmeter/notification/internal/rule.go (1)
openmeter/billing/invoiceline.go (2)
NewFlatFeeLine(631-673)NewFlatFeeLineInput(592-616)
test/billing/collection_test.go (1)
openmeter/billing/invoiceline.go (2)
NewFlatFeeLine(631-673)NewFlatFeeLineInput(592-616)
test/billing/invoice_test.go (4)
pkg/clock/clock.go (1)
Now(14-21)openmeter/billing/invoiceline.go (6)
InvoiceLineTypeUsageBased(35-35)UsageBasedLine(764-777)Period(83-86)Line(311-325)NewFlatFeeLine(631-673)NewFlatFeeLineInput(592-616)openmeter/productcatalog/price.go (4)
Price(86-93)NewPriceFrom(369-391)FlatPrice(420-427)InAdvancePaymentTerm(20-20)test/billing/suite.go (1)
ExpectJSONEqual(571-581)
openmeter/billing/httpdriver/invoice_test.go (1)
openmeter/billing/invoiceline.go (1)
NewFlatFeeLine(631-673)
openmeter/billing/invoiceline.go (1)
openmeter/billing/service/lineservice/service.go (1)
Line(206-221)
test/app/stripe/invoice_test.go (1)
openmeter/billing/invoiceline.go (2)
NewFlatFeeLine(631-673)NewFlatFeeLineInput(592-616)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: E2E
- GitHub Check: Quickstart
- GitHub Check: Lint
- GitHub Check: Test
- GitHub Check: Code Generators
- GitHub Check: Build
- GitHub Check: Analyze (go)
🔇 Additional comments (7)
test/app/stripe/invoice_test.go (1)
1304-1311: Constructor swap looks good.Switch to billing.NewFlatFeeLine aligns with the unified constructor. No issues.
test/billing/collection_test.go (1)
244-251: Unified constructor usage is correct.Both test cases now use billing.NewFlatFeeLine. Looks consistent with the new behavior.
Also applies to: 256-263
test/billing/ubpflatfee_test.go (1)
49-56: Migration to the new constructor is consistent.All occurrences correctly use billing.NewFlatFeeLine; validations still check detailed fee lines and totals. LGTM.
Also applies to: 161-177, 241-256, 266-276
openmeter/billing/httpdriver/invoice_test.go (1)
59-69: LGTM on constructor change.Switching to billing.NewFlatFeeLine matches the new creation path. No other adjustments needed.
openmeter/notification/internal/rule.go (1)
188-205: Test payload constructor update looks correct.Using billing.NewFlatFeeLine here preserves the intended simulated invoice content.
test/billing/invoice_test.go (2)
252-252: Assertions updated for UsageBased wrapper are correct.
- Type switched to InvoiceLineTypeUsageBased.
- Expected price set via productcatalog.NewPriceFrom(FlatPrice).
- JSON equality helper aligns with structural changes.
- Lookups filter by usage-based type/feature key where appropriate.
Also applies to: 266-272, 285-285, 324-327, 363-371, 374-375
3979-3985: Constructor swaps in additional tests look good.Updated to billing.NewFlatFeeLine across period persistence and deleted customer scenarios. No issues.
Also applies to: 4011-4017, 4090-4096, 4127-4133
Overview
This patch makes sure that we are always using the usagebased wrapped fee lines in tests.
This is required as even thru the previous version is still working it is not something worth testing for: we should validate using the new format of the lines.
Notes for reviewer
The ubp wrapped flat fee lines is running reliably on prod for ages, so it's a no risk change.
Summary by CodeRabbit