This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
organizations_test.go
177 lines (158 loc) · 3.45 KB
/
organizations_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package packngo
import (
"log"
"testing"
)
func TestAccOrgList(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, stopRecord := setup(t)
defer stopRecord()
defer organizationTeardown(c)
rs := testProjectPrefix + randString8()
city := "foo"
addr := Address {
Address: "test",
ZipCode: "12345",
Country: "GB",
City: &city,
}
ocr := OrganizationCreateRequest{
Name: rs,
Description: "Managed by Packngo.",
Website: "http://example.com",
Twitter: "foo",
Address: addr,
}
org, _, err := c.Organizations.Create(&ocr)
if err != nil {
t.Fatal(err)
}
if org.Name != rs {
t.Fatalf("Expected new project name to be %s, not %s", rs, org.Name)
}
ol, _, err := c.Organizations.List(&ListOptions{PerPage: 1})
if err != nil {
t.Fatal(err)
}
found := false
for _, o := range ol {
if o.ID == org.ID {
found = true
break
}
}
if !found {
log.Println("Couldn't find created test org in org listing")
}
_, err = c.Organizations.Delete(org.ID)
if err != nil {
t.Fatal(err)
}
}
func TestAccOrgBasic(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, stopRecord := setup(t)
defer stopRecord()
defer organizationTeardown(c)
rs := testProjectPrefix + randString8()
city := "foo"
addr := Address{
Address: "test",
ZipCode: "12345",
Country: "GB",
City: &city,
}
ocr := OrganizationCreateRequest{
Name: rs,
Description: "Managed by Packngo.",
Website: "http://example.com",
Twitter: "foo",
Address: addr,
}
p, _, err := c.Organizations.Create(&ocr)
if err != nil {
t.Fatal(err)
}
if p.Name != rs {
t.Fatalf("Expected new project name to be %s, not %s", rs, p.Name)
}
rs = testProjectPrefix + randString8()
oDesc := "Managed by Packngo."
oWeb := "http://quux.example.com"
oTwi := "bar"
oCity := "bar"
oAddr := Address{
Address: "test 2",
ZipCode: "54321",
Country: "ES",
City: &oCity,
}
pur := OrganizationUpdateRequest{
Name: &rs,
Description: &oDesc,
Website: &oWeb,
Twitter: &oTwi,
Address: &oAddr,
}
org, _, err := c.Organizations.Update(p.ID, &pur)
if err != nil {
t.Fatal(err)
}
if org.Name != rs {
t.Fatalf("Expected the name of the updated project to be %s, not %s", rs, p.Name)
}
gotOrg, _, err := c.Organizations.Get(org.ID, nil)
if err != nil {
t.Fatal(err)
}
if gotOrg.Name != rs {
t.Fatalf("Expected the name of the GOT project to be %s, not %s", rs, gotOrg.Name)
}
_, _, err = c.Organizations.ListEvents(org.ID, nil)
if err != nil {
t.Fatal(err)
}
_, err = c.Organizations.Delete(org.ID)
if err != nil {
t.Fatal(err)
}
}
func TestAccOrgListPaymentMethods(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
// setup
c, stopRecord := setup(t)
defer stopRecord()
defer organizationTeardown(c)
rs := testProjectPrefix + randString8()
city := "foo"
addr := Address{
Address: "test",
ZipCode: "12345",
Country: "GB",
City: &city,
}
ocr := OrganizationCreateRequest{
Name: rs,
Description: "Managed by Packngo.",
Website: "http://example.com",
Twitter: "foo",
Address: addr,
}
org, _, err := c.Organizations.Create(&ocr)
if err != nil {
t.Fatal(err)
}
// tests
pms, _, err := c.Organizations.ListPaymentMethods(org.ID)
if err != nil {
t.Fatal("error: ", err)
}
if len(pms) != 0 {
t.Fatal("the new test org should have no payment methods")
}
// teardown
_, err = c.Organizations.Delete(org.ID)
if err != nil {
t.Fatal(err)
}
}