github.com/stripe/stripe-go/v76@v76.25.0/quote/client_test.go (about) 1 package quote 2 3 import ( 4 "io/ioutil" 5 "testing" 6 7 assert "github.com/stretchr/testify/require" 8 stripe "github.com/stripe/stripe-go/v76" 9 _ "github.com/stripe/stripe-go/v76/testing" 10 ) 11 12 func TestQuoteGet(t *testing.T) { 13 quote, err := Get("qt_123", nil) 14 assert.Nil(t, err) 15 assert.NotNil(t, quote) 16 } 17 18 func TestQuoteList(t *testing.T) { 19 i := List(&stripe.QuoteListParams{}) 20 21 // Verify that we can get at least one quote 22 assert.True(t, i.Next()) 23 assert.Nil(t, i.Err()) 24 assert.NotNil(t, i.Quote()) 25 assert.NotNil(t, i.QuoteList()) 26 } 27 28 func TestQuoteListComputedUpfrontLineItems(t *testing.T) { 29 i := ListComputedUpfrontLineItems(&stripe.QuoteListComputedUpfrontLineItemsParams{ 30 Quote: stripe.String("qt_123"), 31 }) 32 33 // Verify that we can get at least line item 34 assert.True(t, i.Next()) 35 assert.Nil(t, i.Err()) 36 assert.NotNil(t, i.LineItem()) 37 assert.NotNil(t, i.LineItemList()) 38 } 39 40 func TestQuoteListLineItems(t *testing.T) { 41 i := ListLineItems(&stripe.QuoteListLineItemsParams{ 42 Quote: stripe.String("qt_123"), 43 }) 44 45 // Verify that we can get at least one quote 46 assert.True(t, i.Next()) 47 assert.Nil(t, i.Err()) 48 assert.NotNil(t, i.LineItem()) 49 assert.NotNil(t, i.LineItemList()) 50 } 51 52 func TestQuoteNew(t *testing.T) { 53 quote, err := New(&stripe.QuoteParams{ 54 CollectionMethod: stripe.String(string(stripe.QuoteCollectionMethodChargeAutomatically)), 55 Customer: stripe.String("cus_123"), 56 }) 57 assert.Nil(t, err) 58 assert.NotNil(t, quote) 59 } 60 61 func TestQuotePDF(t *testing.T) { 62 stream, err := PDF("qt_123", &stripe.QuotePDFParams{}) 63 assert.Nil(t, err) 64 assert.NotNil(t, stream) 65 body, err := ioutil.ReadAll(stream.LastResponse.Body) 66 assert.Nil(t, err) 67 assert.NotNil(t, body) 68 assert.Equal(t, []byte("Stripe binary response"), body) 69 } 70 71 func TestQuoteUpdate(t *testing.T) { 72 quote, err := Update("qt_123", &stripe.QuoteParams{ 73 Params: stripe.Params{ 74 Metadata: map[string]string{ 75 "foo": "bar", 76 }, 77 }, 78 }) 79 assert.Nil(t, err) 80 assert.NotNil(t, quote) 81 } 82 83 func TestQuoteFinalizeQuote(t *testing.T) { 84 quote, err := FinalizeQuote("qt_123", &stripe.QuoteFinalizeQuoteParams{}) 85 assert.Nil(t, err) 86 assert.NotNil(t, quote) 87 }