-
Notifications
You must be signed in to change notification settings - Fork 461
/
order_test.go
62 lines (55 loc) · 1.7 KB
/
order_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package stripe
import (
"encoding/json"
"testing"
assert "github.com/stretchr/testify/require"
"github.com/stripe/stripe-go/form"
)
func TestOrderUpdateParams_AppendTo(t *testing.T) {
{
params := &OrderUpdateParams{
Status: String("fulfilled"),
Shipping: &OrderUpdateShippingParams{
Carrier: String("USPS"),
TrackingNumber: String("123"),
},
}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"fulfilled"}, body.Get("status"))
assert.Equal(t, []string{"USPS"}, body.Get("shipping[carrier]"))
assert.Equal(t, []string{"123"}, body.Get("shipping[tracking_number]"))
}
}
func TestShipping_MarshalJSON(t *testing.T) {
{
shipping := &Shipping{
Name: "name",
Phone: "phone",
Carrier: "USPS",
TrackingNumber: "tracking.123",
Address: &Address{
Line1: "123 Market Street",
City: "San Francisco",
State: "CA",
Country: "USA",
},
}
d, err := json.Marshal(shipping)
assert.NoError(t, err)
assert.NotNil(t, d)
unmarshalled := &Shipping{}
err = json.Unmarshal(d, unmarshalled)
assert.NoError(t, err)
assert.Equal(t, unmarshalled.Name, shipping.Name)
assert.Equal(t, unmarshalled.Phone, shipping.Phone)
assert.Equal(t, unmarshalled.Carrier, shipping.Carrier)
assert.Equal(t, unmarshalled.TrackingNumber, shipping.TrackingNumber)
assert.NotNil(t, unmarshalled.Address)
assert.Equal(t, unmarshalled.Address.Line1, shipping.Address.Line1)
assert.Equal(t, unmarshalled.Address.City, shipping.Address.City)
assert.Equal(t, unmarshalled.Address.State, shipping.Address.State)
assert.Equal(t, unmarshalled.Address.Country, shipping.Address.Country)
}
}