Skip to content

Commit

Permalink
fix: remove unreachable product fetch block (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
anujk14 authored Sep 2, 2024
1 parent 9565abb commit c9331fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
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

0 comments on commit c9331fc

Please sign in to comment.