Repository navigation
feat(backend): add settlement mode to internal types - #4013
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a new SettlementMode field to Plan and Subscription models, validates it, and propagates settlement_mode through plan creation/update, adapters, repo persistence, mappings, converters, and test fixtures so settlement mode is consistently carried end-to-end. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
e367a9b to
1d037a9
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
openmeter/subscription/workflow/service/subscription_test.go (1)
914-914: Please add one explicit settlement-mode assertion inTestChangeToPlan.Line 914 updates the fixture, but the test doesn’t directly assert that settlement mode is preserved in the resulting subscription spec/view.
Suggested assertion
require.NotNil(t, new.Subscription.PlanRef) require.Equal(t, examplePlanInput2.Key, new.Subscription.PlanRef.Key) + require.Equal(t, productcatalog.CreditThenInvoiceSettlementMode, new.Spec.CreateSubscriptionPlanInput.SettlementMode)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/subscription/workflow/service/subscription_test.go` at line 914, Add an explicit assertion in TestChangeToPlan that the subscription's settlement mode is preserved: after invoking the code under test and obtaining the resulting subscription (e.g., the variable named result/ got/ subView returned by the workflow), assert that its SettlementMode field equals productcatalog.CreditThenInvoiceSettlementMode (for example: require.Equal(t, productcatalog.CreditThenInvoiceSettlementMode, result.Spec.SettlementMode) or equivalent); place this assertion after the existing fixture update (where SettlementMode: productcatalog.CreditThenInvoiceSettlementMode is set) and after the function call that produces the subscription view so the test explicitly verifies settlement mode preservation.openmeter/billing/worker/subscriptionsync/service/sync_test.go (1)
153-153: Coverage gap: only one settlement mode is exercised in these updates.All new fixtures use
CreditThenInvoiceSettlementMode. Consider adding at least one scenario each forinvoice_onlyandcredit_onlyso enum-path regressions are caught early.As per coding guidelines
**/*_test.go: Make sure the tests are comprehensive and cover the changes.Also applies to: 545-545, 796-796, 931-931, 1538-1538, 1623-1623, 1915-1915, 2060-2060, 2280-2280, 4245-4245, 4713-4713, 4824-4824, 4935-4935
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/worker/subscriptionsync/service/sync_test.go` at line 153, The fixtures in sync_test.go only exercise productcatalog.CreditThenInvoiceSettlementMode; add at least two additional test scenarios (or table-driven entries) that set SettlementMode to productcatalog.InvoiceOnlySettlementMode and productcatalog.CreditOnlySettlementMode respectively, mirror the existing fixture structure used where SettlementMode is assigned, and add assertions for the expected behavior/outcomes for those modes (e.g., invoice-only flow and credit-only flow) so enum-path regressions are covered; update the relevant test function(s) in sync_test.go to include these new cases.
🤖 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/productcatalog/plan/plan.go`:
- Around line 73-87: The new ValidateSettlementMode validator is never invoked
because it isn't added to the Plan validation chain; update the Plan.Validate
method to include ValidateSettlementMode() (or register it where other
validators are composed) so settlement mode checks run during the default
validation path; locate Plan.Validate and append or merge
models.ValidatorFunc[Plan](ValidateSettlementMode()) into the existing
validators slice/chain so empty/invalid SettlementMode errors are returned via
models.NewNillableGenericValidationError.
In `@openmeter/productcatalog/plan/service.go`:
- Around line 109-111: CreatePlanInput.Validate() and UpdatePlanInput.Validate()
are missing checks for the new SettlementMode field
(productcatalog.SettlementMode), so add validation to both methods to reject
empty or invalid values: ensure SettlementMode is not empty (when required) and
that its value is one of the allowed enum cases defined for
productcatalog.SettlementMode (use the same enum validation pattern used for
other fields or a switch/IsValid helper). Update error messages to reference
SettlementMode and mirror existing validator behavior for consistency.
In `@openmeter/subscription/subscriptionview.go`:
- Line 243: The SubscriptionView.Validate() method is missing a check for
SettlementMode; add a comparison that asserts spec.SettlementMode ==
s.Subscription.SettlementMode (using the same structs used to build the spec)
and return a validation error if they differ. Locate the Validate function in
subscriptionview.go and after other field checks add a conditional that compares
spec.SettlementMode with s.Subscription.SettlementMode and produces an
appropriate error message (consistent with the existing validation error style)
when they don’t match.
---
Nitpick comments:
In `@openmeter/billing/worker/subscriptionsync/service/sync_test.go`:
- Line 153: The fixtures in sync_test.go only exercise
productcatalog.CreditThenInvoiceSettlementMode; add at least two additional test
scenarios (or table-driven entries) that set SettlementMode to
productcatalog.InvoiceOnlySettlementMode and
productcatalog.CreditOnlySettlementMode respectively, mirror the existing
fixture structure used where SettlementMode is assigned, and add assertions for
the expected behavior/outcomes for those modes (e.g., invoice-only flow and
credit-only flow) so enum-path regressions are covered; update the relevant test
function(s) in sync_test.go to include these new cases.
In `@openmeter/subscription/workflow/service/subscription_test.go`:
- Line 914: Add an explicit assertion in TestChangeToPlan that the
subscription's settlement mode is preserved: after invoking the code under test
and obtaining the resulting subscription (e.g., the variable named result/ got/
subView returned by the workflow), assert that its SettlementMode field equals
productcatalog.CreditThenInvoiceSettlementMode (for example: require.Equal(t,
productcatalog.CreditThenInvoiceSettlementMode, result.Spec.SettlementMode) or
equivalent); place this assertion after the existing fixture update (where
SettlementMode: productcatalog.CreditThenInvoiceSettlementMode is set) and after
the function call that produces the subscription view so the test explicitly
verifies settlement mode preservation.
🪄 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: d8117e2d-fd09-4784-8330-af4ee9332231
📒 Files selected for processing (31)
openmeter/billing/worker/subscriptionsync/service/suitebase_test.goopenmeter/billing/worker/subscriptionsync/service/sync_test.goopenmeter/billing/worker/subscriptionsync/service/syncbillinganchor_test.goopenmeter/productcatalog/plan/adapter/mapping.goopenmeter/productcatalog/plan/adapter/plan.goopenmeter/productcatalog/plan/assert.goopenmeter/productcatalog/plan/plan.goopenmeter/productcatalog/plan/service.goopenmeter/productcatalog/plan/service/plan.goopenmeter/productcatalog/subscription/plan.goopenmeter/productcatalog/subscription/service/plan.goopenmeter/productcatalog/subscription/testutils/adapter.goopenmeter/productcatalog/testutils/plan.goopenmeter/subscription/repo/mapping.goopenmeter/subscription/repo/subscriptionrepo.goopenmeter/subscription/repository.goopenmeter/subscription/subscription.goopenmeter/subscription/subscriptionspec.goopenmeter/subscription/subscriptionview.goopenmeter/subscription/testutils/builder.goopenmeter/subscription/testutils/helpers.goopenmeter/subscription/testutils/plan.goopenmeter/subscription/testutils/repository.goopenmeter/subscription/workflow/service/subscription_test.gotest/billing/subscription_test.gotest/customer/customer.gotest/customer/subject.gotest/subscription/scenario_editaligned_test.gotest/subscription/scenario_editcancel_test.gotest/subscription/scenario_entinnextphase_test.gotest/subscription/scenario_firstofmonth_test.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/productcatalog/plan/plan.go (1)
77-83: Avoid duplicate errors whenSettlementModeis empty.When
SettlementModeis empty, both the "required" check andValidate()will fire, producing two errors for the same root cause. Usingelse ifkeeps the error output clean.🔧 Suggested fix
func ValidateSettlementMode() models.ValidatorFunc[Plan] { return func(p Plan) error { var errs []error if p.SettlementMode == "" { errs = append(errs, fmt.Errorf("settlement mode is required")) - } - - if err := p.SettlementMode.Validate(); err != nil { + } else if err := p.SettlementMode.Validate(); err != nil { errs = append(errs, fmt.Errorf("invalid settlement mode: %w", err)) } return models.NewNillableGenericValidationError(errors.Join(errs...)) } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/productcatalog/plan/plan.go` around lines 77 - 83, The code currently appends both a "required" error and the result of p.SettlementMode.Validate() when SettlementMode is empty; change the two independent checks into an if...else if so Validate() is only called when p.SettlementMode is non-empty. Specifically, replace the separate blocks around p.SettlementMode == "" and the call to p.SettlementMode.Validate() so that the Validate() invocation (and its errs = append(... "invalid settlement mode: %w" ...)) runs only in the else branch after confirming p.SettlementMode is not empty, referencing p.SettlementMode and Validate() to locate the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@openmeter/productcatalog/plan/plan.go`:
- Around line 77-83: The code currently appends both a "required" error and the
result of p.SettlementMode.Validate() when SettlementMode is empty; change the
two independent checks into an if...else if so Validate() is only called when
p.SettlementMode is non-empty. Specifically, replace the separate blocks around
p.SettlementMode == "" and the call to p.SettlementMode.Validate() so that the
Validate() invocation (and its errs = append(... "invalid settlement mode: %w"
...)) runs only in the else branch after confirming p.SettlementMode is not
empty, referencing p.SettlementMode and Validate() to locate the code.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2a5ef655-e665-4b97-8771-e8d3b2de2ddd
📒 Files selected for processing (31)
openmeter/billing/worker/subscriptionsync/service/suitebase_test.goopenmeter/billing/worker/subscriptionsync/service/sync_test.goopenmeter/billing/worker/subscriptionsync/service/syncbillinganchor_test.goopenmeter/productcatalog/plan/adapter/mapping.goopenmeter/productcatalog/plan/adapter/plan.goopenmeter/productcatalog/plan/assert.goopenmeter/productcatalog/plan/plan.goopenmeter/productcatalog/plan/service.goopenmeter/productcatalog/plan/service/plan.goopenmeter/productcatalog/subscription/plan.goopenmeter/productcatalog/subscription/service/plan.goopenmeter/productcatalog/subscription/testutils/adapter.goopenmeter/productcatalog/testutils/plan.goopenmeter/subscription/repo/mapping.goopenmeter/subscription/repo/subscriptionrepo.goopenmeter/subscription/repository.goopenmeter/subscription/subscription.goopenmeter/subscription/subscriptionspec.goopenmeter/subscription/subscriptionview.goopenmeter/subscription/testutils/builder.goopenmeter/subscription/testutils/helpers.goopenmeter/subscription/testutils/plan.goopenmeter/subscription/testutils/repository.goopenmeter/subscription/workflow/service/subscription_test.gotest/billing/subscription_test.gotest/customer/customer.gotest/customer/subject.gotest/subscription/scenario_editaligned_test.gotest/subscription/scenario_editcancel_test.gotest/subscription/scenario_entinnextphase_test.gotest/subscription/scenario_firstofmonth_test.go
✅ Files skipped from review due to trivial changes (15)
- openmeter/subscription/repo/mapping.go
- openmeter/billing/worker/subscriptionsync/service/syncbillinganchor_test.go
- openmeter/subscription/testutils/builder.go
- openmeter/productcatalog/subscription/testutils/adapter.go
- openmeter/subscription/subscriptionview.go
- test/billing/subscription_test.go
- openmeter/billing/worker/subscriptionsync/service/suitebase_test.go
- test/subscription/scenario_entinnextphase_test.go
- openmeter/subscription/workflow/service/subscription_test.go
- openmeter/subscription/repo/subscriptionrepo.go
- test/subscription/scenario_editaligned_test.go
- test/subscription/scenario_editcancel_test.go
- test/customer/customer.go
- test/customer/subject.go
- openmeter/subscription/repository.go
🚧 Files skipped from review as they are similar to previous changes (14)
- openmeter/productcatalog/testutils/plan.go
- openmeter/productcatalog/plan/adapter/mapping.go
- openmeter/subscription/testutils/repository.go
- openmeter/subscription/testutils/helpers.go
- openmeter/productcatalog/plan/adapter/plan.go
- openmeter/productcatalog/plan/service/plan.go
- openmeter/productcatalog/subscription/service/plan.go
- openmeter/productcatalog/subscription/plan.go
- openmeter/productcatalog/plan/assert.go
- test/subscription/scenario_firstofmonth_test.go
- openmeter/productcatalog/plan/service.go
- openmeter/subscription/subscriptionspec.go
- openmeter/subscription/subscription.go
- openmeter/subscription/testutils/plan.go
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openmeter/productcatalog/plan/service.go (1)
282-323:⚠️ Potential issue | 🟡 MinorAdd
SettlementModetoValidateWithPlan.You've got the right idea here. This method applies update fields to a plan before validation, and
SettlementModeis definitely updatable (it's inUpdatePlanInputas a pointer), but it's missing from the merge step. Since the Plan'sValidate()checksSettlementMode, you'll want to apply it just like the other fields:if i.SettlementMode != nil { p.SettlementMode = *i.SettlementMode }This keeps the logic consistent across all updatable fields.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/productcatalog/plan/service.go` around lines 282 - 323, In UpdatePlanInput.ValidateWithPlan, the SettlementMode field isn't applied to the plan before validation; add the same merge pattern used for other pointer fields (check i.SettlementMode != nil and set p.SettlementMode = *i.SettlementMode) so that productcatalog.Plan has the updated SettlementMode prior to calling p.Validate(), ensuring Plan.Validate() sees the new value.
🤖 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/productcatalog/plan/service.go`:
- Around line 271-277: The settlement-mode validation block for i.SettlementMode
is being executed after the code computes the issues list (so its errors are
never returned); move the entire if i.SettlementMode != nil { ... } block to run
before the computation of issues (the same place other validations in
CreatePlanInput.Validate() run) so that calls to i.SettlementMode.Validate() and
the append to errs are included in the final returned errs; ensure you reference
the SettlementMode field and its Validate() method when relocating the block.
- Around line 135-141: The SettlementMode empty-check and Validate() call are
being appended to errs after issues is computed, so those errors get discarded;
move the block that checks i.SettlementMode == "" and the subsequent if err :=
i.SettlementMode.Validate(); err != nil { ... } so it runs before computing
issues (before the code that builds issues from errs), and change the two checks
to use an else if (i.e., do the empty-string check, else if call Validate()) to
avoid duplicate error messages; ensure the code still appends to errs and that
the function returns issues.AsError() after issues is built from the updated
errs.
---
Outside diff comments:
In `@openmeter/productcatalog/plan/service.go`:
- Around line 282-323: In UpdatePlanInput.ValidateWithPlan, the SettlementMode
field isn't applied to the plan before validation; add the same merge pattern
used for other pointer fields (check i.SettlementMode != nil and set
p.SettlementMode = *i.SettlementMode) so that productcatalog.Plan has the
updated SettlementMode prior to calling p.Validate(), ensuring Plan.Validate()
sees the new value.
🪄 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: eeca87f4-7a2d-41fb-8d4c-d616f957a0e2
📒 Files selected for processing (3)
openmeter/productcatalog/plan/plan.goopenmeter/productcatalog/plan/service.goopenmeter/subscription/subscriptionview.go
✅ Files skipped from review due to trivial changes (1)
- openmeter/subscription/subscriptionview.go
🚧 Files skipped from review as they are similar to previous changes (1)
- openmeter/productcatalog/plan/plan.go
d7be733 to
6a589e1
Compare
6a589e1 to
fa28977
Compare
fa28977 to
2ed60b7
Compare
2ed60b7 to
0257e79
Compare
0257e79 to
6317b74
Compare
6317b74 to
57d8505
Compare
Add settlement mode to internal types
Summary by CodeRabbit
New Features
Tests