This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params_test.go
115 lines (95 loc) · 2.74 KB
/
params_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package stripe_test
import (
"net/url"
"reflect"
"testing"
stripe "github.com/Onefootball/stripe-go"
. "github.com/Onefootball/stripe-go/testing"
)
func TestParamsWithExtras(t *testing.T) {
testCases := []struct {
InitialBody url.Values
Extras [][2]string
ExpectedBody url.Values
}{
{
InitialBody: url.Values{"foo": {"bar"}},
Extras: [][2]string{},
ExpectedBody: url.Values{"foo": {"bar"}},
},
{
InitialBody: url.Values{"foo": {"bar"}},
Extras: [][2]string{{"foo", "baz"}, {"other", "thing"}},
ExpectedBody: url.Values{"foo": {"bar", "baz"}, "other": {"thing"}},
},
}
for _, testCase := range testCases {
p := stripe.Params{}
for _, extra := range testCase.Extras {
p.AddExtra(extra[0], extra[1])
}
body := testCase.InitialBody
p.AppendTo(&body)
if !reflect.DeepEqual(body, testCase.ExpectedBody) {
t.Fatalf("Expected body of %v but got %v.", testCase.ExpectedBody, body)
}
}
}
func TestCheckinListParamsExpansion(t *testing.T) {
testCases := []struct {
InitialBody url.Values
Expand []string
ExpectedBody url.Values
}{
{
InitialBody: url.Values{"foo": {"bar"}},
Expand: []string{},
ExpectedBody: url.Values{"foo": {"bar"}},
},
{
InitialBody: url.Values{"foo": {"bar", "baz"}},
Expand: []string{"data", "data.foo"},
ExpectedBody: url.Values{"foo": {"bar", "baz"}, "expand[]": {"data", "data.foo"}},
},
}
for _, testCase := range testCases {
p := stripe.ListParams{}
for _, exp := range testCase.Expand {
p.Expand(exp)
}
body := testCase.InitialBody
p.AppendTo(&body)
if !reflect.DeepEqual(body, testCase.ExpectedBody) {
t.Fatalf("Expected body of %v but got %v.", testCase.ExpectedBody, body)
}
}
}
func TestCheckinListParamsToParams(t *testing.T) {
listParams := &stripe.ListParams{StripeAccount: TestMerchantID}
params := listParams.ToParams()
if params.StripeAccount != TestMerchantID {
t.Fatalf("Expected StripeAccount of %v but got %v.",
TestMerchantID, params.StripeAccount)
}
}
func TestCheckinParamsSetAccount(t *testing.T) {
p := &stripe.Params{}
p.SetAccount(TestMerchantID)
if p.Account != TestMerchantID {
t.Fatalf("Expected Account of %v but got %v.", TestMerchantID, p.Account)
}
if p.StripeAccount != TestMerchantID {
t.Fatalf("Expected StripeAccount of %v but got %v.", TestMerchantID, p.StripeAccount)
}
}
func TestCheckinParamsSetStripeAccount(t *testing.T) {
p := &stripe.Params{}
p.SetStripeAccount(TestMerchantID)
if p.StripeAccount != TestMerchantID {
t.Fatalf("Expected Account of %v but got %v.", TestMerchantID, p.StripeAccount)
}
// Check that we don't set the deprecated parameter.
if p.Account != "" {
t.Fatalf("Expected empty Account but got %v.", TestMerchantID)
}
}