forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplan_integration_test.go
79 lines (73 loc) · 1.4 KB
/
plan_integration_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
package braintree
import (
"testing"
)
// This test will fail unless you set up your Braintree sandbox account correctly. See TESTING.md for details.
func TestPlan(t *testing.T) {
g := testGateway.Plan()
plans, err := g.All()
if err != nil {
t.Fatal(err)
}
if len(plans) == 0 {
t.Fatal(plans)
}
var plan *Plan
for _, p := range plans {
if p.Id == "test_plan" {
plan = p
break
}
}
t.Log(plan)
if plan == nil {
t.Fatal("plan not found")
}
if x := plan.Id; x != "test_plan" {
t.Fatal(x)
}
if x := plan.MerchantId; x == "" {
t.Fatal(x)
}
if x := plan.BillingFrequency; !x.Valid || x.Int64 != 1 {
t.Fatal(x)
}
if x := plan.CurrencyISOCode; x != "USD" {
t.Fatal(x)
}
if x := plan.Description; x != "test_plan_desc" {
t.Fatal(x)
}
if x := plan.Name; x != "test_plan_name" {
t.Fatal(x)
}
if x := plan.NumberOfBillingCycles; !x.Valid || x.Int64 != 2 {
t.Fatal(x)
}
if x := plan.Price; x.Cmp(NewDecimal(1000, 2)) != 0 {
t.Fatal(x)
}
if x := plan.TrialDuration; !x.Valid || x.Int64 != 14 {
t.Fatal(x)
}
if x := plan.TrialDurationUnit; x != "day" {
t.Fatal(x)
}
if x := plan.TrialPeriod; !x.Valid || !x.Bool {
t.Fatal(x)
}
if x := plan.CreatedAt; x == nil {
t.Fatal(x)
}
if x := plan.UpdatedAt; x == nil {
t.Fatal(x)
}
// Find
plan2, err := g.Find("test_plan_2")
if err != nil {
t.Fatal(err)
}
if plan2.Id != "test_plan_2" {
t.Fatal(plan2)
}
}