-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavailable_phone_number_test.go
137 lines (123 loc) · 3.96 KB
/
available_phone_number_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
package twiliolo_test
import (
"fmt"
"testing"
"time"
"net/url"
"github.com/genesor/twiliolo"
"github.com/genesor/twiliolo/internal"
"github.com/genesor/twiliolo/option"
"github.com/stretchr/testify/assert"
)
func TestAvailablePhoneNumberLocal(t *testing.T) {
client := new(internal.MockAPIClient)
client.GetFn = func(uri string, options []option.RequestOption) ([]byte, error) {
assert.Equal(t, option.VoiceEnabled(true), options[0])
assert.Equal(t, "/AvailablePhoneNumbers/FR/Local.json", uri)
response := `
{
"uri": "\/2010-04-01\/Accounts\/TwilioloFake\/AvailablePhoneNumbers\/FR\/Local.json?VoiceEnabled=true",
"available_phone_numbers": [
{
"friendly_name": "+3366554433",
"phone_number": "+3366554433",
"iso_country": "FR",
"capabilities": {
"voice": true,
"SMS": true,
"MMS": false
},
"address_requirements": "none",
"beta": false
},
{
"friendly_name": "+3399887799",
"phone_number": "+3399887799",
"iso_country": "FR",
"capabilities": {
"voice": true,
"SMS": false,
"MMS": false
},
"beta": false
}
]
}`
return []byte(response), nil
}
service := twiliolo.AvailablePhoneNumberService{Client: client}
list, err := service.Local("FR", option.VoiceEnabled(true))
assert.NoError(t, err)
assert.Equal(t, 1, client.GetCall)
assert.Equal(t, 2, len(list))
assert.Equal(t, "+3366554433", list[0].PhoneNumber)
assert.Equal(t, "+3366554433", list[0].FriendlyName)
assert.Equal(t, true, list[0].Capabilities.SMS)
assert.Equal(t, true, list[0].Capabilities.Voice)
assert.Equal(t, "FR", list[0].ISOCountry)
assert.Equal(t, "+3399887799", list[1].PhoneNumber)
assert.Equal(t, "+3399887799", list[1].FriendlyName)
assert.Equal(t, false, list[1].Capabilities.SMS)
assert.Equal(t, true, list[1].Capabilities.Voice)
assert.Equal(t, "FR", list[1].ISOCountry)
}
func TestAvailablePhoneNumberBuy(t *testing.T) {
client := new(internal.MockAPIClient)
client.PostFn = func(uri string, _ []option.RequestOption, values url.Values) ([]byte, error) {
assert.Equal(t, "+3399887799", values.Get("PhoneNumber"))
assert.Equal(t, "FriendlyName", values.Get("FriendlyName"))
assert.Equal(t, "/IncomingPhoneNumbers.json", uri)
response := fmt.Sprintf(`
{
"sid": "TwiliololIncomingFake",
"account_sid": "TwilioloFake",
"friendly_name": "FriendlyName",
"phone_number": "+3399887799",
"voice_url": "http://test.com",
"voice_method": "POST",
"voice_fallback_url": "http://fail.com",
"voice_fallback_method": "GET",
"status_callback": "http://status.com",
"status_callback_method": "GET",
"voice_caller_id_lookup": true,
"voice_application_sid": null,
"date_created": "%s",
"date_updated": "%s",
"sms_url": "http://sms.com",
"sms_method": "GET",
"sms_fallback_url": "http://fail-sms.com",
"sms_fallback_method": "GET",
"sms_application_sid": null,
"capabilities": {
"voice": true,
"sms": false,
"mms": false
},
"beta": false,
"api_version": "2010-04-01",
"uri": "\/2010-04-01\/Accounts\/TwilioloFake\/IncomingPhoneNumbers\/TwiliololIncomingFake.json"
}`, dateCreated.Format(time.RFC1123Z), dateCreated.Format(time.RFC1123Z))
return []byte(response), nil
}
availPhone := twiliolo.AvailablePhoneNumber{
FriendlyName: "FriendlyName",
PhoneNumber: "+3399887799",
ISOCountry: "FR",
AddressRequirements: "",
Beta: false,
Capabilities: twiliolo.Capabilities{
SMS: false,
MMS: false,
Voice: true,
},
}
service := twiliolo.AvailablePhoneNumberService{Client: client}
phone, err := service.Buy(&availPhone)
assert.NoError(t, err)
assert.Equal(t, 1, client.PostCall)
assert.Equal(t, "+3399887799", phone.PhoneNumber)
assert.Equal(t, "TwiliololIncomingFake", phone.Sid)
assert.Equal(t, false, phone.Capabilities.SMS)
assert.Equal(t, true, phone.Capabilities.Voice)
assert.Equal(t, "FriendlyName", phone.FriendlyName)
}