forked from Vonage/vonage-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
numberinsight_test.go
187 lines (163 loc) · 4.72 KB
/
numberinsight_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
178
179
180
181
182
183
184
185
186
187
package vonage
import (
"net/http"
"testing"
"github.com/jarcoal/httpmock"
)
func TestNINewClient(*testing.T) {
auth := CreateAuthFromKeySecret("123", "456")
NewNumberInsightClient(auth)
}
func TestNIBasic(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", "https://api.nexmo.com/ni/basic/json",
func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `
{
"status": 0,
"status_message": "Success",
"request_id": "aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"international_format_number": "447700900000",
"national_format_number": "07700 900000",
"country_code": "GB",
"country_code_iso3": "GBR",
"country_name": "United Kingdom",
"country_prefix": "44"
}
`,
)
resp.Header.Add("Content-Type", "application/json")
return resp, nil
},
)
auth := CreateAuthFromKeySecret("12345678", "456")
client := NewNumberInsightClient(auth)
response, _, _ := client.Basic("44777000777", NiOpts{})
message := "Status: " + response.StatusMessage
if message != "Status: Success" {
t.Errorf("Number insight basic lookup failed")
}
}
func TestNIBasicWithOpts(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", "https://api.nexmo.com/ni/basic/json",
func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `
{
"status": 0,
"status_message": "Success",
"request_id": "aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"international_format_number": "447700900000",
"national_format_number": "07700 900000",
"country_code": "GB",
"country_code_iso3": "GBR",
"country_name": "United Kingdom",
"country_prefix": "44"
}
`,
)
resp.Header.Add("Content-Type", "application/json")
return resp, nil
},
)
auth := CreateAuthFromKeySecret("12345678", "456")
client := NewNumberInsightClient(auth)
response, _, _ := client.Basic("44777000777", NiOpts{Country: "US"})
message := "Status: " + response.StatusMessage
if message != "Status: Success" {
t.Errorf("Number insight basic lookup failed")
}
}
func TestNIAsync(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", "https://api.nexmo.com/ni/advanced/async/json",
func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `
{
"request_id": "aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"number": "447700900000",
"remaining_balance": "1.23456789",
"request_price": "0.01500000",
"status": 0,
"error_text": "Success"
}
`,
)
resp.Header.Add("Content-Type", "application/json")
return resp, nil
},
)
auth := CreateAuthFromKeySecret("12345678", "456")
client := NewNumberInsightClient(auth)
response, _, _ := client.AdvancedAsync("44777000777", "https://example.com/webhook/ni", NiOpts{Country: "US"})
message := "Price: " + response.RequestPrice
if message != "Price: 0.01500000" {
t.Errorf("Number insight advanced async request failed")
}
}
func TestNIStandard(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", "https://api.nexmo.com/ni/standard/json",
func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `
{
"status": 0,
"status_message": "Success",
"request_id": "aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"international_format_number": "447700900000",
"national_format_number": "07700 900000",
"country_code": "GB",
"country_code_iso3": "GBR",
"country_name": "United Kingdom",
"country_prefix": "44",
"request_price": "0.04000000",
"refund_price": "0.01500000",
"remaining_balance": "1.23456789",
"current_carrier": {
"network_code": "12345",
"name": "Acme Inc",
"country": "GB",
"network_type": "mobile"
},
"original_carrier": {
"network_code": "12345",
"name": "Acme Inc",
"country": "GB",
"network_type": "mobile"
},
"ported": "not_ported",
"roaming": {
"status": "roaming",
"roaming_country_code": "US",
"roaming_network_code": "12345",
"roaming_network_name": "Acme Inc"
},
"caller_identity": {
"caller_type": "consumer",
"caller_name": "John Smith",
"first_name": "John",
"last_name": "Smith"
},
"caller_name": "John Smith",
"last_name": "Smith",
"first_name": "John",
"caller_type": "consumer"
}
`,
)
resp.Header.Add("Content-Type", "application/json")
return resp, nil
},
)
auth := CreateAuthFromKeySecret("12345678", "456")
client := NewNumberInsightClient(auth)
response, _, _ := client.Standard("44777000777", NiOpts{Country: "US"})
message := "Price: " + response.RequestPrice
if message != "Price: 0.04000000" {
t.Errorf("Number insight standard lookup failed")
}
}