Skip to content

Commit 065d44d

Browse files
committed
feat(taxcode): add annotations to update
1 parent aa5f680 commit 065d44d

5 files changed

Lines changed: 26 additions & 9 deletions

File tree

api/v3/handlers/taxcodes/convert.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727
// goverter:context namespacedID
2828
// goverter:map NamespacedID | ResolveNamespacedIDFromContext
2929
// goverter:map Labels Metadata
30+
// goverter:ignore Annotations
3031
ConvertFromUpsertTaxCodeRequestToUpdateTaxCodeInput func(namespacedID models.NamespacedID, upsertTaxCodeRequest api.UpsertTaxCodeRequest) (taxcode.UpdateTaxCodeInput, error)
3132

3233
// goverter:map . Labels | ConvertTaxCodeToLabels

openmeter/taxcode/adapter/taxcode.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ func (a *adapter) UpdateTaxCode(ctx context.Context, input taxcode.UpdateTaxCode
5858
Where(taxcodedb.DeletedAtIsNil()).
5959
SetName(input.Name).
6060
SetNillableDescription(input.Description).
61-
SetMetadata(input.Metadata)
61+
SetMetadata(input.Metadata).
62+
SetAnnotations(input.Annotations)
6263

6364
if len(input.AppMappings) > 0 {
6465
query = query.SetAppMappings(&input.AppMappings)

openmeter/taxcode/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type UpdateTaxCodeInput struct {
6868
Description *string
6969
AppMappings TaxCodeAppMappings
7070
Metadata models.Metadata
71+
Annotations models.Annotations
7172
}
7273

7374
func (i UpdateTaxCodeInput) Validate() error {

openmeter/taxcode/service/taxcode.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ func (s *service) GetOrCreateByAppMapping(ctx context.Context, input taxcode.Get
110110
AppMappings: taxcode.TaxCodeAppMappings{
111111
{AppType: input.AppType, TaxCode: input.TaxCode},
112112
},
113-
Annotations: models.Annotations{
114-
taxcode.AnnotationKeyManagedBy: taxcode.AnnotationValueManagedBySystem,
115-
},
116113
})
117114
if err != nil {
118115
// Another request may have created it concurrently.

openmeter/taxcode/service/taxcode_test.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/stretchr/testify/assert"
77
"github.com/stretchr/testify/require"
88

9-
"github.com/openmeterio/openmeter/openmeter/app"
109
"github.com/openmeterio/openmeter/openmeter/taxcode"
1110
taxcodetestutils "github.com/openmeterio/openmeter/openmeter/taxcode/testutils"
1211
"github.com/openmeterio/openmeter/openmeter/testutils"
@@ -21,11 +20,15 @@ func TestTaxCodeService(t *testing.T) {
2120
ns := testutils.NameGenerator.Generate().Key
2221

2322
t.Run("SystemManaged", func(t *testing.T) {
24-
// Create a system-managed tax code via GetOrCreateByAppMapping.
25-
tc, err := env.Service.GetOrCreateByAppMapping(t.Context(), taxcode.GetOrCreateByAppMappingInput{
23+
// Create a system-managed tax code by explicitly setting the annotation.
24+
name := testutils.NameGenerator.Generate()
25+
tc, err := env.Service.CreateTaxCode(t.Context(), taxcode.CreateTaxCodeInput{
2626
Namespace: ns,
27-
AppType: app.AppTypeStripe,
28-
TaxCode: "txcd_99999999",
27+
Key: name.Key,
28+
Name: name.Name,
29+
Annotations: models.Annotations{
30+
taxcode.AnnotationKeyManagedBy: taxcode.AnnotationValueManagedBySystem,
31+
},
2932
})
3033
require.NoError(t, err)
3134
assert.True(t, tc.IsManagedBySystem())
@@ -73,6 +76,20 @@ func TestTaxCodeService(t *testing.T) {
7376
assert.Equal(t, "updated name", updated.Name)
7477
})
7578

79+
t.Run("UpdateAnnotationsSucceeds", func(t *testing.T) {
80+
updated, err := env.Service.UpdateTaxCode(t.Context(), taxcode.UpdateTaxCodeInput{
81+
NamespacedID: models.NamespacedID{Namespace: ns, ID: tc.ID},
82+
Name: tc.Name,
83+
Annotations: models.Annotations{
84+
taxcode.AnnotationKeyManagedBy: taxcode.AnnotationValueManagedBySystem,
85+
"schema_version": 1,
86+
},
87+
})
88+
require.NoError(t, err)
89+
assert.True(t, updated.IsManagedBySystem())
90+
assert.Equal(t, float64(1), updated.Annotations["schema_version"])
91+
})
92+
7693
t.Run("DeleteSucceeds", func(t *testing.T) {
7794
// Create a fresh one to delete (the one above was updated, still valid).
7895
name2 := testutils.NameGenerator.Generate()

0 commit comments

Comments
 (0)