forked from sfreiberg/gotwilio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phonenumbers_test.go
80 lines (63 loc) · 2.01 KB
/
phonenumbers_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
package gotwilio
import (
"testing"
"github.com/stretchr/testify/assert"
log "github.com/sirupsen/logrus"
)
func TestGetAvailablePhoneNumbers(t *testing.T) {
log.SetLevel(log.DebugLevel)
options := AvailablePhoneNumbersOptions{
AreaCode: "925",
SMSEnabled: NewBoolean(true),
}
// get available phone numbers
client := initTestTwilioClient()
res, exception, err := client.GetAvailablePhoneNumbers(PhoneNumberLocal, "US", options)
validateTwilioException(t, exception)
assert.NoError(t, err)
assert.NotNil(t, res)
for _, availablePhoneNumber := range res {
log.Debug(availablePhoneNumber.PhoneNumber)
assert.NotNil(t, availablePhoneNumber)
assert.NotEmpty(t, availablePhoneNumber.PhoneNumber)
}
}
func TestAvailablePhoneNumberOptionsToQueryString(t *testing.T) {
log.SetLevel(log.DebugLevel)
options := AvailablePhoneNumbersOptions{
AreaCode: "415",
SMSEnabled: NewBoolean(true),
VoiceEnabled: NewBoolean(false),
}
queryString, err := options.ToQueryString()
assert.NoError(t, err)
assert.Empty(t, queryString.Get("in_region"))
// test our ternary boolean
assert.Equal(t, "true", queryString.Get("SmsEnabled"))
assert.Equal(t, "false", queryString.Get("VoiceEnabled"))
assert.Empty(t, queryString.Get("MmsEnabled"))
}
func TestCreateUpdateDeleteIncomingPhoneNumber(t *testing.T) {
log.SetLevel(log.DebugLevel)
client := initTestTwilioClient()
phoneNumber := IncomingPhoneNumber{
AreaCode: "925",
}
// create
number, exception, err := client.CreateIncomingPhoneNumber(phoneNumber)
validateTwilioException(t, exception)
assert.NoError(t, err)
assert.NotNil(t, number)
// update
number, exception, err = client.UpdateIncomingPhoneNumber(number.SID, IncomingPhoneNumber{
FriendlyName: "test name",
})
validateTwilioException(t, exception)
assert.NoError(t, err)
assert.NotNil(t, number)
assert.Equal(t, "test name", number.FriendlyName)
// delete
exception, err = client.DeleteIncomingPhoneNumber(number.SID)
validateTwilioException(t, exception)
assert.NoError(t, err)
}