-
Notifications
You must be signed in to change notification settings - Fork 23
/
numbers_test.go
146 lines (116 loc) · 3.23 KB
/
numbers_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
package plivo
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNumberService_Create(t *testing.T) {
expectResponse("NumberCreateResponse.json", 202)
if _, err := client.Numbers.Create(NumberCreateParams{}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err := client.Numbers.Create(NumberCreateParams{})
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "POST", "Number")
}
func TestNumberService_Update(t *testing.T) {
expectResponse("NumberUpdateResponse.json", 202)
NumberId := "NumberId"
if _, err := client.Numbers.Update(NumberId, NumberUpdateParams{}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err := client.Numbers.Update(NumberId, NumberUpdateParams{})
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "POST", "Number/%s", NumberId)
}
func TestNumberService_List(t *testing.T) {
expectResponse("NumberListResponse.json", 200)
if _, err := client.Numbers.List(NumberListParams{}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err := client.Numbers.List(NumberListParams{})
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "GET", "Number")
}
func TestNumberService_Get(t *testing.T) {
expectResponse("NumberGetResponse.json", 200)
NumberId := "NumberId"
number, err := client.Numbers.Get(NumberId)
assert.Equal(t, number.ID(), number.Number)
if err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err = client.Numbers.Get(NumberId)
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "GET", "Number/%s", NumberId)
}
func TestNumberService_Delete(t *testing.T) {
expectResponse("", 204)
NumberId := "NumberId"
if err := client.Numbers.Delete(NumberId); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
err := client.Numbers.Delete(NumberId)
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "DELETE", "Number/%s", NumberId)
}
func TestPhoneNumberService_Create(t *testing.T) {
expectResponse("PhoneNumberCreateResponse.json", 202)
if _, err := client.PhoneNumbers.Create("123", PhoneNumberCreateParams{}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err := client.PhoneNumbers.Create("123", PhoneNumberCreateParams{})
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "POST", "PhoneNumber/%s", "123")
}
func TestPhoneNumberService_List(t *testing.T) {
expectResponse("PhoneNumberListResponse.json", 200)
if _, err := client.PhoneNumbers.List(PhoneNumberListParams{}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err := client.PhoneNumbers.List(PhoneNumberListParams{})
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "GET", "PhoneNumber")
}