-
Notifications
You must be signed in to change notification settings - Fork 26
/
verify_test.go
86 lines (70 loc) · 2.28 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
package nexmo
import (
"testing"
"time"
)
func testSend(t *testing.T) *VerifyMessageResponse {
time.Sleep(1 * time.Second) // Sleep 1 second due to API limitation
if testPhoneNumber == "" {
t.Fatal("no test phone number specified. Please set NEXMO_NUM")
}
client, err := NewClient(testAPIKey, testAPISecret)
if err != nil {
t.Error("failed to create Client with error:", err)
}
message := &VerifyMessageRequest{
Number: testPhoneNumber,
Brand: testFrom,
SenderID: testFrom,
}
messageResponse, err := client.Verify.Send(message)
if err != nil {
t.Error("failed to send verification request with error:", err)
}
return messageResponse
}
func TestSend(t *testing.T) {
messageResponse := testSend(t)
t.Logf("Sent Verification SMS, response was: %#v\n", messageResponse)
}
func TestSendCheck(t *testing.T) {
// We need the request ID, so we have to run this first.
sendResponse := testSend(t)
time.Sleep(1 * time.Second) // Sleep 1 second due to API limitation
if testPhoneNumber == "" {
t.Fatal("No test phone number specified. Please set NEXMO_NUM")
}
client, err := NewClient(testAPIKey, testAPISecret)
if err != nil {
t.Error("Failed to create Client with error:", err)
}
message := &VerifyCheckRequest{
RequestID: sendResponse.RequestID,
Code: "1122", // Take a random code here, the number will not be verified properly though.
}
messageResponse, err := client.Verify.Check(message)
if err != nil {
t.Error("Failed to send verification check request with error:", err)
}
t.Logf("Sent Verification SMS, response was: %#v\n", messageResponse)
}
func TestSendSearch(t *testing.T) {
// We need the request id, so we have to run this first.
sendResponse := testSend(t)
time.Sleep(1 * time.Second) // Sleep 1 second due to API limitation
if testPhoneNumber == "" {
t.Fatal("No test phone number specified. Please set NEXMO_NUM")
}
client, err := NewClient(testAPIKey, testAPISecret)
if err != nil {
t.Error("Failed to create Client with error:", err)
}
message := &VerifySearchRequest{
RequestID: sendResponse.RequestID,
}
messageResponse, err := client.Verify.Search(message)
if err != nil {
t.Error("Failed to send verification search request with error:", err)
}
t.Logf("Sent Verification SMS, response was: %#v\n", messageResponse)
}