Skip to content

Commit

Permalink
Fix URL to delete coupon redemptions (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
everdance authored Feb 11, 2020
1 parent 9cc01b2 commit fa80930
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions mock/redemptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type RedemptionsService struct {
OnRedeem func(ctx context.Context, code string, r recurly.CouponRedemption) (*recurly.Redemption, error)
RedeemInvoked bool

OnDelete func(ctx context.Context, accountCode string) error
OnDelete func(ctx context.Context, accountCode, couponCode string) error
DeleteInvoked bool
}

Expand All @@ -46,7 +46,7 @@ func (m *RedemptionsService) Redeem(ctx context.Context, code string, r recurly.
return m.OnRedeem(ctx, code, r)
}

func (m *RedemptionsService) Delete(ctx context.Context, accountCode string) error {
func (m *RedemptionsService) Delete(ctx context.Context, accountCode, couponCode string) error {
m.DeleteInvoked = true
return m.OnDelete(ctx, accountCode)
return m.OnDelete(ctx, accountCode, couponCode)
}
6 changes: 3 additions & 3 deletions redemptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type RedemptionsService interface {
// of the coupon. See Recurly's documentation for details.
//
// https://dev.recurly.com/docs/remove-a-coupon-from-an-account
Delete(ctx context.Context, accountCode string) error
Delete(ctx context.Context, accountCode, couponCode string) error
}

// Redemptions constants.
Expand Down Expand Up @@ -148,8 +148,8 @@ func (s *redemptionsImpl) Redeem(ctx context.Context, code string, r CouponRedem
return &dst, nil
}

func (s *redemptionsImpl) Delete(ctx context.Context, accountCode string) error {
path := fmt.Sprintf("/accounts/%s/redemption", accountCode)
func (s *redemptionsImpl) Delete(ctx context.Context, accountCode, couponCode string) error {
path := fmt.Sprintf("/accounts/%s/redemptions/%s", accountCode, couponCode)
req, err := s.client.newRequest("DELETE", path, nil)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions redemptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ func TestRedemptions_Delete(t *testing.T) {
client, s := recurly.NewTestServer()
defer s.Close()

s.HandleFunc("DELETE", "/v2/accounts/1/redemption", func(w http.ResponseWriter, r *http.Request) {
s.HandleFunc("DELETE", "/v2/accounts/1/redemptions/30_off", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
}, t)

if err := client.Redemptions.Delete(context.Background(), "1"); !s.Invoked {
if err := client.Redemptions.Delete(context.Background(), "1", "30_off"); !s.Invoked {
t.Fatal("expected fn invocation")
} else if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit fa80930

Please sign in to comment.