-
Notifications
You must be signed in to change notification settings - Fork 23
/
verify_test.go
88 lines (79 loc) · 2.37 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
package plivo
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestVerifyService_List(t *testing.T) {
expectResponse("verifySessionListResponse.json", 200)
assert := require.New(t)
resp, err := client.VerifySession.List(SessionListParams{})
assert.NotNil(resp)
assert.Nil(err)
assert.NotEmpty(resp.Sessions[0].SessionUUID)
assert.NotNil(resp.Sessions)
assert.NotNil(resp.Meta)
cl := client.httpClient
client.httpClient = nil
resp, err = client.VerifySession.List(SessionListParams{})
assert.NotNil(err)
assert.Nil(resp)
client.httpClient = cl
assertRequest(t, "GET", "Verify/Session")
}
func TestVerifyService_Get(t *testing.T) {
expectResponse("verifySessionGetResponse.json", 200)
uuid := "4124e518-a8c9-4feb-8cff-d86636ba9234"
assert := require.New(t)
resp, err := client.VerifySession.Get(uuid)
assert.NotNil(resp)
assert.Nil(err)
assert.Equal(resp.SessionUUID, uuid)
cl := client.httpClient
client.httpClient = nil
resp, err = client.VerifySession.Get(uuid)
assert.NotNil(err)
assert.Nil(resp)
client.httpClient = cl
assertRequest(t, "GET", "Verify/Session/%s", uuid)
}
func TestVerifyService_Create(t *testing.T) {
expectResponse("verifySessionSendResponse.json", 202)
assert := require.New(t)
resp, err := client.VerifySession.Create(SessionCreateParams{
Recipient: "9089789099",
})
assert.NotNil(resp)
assert.Nil(err)
assert.NotEmpty(resp.APIID)
assert.NotEmpty(resp.SessionUUID)
assert.Equal(resp.Error, "")
cl := client.httpClient
client.httpClient = nil
resp, err = client.VerifySession.Create(SessionCreateParams{
Recipient: "9089789099",
})
assert.NotNil(err)
assert.Nil(resp)
client.httpClient = cl
assertRequest(t, "POST", "Verify/Session")
}
func TestVerifyService_Validate(t *testing.T) {
expectResponse("verifySessionValidateResponse.json", 200)
assert := require.New(t)
resp, err := client.VerifySession.Validate(SessionValidationParams{
OTP: "9089789",
}, "5b40a428-bfc7-4daf-9d06-726c558bf3b8")
assert.NotNil(resp)
assert.Nil(err)
assert.NotEmpty(resp.APIID)
assert.Equal(resp.Error, "")
cl := client.httpClient
client.httpClient = nil
resp, err = client.VerifySession.Validate(SessionValidationParams{
OTP: "9089789",
}, "5b40a428-bfc7-4daf-9d06-726c558bf3b8")
assert.NotNil(err)
assert.Nil(resp)
client.httpClient = cl
assertRequest(t, "POST", "Verify/Session/%s", "5b40a428-bfc7-4daf-9d06-726c558bf3b8")
}