-
Notifications
You must be signed in to change notification settings - Fork 152
fix: grant creation mapping #3454
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
Adds e2e tests to assert this works as expected and adds a missing mapping.
📝 WalkthroughWalkthroughAdds Metadata to entitlement grant create input and output types, updates e2e tests to set/assert Metadata, introduces an annotations parity test across V2 create and V1 get, and propagates Metadata during metered grant creation to the underlying CreateGrant input. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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 (1)
e2e/entitlement_parity_test.go (1)
372-403: Test only verifies Annotations but not Metadata.The test name "Annotations and metadata parity (create and get)" suggests it should test both Annotations and Metadata, but the implementation only verifies Annotations. Since this PR adds Metadata mapping support, consider adding assertions for Metadata as well to ensure complete coverage of the fix.
Apply this diff to add Metadata verification:
t.Run("Annotations created with V2 API should show up in V1 API", func(t *testing.T) { createGrantResponse, err := client.CreateCustomerEntitlementGrantV2WithResponse(ctx, customerID, feature1Key, api.CreateCustomerEntitlementGrantV2JSONRequestBody{ Amount: 100, EffectiveAt: time.Now().Truncate(time.Minute).Add(time.Minute), Expiration: nil, Annotations: &api.Annotations{ "some_annotation": "some_annotation_value", }, + Metadata: &api.Metadata{ + "some_metadata_key": "some_metadata_value", + }, }) require.NoError(t, err) require.Equal(t, http.StatusCreated, createGrantResponse.StatusCode(), "Invalid status code [response_body=%s]", string(createGrantResponse.Body)) getGrantResponse, err := client.ListEntitlementGrantsWithResponse(ctx, subjectKey, feature1Key, &api.ListEntitlementGrantsParams{}) require.NoError(t, err) require.Equal(t, http.StatusOK, getGrantResponse.StatusCode(), "Invalid status code [response_body=%s]", string(getGrantResponse.Body)) require.NotNil(t, getGrantResponse.JSON200) require.GreaterOrEqual(t, len(lo.FromPtr(getGrantResponse.JSON200)), 1, "Invalid number of grants [response_body=%s]", string(getGrantResponse.Body)) var found *api.EntitlementGrant for _, grant := range lo.FromPtr(getGrantResponse.JSON200) { if grant.Id == createGrantResponse.JSON201.Id { found = &grant break } } require.NotNil(t, found, "Grant not found [response_body=%s]", string(getGrantResponse.Body)) require.Equal(t, "some_annotation_value", lo.FromPtr(found.Annotations)["some_annotation"]) + require.Equal(t, "some_metadata_value", lo.FromPtr(found.Metadata)["some_metadata_key"]) })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
e2e/e2e_test.go(2 hunks)e2e/entitlement_parity_test.go(1 hunks)openmeter/entitlement/metered/entitlement_grant.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
e2e/entitlement_parity_test.go (1)
api/api.gen.go (4)
CreateCustomerEntitlementGrantV2JSONRequestBody(9164-9164)Annotations(1036-1036)ListEntitlementGrantsParams(8741-8744)EntitlementGrant(2775-2833)
e2e/e2e_test.go (3)
api/client/javascript/src/client/schemas.ts (1)
Metadata(11689-11689)api/api.gen.go (1)
Metadata(4946-4946)api/client/go/client.gen.go (1)
Metadata(4479-4479)
openmeter/entitlement/metered/entitlement_grant.go (3)
api/client/javascript/src/client/schemas.ts (1)
Metadata(11689-11689)api/api.gen.go (1)
Metadata(4946-4946)api/client/go/client.gen.go (1)
Metadata(4479-4479)
⏰ 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). (8)
- GitHub Check: Artifacts / Container image
- GitHub Check: Artifacts / Benthos Collector Container image
- GitHub Check: Migration Checks
- GitHub Check: Lint
- GitHub Check: Build
- GitHub Check: Code Generators
- GitHub Check: Test
- GitHub Check: Analyze (go)
🔇 Additional comments (3)
openmeter/entitlement/metered/entitlement_grant.go (1)
80-80: LGTM! Metadata propagation is correctly implemented.The addition of Metadata field mapping is consistent with the existing Annotations pattern and correctly propagates metadata from the input to the underlying grant creation.
e2e/e2e_test.go (2)
959-961: LGTM! Metadata field correctly added to grant creation.The Metadata field is properly included in the grant creation input, ensuring the new mapping is exercised in the e2e test.
988-990: LGTM! Expected grant output includes Metadata.The expected grant response correctly includes the Metadata field, verifying that metadata is properly propagated through the grant creation and retrieval flow.
Adds e2e tests to assert this works as expected and adds a missing mapping.
Overview
Fixes #(issue)
Notes for reviewer
Summary by CodeRabbit
New Features
Tests