Repository navigation
fix: usage based ratecard validation - #4331
Conversation
📝 WalkthroughWalkthroughAdds validation enforcing FeatureKey presence for usage-based rate cards; converts NewTestPlan to a transformer-based API (MonthPeriod, WithPlanPhases/WithPlanKey) and updates unit and e2e tests to use feature-backed rate cards and the new helpers. ChangesRate Card Validation Enhancement
Test Utility and Suite Migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsTimed out fetching pipeline failures after 30000ms Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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
🤖 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/productcatalog/plan/adapter/adapter_test.go`:
- Around line 25-26: Replace the use of context.Background() when creating the
test context so the test's lifecycle is tied to the testing harness: in the test
where you call context.WithCancel to create ctx and cancel (symbols: ctx,
cancel, context.WithCancel), pass t.Context() instead of context.Background() so
cancellation and deadlines follow the test (use t.Context() as the parent).
🪄 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: 190f7302-73b7-4fd3-92d8-c9f4b4d03fa3
📒 Files selected for processing (11)
openmeter/productcatalog/addon/service/taxcode_test.goopenmeter/productcatalog/errors.goopenmeter/productcatalog/plan/adapter/adapter_test.goopenmeter/productcatalog/plan/service/service_test.goopenmeter/productcatalog/plan/service/taxcode_test.goopenmeter/productcatalog/planaddon/adapter/adapter_test.goopenmeter/productcatalog/planaddon/service/service_test.goopenmeter/productcatalog/ratecard.goopenmeter/productcatalog/testutils/plan.goopenmeter/subscription/addon/diff/restore_test.goopenmeter/subscription/workflow/service/addon_test.go
e67c543 to
8e00f12
Compare
8e00f12 to
cf98d88
Compare
cf98d88 to
abdce99
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
e2e/e2e_test.go (1)
1569-1571:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAvoid strict
Len == 1here to reduce flaky e2e behavior.This can still fail if the same meter already has multiple features (shared DB / reruns). It’s safer to assert that the created feature is present.
Suggested tweak
features, err := featureListResp.JSON200.AsListFeaturesResult0() require.NoError(t, err) - require.Len(t, features, 1) + require.NotEmpty(t, features) + found := false + for _, f := range features { + if f.Id == featureId { + found = true + break + } + } + require.True(t, found, "created feature not found in filtered feature list")As per coding guidelines
**/*_test.go: “Make sure the tests are comprehensive and cover the changes.”🤖 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 `@e2e/e2e_test.go` around lines 1569 - 1571, The test currently asserts require.Len(t, features, 1) which is flaky; instead, decode the list via featureListResp.JSON200.AsListFeaturesResult0() into features and assert that the expected created feature exists in that slice (e.g., by matching its ID or name). Replace the strict require.Len check with a presence check over features (using require.True with a loop/any() predicate or require.Contains/require.Equal on a mapped list of IDs/names) so the test passes even if extra features exist.
🤖 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 `@e2e/productcatalog_smoke_v3_test.go`:
- Around line 106-111: The comment is outdated: it claims the graduated rate
card has no feature, but the test now passes features[1] into
validGraduatedRateCard; update the block comment around the three rate-card
shapes to reflect that the graduated card does include a feature (e.g., mention
validGraduatedRateCard(features[1]) supplies a feature) so readers aren't
confused by the earlier statement that the graduated case has "no feature."
---
Outside diff comments:
In `@e2e/e2e_test.go`:
- Around line 1569-1571: The test currently asserts require.Len(t, features, 1)
which is flaky; instead, decode the list via
featureListResp.JSON200.AsListFeaturesResult0() into features and assert that
the expected created feature exists in that slice (e.g., by matching its ID or
name). Replace the strict require.Len check with a presence check over features
(using require.True with a loop/any() predicate or
require.Contains/require.Equal on a mapped list of IDs/names) so the test passes
even if extra features exist.
🪄 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: bc11a356-3983-4d6d-81ba-671149989b91
📒 Files selected for processing (15)
e2e/addons_v3_test.goe2e/e2e_test.goe2e/productcatalog_smoke_v3_test.goe2e/v3helpers_test.goopenmeter/productcatalog/addon/service/taxcode_test.goopenmeter/productcatalog/errors.goopenmeter/productcatalog/plan/adapter/adapter_test.goopenmeter/productcatalog/plan/service/service_test.goopenmeter/productcatalog/plan/service/taxcode_test.goopenmeter/productcatalog/planaddon/adapter/adapter_test.goopenmeter/productcatalog/planaddon/service/service_test.goopenmeter/productcatalog/ratecard.goopenmeter/productcatalog/testutils/plan.goopenmeter/subscription/addon/diff/restore_test.goopenmeter/subscription/workflow/service/addon_test.go
🚧 Files skipped from review as they are similar to previous changes (11)
- openmeter/productcatalog/ratecard.go
- openmeter/subscription/addon/diff/restore_test.go
- openmeter/productcatalog/planaddon/service/service_test.go
- openmeter/productcatalog/errors.go
- openmeter/productcatalog/planaddon/adapter/adapter_test.go
- openmeter/subscription/workflow/service/addon_test.go
- openmeter/productcatalog/addon/service/taxcode_test.go
- openmeter/productcatalog/testutils/plan.go
- openmeter/productcatalog/plan/service/taxcode_test.go
- openmeter/productcatalog/plan/service/service_test.go
- openmeter/productcatalog/plan/adapter/adapter_test.go
Overview
Ensure that usage based ratecards with usage-based pricing always have valid feature assigned to.
Summary by CodeRabbit
Bug Fixes
Tests