forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 69
/
verify_test.go
151 lines (138 loc) · 4.65 KB
/
verify_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
package twilio
import (
"context"
"net/url"
"testing"
)
func TestVerifyPhoneNumbersCreate(t *testing.T) {
t.Parallel()
client, s := getServer(verifyResponse)
defer s.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
data := url.Values{}
data.Add("to", "+14155551234")
data.Add("channel", "sms")
verify, err := client.Verify.Verifications.Create(ctx, "VA9e0bd45bfa7d9b9e7dca86cf94c7d4f8", data)
if err != nil {
t.Fatal(err)
}
if verify.To != "+14155551234" {
t.Errorf("expected To to be %s, got %s", "+14155551234", verify.To)
}
if verify.Valid {
t.Errorf("expected Valid to be %t, got %t", false, true)
}
if verify.Channel != "sms" {
t.Errorf("expected Channel to be %s, got %s", "sms", verify.Channel)
}
if verify.Lookup.Carrier.Type != "mobile" {
t.Errorf("expected Lookup.Carrier to be %s, got %s", "mobile", verify.Lookup.Carrier.Type)
}
}
func TestVerifyPhoneNumbersGet(t *testing.T) {
t.Parallel()
client, s := getServer(verifyResponse)
defer s.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
verify, err := client.Verify.Verifications.Get(ctx, "VA9e0bd45bfa7d9b9e7dca86cf94c7d4f8", "+14155551234")
if err != nil {
t.Fatal(err)
}
if verify.To != "+14155551234" {
t.Errorf("expected To to be %s, got %s", "+14155551234", verify.To)
}
if verify.Valid {
t.Errorf("expected Valid to be %t, got %t", false, true)
}
if verify.Channel != "sms" {
t.Errorf("expected Channel to be %s, got %s", "sms", verify.Channel)
}
if verify.Lookup.Carrier.Type != "mobile" {
t.Errorf("expected Lookup.Carrier to be %s, got %s", "mobile", verify.Lookup.Carrier.Type)
}
}
func TestVerifyPhoneNumbersCheck(t *testing.T) {
t.Parallel()
client, s := getServer(verifyCheckResponse)
defer s.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
data := url.Values{}
data.Add("code", "1234")
data.Add("to", "+14155551234")
verify, err := client.Verify.Verifications.Check(ctx, "VA9e0bd45bfa7d9b9e7dca86cf94c7d4f8", data)
if err != nil {
t.Fatal(err)
}
if verify.To != "+14155551234" {
t.Errorf("expected To to be %s, got %s", "+14155551234", verify.To)
}
if !verify.Valid {
t.Errorf("expected Valid to be %t, got %t", true, false)
}
if verify.Status != "approved" {
t.Errorf("expected Status to be %s, got %s", "approved", verify.Status)
}
if verify.Channel != "sms" {
t.Errorf("expected Channel to be %s, got %s", "sms", verify.Channel)
}
}
func TestVerifyAccessTokenCreate(t *testing.T) {
t.Parallel()
client, s := getServer(verifyAccessTokenResponse)
defer s.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
data := url.Values{}
data.Add("Identity", "foo")
data.Add("FactorType", "push")
verify, err := client.Verify.AccessTokens.Create(ctx, "VA9e0bd45bfa7d9b9e7dca86cf94c7d4f8", data)
if err != nil {
t.Fatal(err)
}
if verify.Token != "token.stub" {
t.Errorf("expected Token to be %s, got %s", "token.stub", verify.Token)
}
}
func TestVerifyChallengeCreate(t *testing.T) {
t.Parallel()
client, s := getServer(verifyChallengeResponse)
defer s.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
data := url.Values{}
data.Add("FactorSid", "YFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
data.Add("FactorType", "push")
data.Add("Details.Message", "Hi! Mr. John Doe, would you like to sign up?")
data.Add("Details.Fields", "{\"label\": \"Action\", \"value\": \"Sign up in portal\"}")
data.Add("Details.Fields", "{\"label\": \"Location\", \"value\": \"California\"}")
challenge, err := client.Verify.Challenges.Create(ctx, "VA9e0bd45bfa7d9b9e7dca86cf94c7d4f8", "ff483d1ff591898a9942916050d2ca3f", data)
if err != nil {
t.Fatal(err)
}
if challenge.FactorSid != "YFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" {
t.Errorf("expected FactorSid to be %s, got %s", "YFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", challenge.FactorSid)
}
if challenge.FactorType != "push" {
t.Errorf("expected FactorType to be %s, got %s", "push", challenge.FactorType)
}
}
func TestVerifyChallengeCheck(t *testing.T) {
t.Parallel()
client, s := getServer(verifyChallengeResponse)
defer s.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
challenge, err := client.Verify.Challenges.Get(ctx, "VA9e0bd45bfa7d9b9e7dca86cf94c7d4f8", "ff483d1ff591898a9942916050d2ca3f", "YCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
if err != nil {
t.Fatal(err)
}
if challenge.Sid != "YC03aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" {
t.Errorf("expected Sid to be %s, got %s", "YC03aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", challenge.Sid)
}
if challenge.FactorType != "push" {
t.Errorf("expected FactorType to be %s, got %s", "push", challenge.FactorType)
}
}