forked from kevinburke/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prices_voice_test.go
208 lines (190 loc) · 6.89 KB
/
prices_voice_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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package twilio
import (
"context"
"net/url"
"testing"
)
func TestGetVoicePriceUS(t *testing.T) {
t.Parallel()
client, server := getServer(voicePriceUS)
defer server.Close()
isoCountry := "US"
expectedCountryName := "United States"
expectedPriceUnit := "USD"
voicePrice, err := client.Pricing.Voice.Countries.Get(context.Background(), isoCountry, nil)
if err != nil {
t.Fatal(err)
}
if voicePrice == nil {
t.Fatal("expected voice price to be returned")
}
if voicePrice.Country != expectedCountryName {
t.Errorf("Expected voice price country to be %s, but got %s\n", expectedCountryName, voicePrice.Country)
}
if voicePrice.IsoCountry != isoCountry {
t.Errorf("Expected voice price iso country to be %s, but got %s\n", isoCountry, voicePrice.IsoCountry)
}
if voicePrice.PriceUnit != expectedPriceUnit {
t.Errorf("Expected voice price unit to be %s, but got %s\n", expectedPriceUnit, voicePrice.PriceUnit)
}
if voicePrice.InboundCallPrices == nil {
t.Error("Expected voice price to contain InboundCallPrices")
}
if voicePrice.OutboundPrefixPrices == nil {
t.Error("Expected voice price to contain OutboundPrefixPrices")
}
inboundPriceMap := make(map[string]bool)
for _, inPrice := range voicePrice.InboundCallPrices {
inboundPriceMap[inPrice.NumberType] = true
}
// inboundPriceMap => map[local:true toll free:true]
_, ok := inboundPriceMap["local"]
if ok == false {
t.Error("Expected inbound price to contain a price for local calls")
}
outboundDestinationPrefixPriceMap := make(map[string]bool)
outboundOriginationPrefixPriceMap := make(map[string]bool)
for _, outPrice := range voicePrice.OutboundPrefixPrices {
for _, prefix := range outPrice.DestinationPrefixes {
outboundDestinationPrefixPriceMap[prefix] = true
}
for _, prefix := range outPrice.OriginationPrefixes {
outboundOriginationPrefixPriceMap[prefix] = true
}
}
// outboundDestinationPrefixPriceMap => map[1907:true 1844:true 1866:true 1877:true 1:true 1808:true 1800:true 1855:true 1888:true]
// outboundOriginationPrefixPriceMap => map[ALL:true]
_, ok = outboundDestinationPrefixPriceMap["1"]
if ok == false {
t.Error("Expected outbound price to contain a price for the destination prefix 1")
}
_, ok = outboundOriginationPrefixPriceMap["ALL"]
if ok == false {
t.Error("Expected outbound price to contain a price for the origination prefix ALL")
}
}
func TestGetVoicePriceGB(t *testing.T) {
t.Parallel()
client, server := getServer(voicePricesGB)
defer server.Close()
isoCountry := "GB"
expectedCountryName := "United Kingdom"
expectedPriceUnit := "USD"
voicePrice, err := client.Pricing.Voice.Countries.Get(context.Background(), isoCountry, nil)
if err != nil {
t.Fatal(err)
}
if voicePrice == nil {
t.Fatal("expected voice price to be returned")
}
if voicePrice.Country != expectedCountryName {
t.Errorf("Expected voice price country to be %s, but got %s\n", expectedCountryName, voicePrice.Country)
}
if voicePrice.IsoCountry != isoCountry {
t.Errorf("Expected voice price iso country to be %s, but got %s\n", isoCountry, voicePrice.IsoCountry)
}
if voicePrice.PriceUnit != expectedPriceUnit {
t.Errorf("Expected voice price unit to be %s, but got %s\n", expectedPriceUnit, voicePrice.PriceUnit)
}
if voicePrice.InboundCallPrices == nil {
t.Error("Expected voice price to contain InboundCallPrices")
}
if voicePrice.OutboundPrefixPrices == nil {
t.Error("Expected voice price to contain OutboundPrefixPrices")
}
inboundPriceMap := make(map[string]bool)
for _, inPrice := range voicePrice.InboundCallPrices {
inboundPriceMap[inPrice.NumberType] = true
}
_, ok := inboundPriceMap["local"]
if ok == false {
t.Error("Expected inbound price to contain a price for local calls")
}
outboundDestinationPrefixPriceMap := make(map[string]bool)
outboundOriginationPrefixPriceMap := make(map[string]bool)
for _, outPrice := range voicePrice.OutboundPrefixPrices {
for _, prefix := range outPrice.DestinationPrefixes {
outboundDestinationPrefixPriceMap[prefix] = true
}
for _, prefix := range outPrice.OriginationPrefixes {
outboundOriginationPrefixPriceMap[prefix] = true
}
}
_, ok = outboundDestinationPrefixPriceMap["44"]
if ok == false {
t.Error("Expected outbound price to contain a price for the prefix 44")
}
_, ok = outboundOriginationPrefixPriceMap["ALL"]
if ok == false {
t.Error("Expected outbound price to contain a price for the origination prefix ALL")
}
}
func TestGetVoicePriceNumber(t *testing.T) {
t.Parallel()
client, server := getServer(voicePriceNumberUS)
defer server.Close()
expectedIsoCountry := "US"
expectedCountryName := "United States"
expectedPriceUnit := "USD"
data := url.Values{}
data.Set("OriginationNumber", from)
voicePriceNum, err := client.Pricing.Voice.Numbers.Get(context.Background(), to, data)
if err != nil {
t.Fatal(err)
}
if voicePriceNum == nil {
t.Fatal("expected voice price to be returned")
}
if voicePriceNum.OriginationNumber != from {
t.Errorf("Expected voice price number to be %s, but got %s\n", from, voicePriceNum.OriginationNumber)
}
if voicePriceNum.DestinationNumber != to {
t.Errorf("Expected voice price number to be %s, but got %s\n", to, voicePriceNum.DestinationNumber)
}
if voicePriceNum.Country != expectedCountryName {
t.Errorf("Expected voice price country to be %s, but got %s\n", expectedCountryName, voicePriceNum.Country)
}
if voicePriceNum.IsoCountry != expectedIsoCountry {
t.Errorf("Expected voice price iso country to be %s, but got %s\n", expectedIsoCountry, voicePriceNum.IsoCountry)
}
if voicePriceNum.PriceUnit != expectedPriceUnit {
t.Errorf("Expected voice price unit to be %s, but got %s\n", expectedPriceUnit, voicePriceNum.PriceUnit)
}
if voicePriceNum.InboundCallPrice.BasePrice != "" {
t.Error("Expected voice price to not contain an InboundCallPrice")
}
if len(voicePriceNum.OutboundCallPrices) != 1 {
t.Error("Expected voice price to contain an OutboundPrefixPrices")
}
if voicePriceNum.OutboundCallPrices[0].BasePrice == "" {
t.Error("Expected outbound call prices to contain an BasePrice")
}
}
func TestGetVoicePricePage(t *testing.T) {
t.Parallel()
client, server := getServer(voiceCountriesPage)
defer server.Close()
data := url.Values{"PageSize": []string{"10"}}
page, err := client.Pricing.Voice.Countries.GetPage(context.Background(), data)
if err != nil {
t.Fatal(err)
}
if len(page.Countries) == 0 {
t.Error("expected to get a list of countries, got back 0")
}
if len(page.Countries) != 10 {
t.Errorf("expected 10 countries, got %d", len(page.Countries))
}
if page.Meta.Key != "countries" {
t.Errorf("expected Key to be 'countries', got %s", page.Meta.Key)
}
if page.Meta.PageSize != 10 {
t.Errorf("expected PageSize to be 10, got %d", page.Meta.PageSize)
}
if page.Meta.Page != 0 {
t.Errorf("expected Page to be 0, got %d", page.Meta.Page)
}
if page.Meta.PreviousPageURL.Valid != false {
t.Errorf("expected previousPage.Valid to be false, got true")
}
}