Repository navigation
fix: implement settlement mode in productcatalog - #4026
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (12)
✅ Files skipped from review due to trivial changes (8)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds end-to-end support for the Plan/Subscription Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 docstrings
🧪 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
openmeter/productcatalog/plan/service/service_test.go (1)
214-238: Consider adding one invalid-settlement-mode test case.Nice coverage on explicit and defaulted success paths. Adding a failing case for an unsupported mode would lock down the validation side too.
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/productcatalog/plan/service/service_test.go` around lines 214 - 238, Add a new subtest (e.g., t.Run("InvalidSettlementMode", ...)) that uses pctestutils.NewTestPlan to build a plan, sets .Key to a unique value and sets .SettlementMode to an unsupported string (e.g., "invalid_mode"), then call env.Plan.CreatePlan(ctx, ...) and assert that it returns an error and does not return a valid plan (use require.Error/require.Nil or assert.Error/assert.Nil). Reference the same symbols used in existing tests: pctestutils.NewTestPlan, env.Plan.CreatePlan, and the SettlementMode field and productcatalog constants to locate where to add this failing-case test.
🤖 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/subscription/workflow/service/subscription_test.go`:
- Around line 2079-2122: The test asserts EditRunning returns an error when
attempting to mutate SettlementMode but doesn't verify the subscription state
stayed unchanged; after the failing call to deps.WorkflowService.EditRunning
(using subView.Subscription.NamespacedID), re-fetch the subscription (e.g., via
deps.WorkflowService.View or the appropriate get/read method on WorkflowService)
and assert that the subscription's SettlementMode remains
productcatalog.CreditThenInvoiceSettlementMode (checking
subscription.Subscription.SettlementMode) to ensure the failed edit didn't
mutate state.
---
Nitpick comments:
In `@openmeter/productcatalog/plan/service/service_test.go`:
- Around line 214-238: Add a new subtest (e.g., t.Run("InvalidSettlementMode",
...)) that uses pctestutils.NewTestPlan to build a plan, sets .Key to a unique
value and sets .SettlementMode to an unsupported string (e.g., "invalid_mode"),
then call env.Plan.CreatePlan(ctx, ...) and assert that it returns an error and
does not return a valid plan (use require.Error/require.Nil or
assert.Error/assert.Nil). Reference the same symbols used in existing tests:
pctestutils.NewTestPlan, env.Plan.CreatePlan, and the SettlementMode field and
productcatalog constants to locate where to add this failing-case test.
🪄 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: 575d325d-5df6-4c63-9077-06799df43469
📒 Files selected for processing (12)
openmeter/productcatalog/addon/adapter/mapping.goopenmeter/productcatalog/plan/adapter/adapter_test.goopenmeter/productcatalog/plan/adapter/plan.goopenmeter/productcatalog/plan/assert.goopenmeter/productcatalog/plan/service/plan.goopenmeter/productcatalog/plan/service/service_test.goopenmeter/productcatalog/testutils/plan.goopenmeter/subscription/addon/diff/restore_test.goopenmeter/subscription/service/sync.goopenmeter/subscription/testutils/builder.goopenmeter/subscription/workflow/service/addon_test.goopenmeter/subscription/workflow/service/subscription_test.go
5fc23db to
304ee36
Compare
Overview
Wire up SettlementMode persistence in plan creation adapter, fixing a bug where non-default modes (e.g. credit_only) were silently stored as
credit_then_invoice due to the DB default
Add service-layer defaulting of empty SettlementMode to credit_then_invoice, ensuring existing API callers and tests that don't set the field
continue to work without breaking
Fix NextPlan and addon adapter's FromPlanRow to correctly copy/read SettlementMode, closing gaps where the field was dropped during plan
versioning and addon plan resolution
Enforce SettlementMode immutability on running subscriptions at the application layer (sync service), complementing the existing DB-level
Immutable() constraint
Add comprehensive tests covering plan create/update/default, plan-to-subscription propagation, custom subscription creation, and immutability
enforcement
Test plan
mode changes
Summary by CodeRabbit
New Features
Bug Fixes
Tests