Skip to content

Commit 670aaed

Browse files
committed
fix(pr): comments
1 parent 08dcf62 commit 670aaed

File tree

12 files changed

+133
-11
lines changed

12 files changed

+133
-11
lines changed

openmeter/app/stripe/invoicesync/handler_test.go

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,53 @@ import (
1111
"github.com/stretchr/testify/require"
1212

1313
stripeclient "github.com/openmeterio/openmeter/openmeter/app/stripe/client"
14+
"github.com/openmeterio/openmeter/openmeter/billing"
1415
)
1516

1617
func TestNewHandler_AllFieldsRequired(t *testing.T) {
17-
// NewHandler should reject nil for every required field.
18-
// We test this by passing an empty config — all fields are nil.
19-
_, err := NewHandler(HandlerConfig{})
20-
require.Error(t, err)
21-
// Should fail on the first nil check (adapter)
22-
assert.Contains(t, err.Error(), "adapter is required")
18+
// Build a fully valid config, then nil out one field at a time
19+
// to verify each required field produces an appropriate error.
20+
validConfig := HandlerConfig{
21+
Adapter: &mockAdapter{},
22+
AppService: &noopAppService{},
23+
BillingService: billing.NoopService{},
24+
StripeAppService: &noopStripeAppService{},
25+
SecretService: &noopSecretService{},
26+
StripeAppClientFactory: func(config stripeclient.StripeAppClientConfig) (stripeclient.StripeAppClient, error) {
27+
return nil, nil
28+
},
29+
Publisher: noopPublisher{},
30+
LockFunc: func(ctx context.Context, namespace, invoiceID string) error {
31+
return nil
32+
},
33+
Logger: slog.New(slog.NewTextHandler(os.Stderr, nil)),
34+
}
35+
36+
tests := []struct {
37+
name string
38+
mutate func(c *HandlerConfig)
39+
wantErr string
40+
}{
41+
{"adapter", func(c *HandlerConfig) { c.Adapter = nil }, "adapter is required"},
42+
{"app service", func(c *HandlerConfig) { c.AppService = nil }, "app service is required"},
43+
{"billing service", func(c *HandlerConfig) { c.BillingService = nil }, "billing service is required"},
44+
{"stripe app service", func(c *HandlerConfig) { c.StripeAppService = nil }, "stripe app service is required"},
45+
{"secret service", func(c *HandlerConfig) { c.SecretService = nil }, "secret service is required"},
46+
{"stripe app client factory", func(c *HandlerConfig) { c.StripeAppClientFactory = nil }, "stripe app client factory is required"},
47+
{"publisher", func(c *HandlerConfig) { c.Publisher = nil }, "publisher is required"},
48+
{"lock function", func(c *HandlerConfig) { c.LockFunc = nil }, "lock function is required"},
49+
{"logger", func(c *HandlerConfig) { c.Logger = nil }, "logger is required"},
50+
}
51+
52+
for _, tt := range tests {
53+
t.Run(tt.name, func(t *testing.T) {
54+
cfg := validConfig
55+
tt.mutate(&cfg)
56+
_, err := NewHandler(cfg)
57+
require.Error(t, err)
58+
assert.Contains(t, err.Error(), tt.wantErr)
59+
})
60+
}
2361
}
2462

2563
func TestHandle_NilEvent(t *testing.T) {

openmeter/app/stripe/invoicesync/types_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func TestGenerateIdempotencyKey(t *testing.T) {
4848
t.Run("key is hex encoded sha256", func(t *testing.T) {
4949
key := GenerateIdempotencyKey("inv-1", "sess-1", 0, OpTypeInvoiceCreate)
5050
require.Len(t, key, 64, "sha256 hex encoding should be 64 chars")
51+
assert.Regexp(t, `^[0-9a-f]{64}$`, key, "key should be lowercase hex")
5152
})
5253
}
5354

openmeter/billing/adapter/invoiceapp.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"github.com/openmeterio/openmeter/openmeter/billing"
88
"github.com/openmeterio/openmeter/openmeter/ent/db"
99
"github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice"
10+
"github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline"
11+
"github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicelinediscount"
12+
"github.com/openmeterio/openmeter/openmeter/ent/db/billingstandardinvoicedetailedline"
1013
"github.com/openmeterio/openmeter/pkg/framework/entutils"
1114
)
1215

@@ -35,6 +38,7 @@ func (a *adapter) SyncExternalIDs(ctx context.Context, in billing.SyncExternalID
3538
// Update detailed line external IDs
3639
for lineID, externalID := range in.LineExternalIDs {
3740
_, err := tx.db.BillingStandardInvoiceDetailedLine.UpdateOneID(lineID).
41+
Where(billingstandardinvoicedetailedline.InvoiceID(in.Invoice.ID)).
3842
SetInvoicingAppExternalID(externalID).
3943
Save(ctx)
4044
if err != nil {
@@ -49,6 +53,9 @@ func (a *adapter) SyncExternalIDs(ctx context.Context, in billing.SyncExternalID
4953
// Update discount external IDs
5054
for discountID, externalID := range in.LineDiscountExternalIDs {
5155
_, err := tx.db.BillingInvoiceLineDiscount.UpdateOneID(discountID).
56+
Where(billinginvoicelinediscount.HasBillingInvoiceLineWith(
57+
billinginvoiceline.InvoiceID(in.Invoice.ID),
58+
)).
5259
SetInvoicingAppExternalID(externalID).
5360
Save(ctx)
5461
if err != nil {

openmeter/ent/db/appstripeinvoicesyncop/appstripeinvoicesyncop.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/db/appstripeinvoicesyncop_create.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/db/appstripeinvoicesyncop_update.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/db/appstripeinvoicesyncplan/appstripeinvoicesyncplan.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/db/appstripeinvoicesyncplan_create.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/db/appstripeinvoicesyncplan_update.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/db/runtime.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)