github.com/stripe/stripe-go/v76@v76.25.0/subschedule_test.go (about) 1 package stripe 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 assert "github.com/stretchr/testify/require" 8 "github.com/stripe/stripe-go/v76/form" 9 ) 10 11 func TestSubscriptionScheduleParams_AppendTo(t *testing.T) { 12 { 13 params := &SubscriptionScheduleParams{StartDateNow: Bool(true)} 14 body := &form.Values{} 15 form.AppendTo(body, params) 16 t.Logf("body = %+v", body) 17 assert.Equal(t, []string{"now"}, body.Get("start_date")) 18 } 19 } 20 21 func TestSubscriptionSchedule_UnmarshalJSON(t *testing.T) { 22 // Unmarshals from a JSON string 23 { 24 var v SubscriptionSchedule 25 err := json.Unmarshal([]byte(`"sub_sched_123"`), &v) 26 assert.NoError(t, err) 27 assert.Equal(t, "sub_sched_123", v.ID) 28 } 29 30 // Unmarshals from a JSON object 31 { 32 v := SubscriptionSchedule{ID: "sub_sched_123"} 33 data, err := json.Marshal(&v) 34 assert.NoError(t, err) 35 36 err = json.Unmarshal(data, &v) 37 assert.NoError(t, err) 38 assert.Equal(t, "sub_sched_123", v.ID) 39 } 40 }