This repository was archived by the owner on Nov 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcard_test.go
More file actions
137 lines (130 loc) · 5.14 KB
/
card_test.go
File metadata and controls
137 lines (130 loc) · 5.14 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package stripe
import (
"io/ioutil"
"strconv"
"strings"
"testing"
"time"
)
var (
VALID = &Card{
Number: "4242424242424242",
ExpMonth: 3,
ExpYear: time.Now().Year() + 4,
CVC: "123",
Name: "Oso de Peluche",
AddressLine1: "123 Awesome Street",
AddressLine2: "Apartment 5",
Zip: "12345",
State: "",
AddressCountry: "Spain",
}
INVALID = &Card{
Number: "2",
ExpMonth: 3,
ExpYear: time.Now().Year() - 1,
CVC: "-1",
Name: "Oso de Peluche", // TODO: Come up with an invalid value
AddressLine1: "123 Awesome Street", // TODO: Come up with an invalid value
AddressLine2: "Apartment 5", // TODO: Come up with an invalid value
Zip: "12345", // TODO: Come up with an invalid value
State: "", // TODO: Come up with an invalid value
AddressCountry: "Spain", // TODO: come up with an invalid value
}
key, err = ioutil.ReadFile("key")
)
func TestCreateCardToken(t *testing.T) {
if err != nil {
t.Fatalf("err = %v, want %v", err, nil)
}
API := New(string(key))
var token *Token
token, err = API.CreateToken(VALID)
if err != nil {
t.Fatalf("err = %v, want %v", err, nil)
}
if token == nil {
t.Fatalf("token is nil, should be set")
}
t.Logf("token = %v", token)
if token.Card.ExpYear != VALID.ExpYear {
t.Errorf("ExpYear is %v, expected %v", token.Card.ExpYear, VALID.ExpYear)
}
if token.Card.ExpMonth != VALID.ExpMonth {
t.Errorf("ExpMonth is %v, expected %v", strconv.Itoa(token.Card.ExpMonth), VALID.ExpMonth)
}
if !strings.HasSuffix(VALID.Number, token.Card.LastFour) {
t.Errorf("token.Card.LastFour is %v, expected %v%v%v%v", token.Card.LastFour, VALID.Number[len(VALID.Number)-1], VALID.Number[len(VALID.Number)-2], VALID.Number[len(VALID.Number)-3], VALID.Number[len(VALID.Number)-4])
}
if token.Card.Name != VALID.Name {
t.Errorf("token.Card.Name is %v, expected %v", token.Card.Name, VALID.Name)
}
if token.Card.AddressCountry != VALID.AddressCountry {
t.Error("token.Card.AddressCountry is %v, expected %v", token.Card.AddressCountry, VALID.AddressCountry)
}
if token.Card.AddressLine1 != VALID.AddressLine1 {
t.Error("token.Card.AddressLine1 is %v, expected %v", token.Card.AddressLine1, VALID.AddressLine1)
}
if token.Card.AddressLine2 != VALID.AddressLine2 {
t.Error("token.Card.AddressLine2 is %v, expected %v", token.Card.AddressLine2, VALID.AddressLine2)
}
if token.Card.Zip != VALID.Zip {
t.Error("token.Card.Zip is %v, expected %v", token.Card.Zip, VALID.Zip)
}
if token.Card.State != VALID.State {
t.Error("token.Card.State is %v, expected %v", token.Card.State, VALID.State)
}
}
// TODO: Test with every permutation of values
// TODO: Update this test.
/*func TestGetCardToken(t *testing.T) {
if err != nil {
t.Fatalf("err = %v, want %v", err, nil)
}
API := New(string(key))
var token, token2 *CardToken
token, err = API.CreateCardTokenWithAll(VALID.Number, VALID.ExpMonth, VALID.ExpYear, VALID.CVC, VALID.Name, VALID.Address1, VALID.Address2, VALID.Zip, VALID.State, VALID.Country)
if err != nil {
t.Fatalf("err = %v, want %v", err, nil)
}
if token == nil {
t.Fatalf("token is nil, should be set")
}
if token.ID == "" {
t.Fatalf("token.ID not set")
}
token2, err = API.GetCardToken(token.ID)
if err != nil {
t.Fatalf("err = %v, want %v", err, nil)
}
if token2 == nil {
t.Fatalf("token2 is nil, should be set")
}
if token.Card.ExpYear != token2.Card.ExpYear {
t.Errorf("ExpYear is %v, expected %v", token2.Card.ExpYear, token.Card.ExpYear)
}
if token.Card.ExpMonth != token2.Card.ExpMonth {
t.Errorf("ExpMonth is %v, expected %v", token2.Card.ExpMonth, token.Card.ExpMonth)
}
if token.Card.LastFour != token2.Card.LastFour {
t.Errorf("token2.Card.LastFour is %v, expected %v", token2.Card.LastFour, token.Card.LastFour)
}
if token.Card.Name != token2.Card.Name {
t.Errorf("token2.Card.Name is %v, expected %v", token2.Card.Name, token.Card.Name)
}
if token.Card.AddressCountry != token2.Card.AddressCountry {
t.Error("token2.Card.AddressCountry is %v, expected %v", token2.Card.AddressCountry, token.Card.Country)
}
if token.Card.Address1 != token2.Card.Address1 {
t.Error("token2.Card.Address1 is %v, expected %v", token2.Card.Address1, token.Card.Address1)
}
if token.Card.Address2 != token2.Card.Address2 {
t.Error("token2.Card.Address2 is %v, expected %v", token2.Card.Address2, token.Card.Address2)
}
if token.Card.Zip != token2.Card.Zip {
t.Error("token2.Card.Zip is %v, expected %v", token2.Card.Zip, token.Card.Zip)
}
if token.Card.State != token2.Card.State {
t.Error("token2.Card.State is %v, expected %v", token2.Card.State, token.Card.State)
}
}*/