Skip to content
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

fix: remove unreachable product fetch block #759

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 3 additions & 13 deletions billing/entitlement/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package entitlement

import (
"context"
"errors"

"github.com/raystack/frontier/billing/plan"

Expand Down Expand Up @@ -48,8 +47,8 @@ func NewEntitlementService(subscriptionService SubscriptionService,
}
}

// Check checks if the customer has access to the feature or product
func (s *Service) Check(ctx context.Context, customerID, featureOrProductID string) (bool, error) {
// Check checks if the customer has access to the feature
func (s *Service) Check(ctx context.Context, customerID, featureID string) (bool, error) {
// get all subscriptions for the customer
subs, err := s.subscriptionService.List(ctx, subscription.Filter{
CustomerID: customerID,
Expand All @@ -59,7 +58,7 @@ func (s *Service) Check(ctx context.Context, customerID, featureOrProductID stri
}

// get the feature
feature, err := s.productService.GetFeatureByID(ctx, featureOrProductID)
feature, err := s.productService.GetFeatureByID(ctx, featureID)
if err != nil {
return false, err
}
Expand All @@ -72,15 +71,6 @@ func (s *Service) Check(ctx context.Context, customerID, featureOrProductID stri
return false, err
}

// could be product ID as well
asProduct, err := s.productService.GetByID(ctx, featureOrProductID)
if err != nil && !errors.Is(err, product.ErrProductNotFound) {
return false, err
}
if asProduct.ID != "" {
products = append(products, asProduct)
}

// check if the product is in any of the subscriptions
for _, sub := range subs {
if !sub.IsActive() {
Expand Down
2 changes: 0 additions & 2 deletions billing/entitlement/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ func TestService_Check(t *testing.T) {
PlanIDs: []string{"plan1"},
},
}, nil)
mockProduct.EXPECT().GetByID(ctx, "feature2").Return(product.Product{}, nil)

return s
},
Expand Down Expand Up @@ -269,7 +268,6 @@ func TestService_Check(t *testing.T) {
PlanIDs: []string{"plan2"},
},
}, nil)
mockProduct.EXPECT().GetByID(ctx, "feature3").Return(product.Product{}, nil)

return s
},
Expand Down
Loading