forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prices_voice_test.go
181 lines (165 loc) · 5.72 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
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)
if err != nil {
t.Fatal(err)
}
if voicePrice == nil {
t.Error("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")
}
outboundPrefixPriceMap := make(map[string]bool)
for _, outPrice := range voicePrice.OutboundPrefixPrices {
for _, prefix := range outPrice.Prefixes {
outboundPrefixPriceMap[prefix] = true
}
}
// outboundPrefixPriceMap => map[1907:true 1844:true 1866:true 1877:true 1:true 1808:true 1800:true 1855:true 1888:true]
_, ok = outboundPrefixPriceMap["1"]
if ok == false {
t.Error("Expected outbound price to contain a price for the prefix 1")
}
}
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)
if err != nil {
t.Fatal(err)
}
if voicePrice == nil {
t.Error("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")
}
outboundPrefixPriceMap := make(map[string]bool)
for _, outPrice := range voicePrice.OutboundPrefixPrices {
for _, prefix := range outPrice.Prefixes {
outboundPrefixPriceMap[prefix] = true
}
}
_, ok = outboundPrefixPriceMap["44"]
if ok == false {
t.Error("Expected outbound price to contain a price for the prefix 44")
}
}
func TestGetVoicePriceNumber(t *testing.T) {
t.Parallel()
client, server := getServer(voicePriceNumberUS)
defer server.Close()
expectedIsoCountry := "US"
expectedCountryName := "United States"
expectedPriceUnit := "USD"
voicePriceNum, err := client.Pricing.Voice.Numbers.Get(context.Background(), from)
if err != nil {
t.Fatal(err)
}
if voicePriceNum == nil {
t.Error("expected voice price to be returned")
}
if voicePriceNum.Number != from {
t.Errorf("Expected voice price number to be %s, but got %s\n", from, voicePriceNum.Number)
}
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 voicePriceNum.OutboundCallPrice.BasePrice == "" {
t.Error("Expected voice price to contain an OutboundPrefixPrice")
}
}
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")
}
}