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

     1  package subscriptionschedule
     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 TestSubscriptionScheduleCancel(t *testing.T) {
    12  	params := &stripe.SubscriptionScheduleCancelParams{
    13  		InvoiceNow: stripe.Bool(true),
    14  		Prorate:    stripe.Bool(true),
    15  	}
    16  	schedule, err := Cancel("sub_sched_123", params)
    17  	assert.Nil(t, err)
    18  	assert.NotNil(t, schedule)
    19  }
    20  
    21  func TestSubscriptionScheduleGet(t *testing.T) {
    22  	schedule, err := Get("sub_sched_123", nil)
    23  	assert.Nil(t, err)
    24  	assert.NotNil(t, schedule)
    25  }
    26  
    27  func TestSubscriptionScheduleList(t *testing.T) {
    28  	params := &stripe.SubscriptionScheduleListParams{
    29  		ReleasedAtRange: &stripe.RangeQueryParams{
    30  			GreaterThanOrEqual: 123456,
    31  		},
    32  	}
    33  	i := List(params)
    34  
    35  	// Verify that we can get at least one schedule
    36  	assert.True(t, i.Next())
    37  	assert.Nil(t, i.Err())
    38  	assert.NotNil(t, i.SubscriptionSchedule())
    39  	assert.NotNil(t, i.SubscriptionScheduleList())
    40  }
    41  
    42  func TestSubscriptionScheduleNew(t *testing.T) {
    43  	params := &stripe.SubscriptionScheduleParams{
    44  		Customer:     stripe.String("cus_123"),
    45  		StartDateNow: stripe.Bool(true),
    46  		Phases: []*stripe.SubscriptionSchedulePhaseParams{
    47  			{
    48  				Items: []*stripe.SubscriptionSchedulePhaseItemParams{
    49  					{
    50  						Plan:     stripe.String("plan_123"),
    51  						Quantity: stripe.Int64(10),
    52  					},
    53  					{
    54  						Plan:     stripe.String("plan_456"),
    55  						Quantity: stripe.Int64(20),
    56  					},
    57  				},
    58  				Trial: stripe.Bool(true),
    59  			},
    60  			{
    61  				Items: []*stripe.SubscriptionSchedulePhaseItemParams{
    62  					{
    63  						Plan:     stripe.String("plan_789"),
    64  						Quantity: stripe.Int64(30),
    65  					},
    66  				},
    67  			},
    68  		},
    69  		EndBehavior: stripe.String(string(stripe.SubscriptionScheduleEndBehaviorCancel)),
    70  	}
    71  	schedule, err := New(params)
    72  	assert.Nil(t, err)
    73  	assert.NotNil(t, schedule)
    74  }
    75  
    76  func TestSubscriptionScheduleRelease(t *testing.T) {
    77  	params := &stripe.SubscriptionScheduleReleaseParams{
    78  		PreserveCancelDate: stripe.Bool(true),
    79  	}
    80  	schedule, err := Release("sub_sched_123", params)
    81  	assert.Nil(t, err)
    82  	assert.NotNil(t, schedule)
    83  }
    84  
    85  func TestSubscriptionScheduleUpdate(t *testing.T) {
    86  	params := &stripe.SubscriptionScheduleParams{
    87  		Params: stripe.Params{
    88  			Metadata: map[string]string{
    89  				"foo": "bar",
    90  			},
    91  		},
    92  	}
    93  	schedule, err := Update("sub_sched_123", params)
    94  	assert.Nil(t, err)
    95  	assert.NotNil(t, schedule)
    96  }