github.com/stripe/stripe-go/v76@v76.25.0/quote_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 TestQuoteSubscriptionDataParams_AppendTo(t *testing.T) {
    12  	{
    13  		params := &QuoteSubscriptionDataParams{EffectiveDateCurrentPeriodEnd: Bool(true)}
    14  		body := &form.Values{}
    15  		form.AppendTo(body, params)
    16  		t.Logf("body = %+v", body)
    17  		assert.Equal(t, []string{"current_period_end"}, body.Get("effective_date"))
    18  	}
    19  }
    20  
    21  func TestQuote_UnmarshalJSON(t *testing.T) {
    22  	// Unmarshals from a JSON string
    23  	{
    24  		var v Quote
    25  		err := json.Unmarshal([]byte(`"qt_123"`), &v)
    26  		assert.NoError(t, err)
    27  		assert.Equal(t, "qt_123", v.ID)
    28  	}
    29  
    30  	// Unmarshals from a JSON object
    31  	{
    32  		v := Quote{ID: "qt_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, "qt_123", v.ID)
    39  	}
    40  }