Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 8 additions & 54 deletions internal/api/v1beta1connect/billing_checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
SetupBody: &frontierv1beta1.CheckoutSetupBody{
Expand Down Expand Up @@ -90,7 +89,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
SetupBody: &frontierv1beta1.CheckoutSetupBody{
Expand Down Expand Up @@ -130,7 +128,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
SubscriptionBody: &frontierv1beta1.CheckoutSubscriptionBody{
Expand Down Expand Up @@ -176,7 +173,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
ProductBody: &frontierv1beta1.CheckoutProductBody{
Expand Down Expand Up @@ -208,7 +204,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
}),
Expand All @@ -225,7 +220,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
SubscriptionBody: &frontierv1beta1.CheckoutSubscriptionBody{
Expand All @@ -246,7 +240,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
ProductBody: &frontierv1beta1.CheckoutProductBody{
Expand All @@ -267,7 +260,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
SetupBody: &frontierv1beta1.CheckoutSetupBody{
Expand All @@ -287,7 +279,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
SetupBody: &frontierv1beta1.CheckoutSetupBody{
Expand All @@ -307,7 +298,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
SubscriptionBody: &frontierv1beta1.CheckoutSubscriptionBody{
Expand All @@ -328,7 +318,6 @@ func TestConnectHandler_CreateCheckout(t *testing.T) {
},
req: connect.NewRequest(&frontierv1beta1.CreateCheckoutRequest{
OrgId: "org-123",
BillingId: "customer-123",
SuccessUrl: "https://example.com/success",
CancelUrl: "https://example.com/cancel",
ProductBody: &frontierv1beta1.CheckoutProductBody{
Expand Down Expand Up @@ -515,8 +504,7 @@ func TestConnectHandler_ListCheckouts(t *testing.T) {
setup: func(cs *mocks.CheckoutService, custSvc *mocks.CustomerService) {
},
req: connect.NewRequest(&frontierv1beta1.ListCheckoutsRequest{
OrgId: "",
BillingId: "test-billing-id",
OrgId: "",
}),
want: nil,
wantErr: true,
Expand All @@ -532,8 +520,7 @@ func TestConnectHandler_ListCheckouts(t *testing.T) {
}).Return(nil, errors.New("service error"))
},
req: connect.NewRequest(&frontierv1beta1.ListCheckoutsRequest{
OrgId: "test-org-id",
BillingId: "test-billing-id",
OrgId: "test-org-id",
}),
want: nil,
wantErr: true,
Expand All @@ -549,8 +536,7 @@ func TestConnectHandler_ListCheckouts(t *testing.T) {
}).Return([]checkout.Checkout{}, nil)
},
req: connect.NewRequest(&frontierv1beta1.ListCheckoutsRequest{
OrgId: "test-org-id",
BillingId: "test-billing-id",
OrgId: "test-org-id",
}),
want: connect.NewResponse(&frontierv1beta1.ListCheckoutsResponse{
CheckoutSessions: []*frontierv1beta1.CheckoutSession{},
Expand Down Expand Up @@ -594,8 +580,7 @@ func TestConnectHandler_ListCheckouts(t *testing.T) {
}, nil)
},
req: connect.NewRequest(&frontierv1beta1.ListCheckoutsRequest{
OrgId: "test-org-id",
BillingId: "test-billing-id",
OrgId: "test-org-id",
}),
want: func() *connect.Response[frontierv1beta1.ListCheckoutsResponse] {
createdAt := time.Now()
Expand Down Expand Up @@ -682,40 +667,12 @@ func TestConnectHandler_GetCheckout(t *testing.T) {
wantErrCode connect.Code
wantErrMsg error
}{
{
name: "should return error if org_id is empty",
setup: func(cs *mocks.CheckoutService, custSvc *mocks.CustomerService) {
cs.EXPECT().GetByID(mock.Anything, "test-checkout-id").Return(checkout.Checkout{}, errors.New("not found"))
},
req: connect.NewRequest(&frontierv1beta1.GetCheckoutRequest{
OrgId: "",
Id: "test-checkout-id",
}),
want: nil,
wantErr: true,
wantErrCode: connect.CodeInternal,
wantErrMsg: ErrInternalServerError,
},
{
name: "should return error if id is empty",
setup: func(cs *mocks.CheckoutService, custSvc *mocks.CustomerService) {
},
req: connect.NewRequest(&frontierv1beta1.GetCheckoutRequest{
OrgId: "test-org-id",
Id: "",
}),
want: nil,
wantErr: true,
wantErrCode: connect.CodeInvalidArgument,
wantErrMsg: ErrBadRequest,
},
{
name: "should return error if both org_id and id are empty",
setup: func(cs *mocks.CheckoutService, custSvc *mocks.CustomerService) {
},
req: connect.NewRequest(&frontierv1beta1.GetCheckoutRequest{
OrgId: "",
Id: "",
Id: "",
}),
want: nil,
wantErr: true,
Expand All @@ -728,8 +685,7 @@ func TestConnectHandler_GetCheckout(t *testing.T) {
cs.EXPECT().GetByID(mock.Anything, "test-checkout-id").Return(checkout.Checkout{}, errors.New("service error"))
},
req: connect.NewRequest(&frontierv1beta1.GetCheckoutRequest{
OrgId: "test-org-id",
Id: "test-checkout-id",
Id: "test-checkout-id",
}),
want: nil,
wantErr: true,
Expand All @@ -756,8 +712,7 @@ func TestConnectHandler_GetCheckout(t *testing.T) {
}, nil)
},
req: connect.NewRequest(&frontierv1beta1.GetCheckoutRequest{
OrgId: "test-org-id",
Id: "test-checkout-id",
Id: "test-checkout-id",
}),
want: func() *connect.Response[frontierv1beta1.GetCheckoutResponse] {
createdAt := time.Now()
Expand Down Expand Up @@ -800,8 +755,7 @@ func TestConnectHandler_GetCheckout(t *testing.T) {
}, nil)
},
req: connect.NewRequest(&frontierv1beta1.GetCheckoutRequest{
OrgId: "test-org-id",
Id: "test-checkout-id-2",
Id: "test-checkout-id-2",
}),
want: func() *connect.Response[frontierv1beta1.GetCheckoutResponse] {
createdAt := time.Now()
Expand Down
Loading