This repository has been archived by the owner on Dec 27, 2018. It is now read-only.
forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
charge_test.go
70 lines (60 loc) · 1.57 KB
/
charge_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
package stripe
import (
"encoding/json"
"testing"
assert "github.com/stretchr/testify/require"
"github.com/stripe/stripe-go/form"
)
func TestCharge_UnmarshalJSON(t *testing.T) {
// Unmarshals from a JSON string
{
var v Charge
err := json.Unmarshal([]byte(`"ch_123"`), &v)
assert.NoError(t, err)
assert.Equal(t, "ch_123", v.ID)
}
// Unmarshals from a JSON object
{
v := Charge{ID: "ch_123"}
data, err := json.Marshal(&v)
assert.NoError(t, err)
err = json.Unmarshal(data, &v)
assert.NoError(t, err)
assert.Equal(t, "ch_123", v.ID)
}
}
func TestChargeOutcomeRule_UnmarshalJSON(t *testing.T) {
// Unmarshals from a JSON string
{
var v ChargeOutcomeRule
err := json.Unmarshal([]byte(`"ssr_123"`), &v)
assert.NoError(t, err)
assert.Equal(t, "ssr_123", v.ID)
}
// Unmarshals from a JSON object
{
v := ChargeOutcomeRule{ID: "ssr_123"}
data, err := json.Marshal(&v)
assert.NoError(t, err)
err = json.Unmarshal(data, &v)
assert.NoError(t, err)
assert.Equal(t, "ssr_123", v.ID)
}
}
func TestChargeParams_AppendTo(t *testing.T) {
{
params := &ChargeParams{Amount: Int64(123)}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"123"}, body.Get("amount"))
}
{
params := &ChargeParams{Source: &SourceParams{Card: &CardParams{Number: String("4242424242424242")}}}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"4242424242424242"}, body.Get("source[number]"))
assert.Equal(t, []string{"card"}, body.Get("source[object]"))
}
}