github.com/stripe/stripe-go/v76@v76.25.0/coupon/client_test.go (about)

     1  package coupon
     2  
     3  import (
     4  	"testing"
     5  
     6  	assert "github.com/stretchr/testify/require"
     7  	stripe "github.com/stripe/stripe-go/v76"
     8  	_ "github.com/stripe/stripe-go/v76/testing"
     9  )
    10  
    11  func TestCouponDel(t *testing.T) {
    12  	coupon, err := Del("25OFF", nil)
    13  	assert.Nil(t, err)
    14  	assert.NotNil(t, coupon)
    15  }
    16  
    17  func TestCouponGet(t *testing.T) {
    18  	coupon, err := Get("25OFF", nil)
    19  	assert.Nil(t, err)
    20  	assert.NotNil(t, coupon)
    21  }
    22  
    23  func TestCouponList(t *testing.T) {
    24  	i := List(&stripe.CouponListParams{})
    25  
    26  	// Verify that we can get at least one coupon
    27  	assert.True(t, i.Next())
    28  	assert.Nil(t, i.Err())
    29  	assert.NotNil(t, i.Coupon())
    30  	assert.NotNil(t, i.CouponList())
    31  }
    32  
    33  func TestCouponNew(t *testing.T) {
    34  	coupon, err := New(&stripe.CouponParams{
    35  		AppliesTo: &stripe.CouponAppliesToParams{
    36  			Products: stripe.StringSlice([]string{
    37  				"prod_123",
    38  				"prod_abc",
    39  			}),
    40  		},
    41  		Currency:         stripe.String(string(stripe.CurrencyUSD)),
    42  		Duration:         stripe.String(string(stripe.CouponDurationRepeating)),
    43  		DurationInMonths: stripe.Int64(3),
    44  		ID:               stripe.String("25OFF"),
    45  		PercentOff:       stripe.Float64(12.5),
    46  	})
    47  	assert.Nil(t, err)
    48  	assert.NotNil(t, coupon)
    49  }
    50  
    51  func TestCouponUpdate(t *testing.T) {
    52  	coupon, err := Update("25OFF", &stripe.CouponParams{
    53  		Params: stripe.Params{
    54  			Metadata: map[string]string{
    55  				"foo": "bar",
    56  			},
    57  		},
    58  	})
    59  	assert.Nil(t, err)
    60  	assert.NotNil(t, coupon)
    61  }