forked from plivo/plivo-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages_test.go
80 lines (67 loc) · 1.85 KB
/
messages_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 plivo
import (
"errors"
"testing"
)
func TestMessageService_List(t *testing.T) {
expectResponse("messageListResponse.json", 200)
if _, err := client.Messages.List(MessageListParams{}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
if _, err := client.Messages.List(MessageListParams{}); err == nil {
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "GET", "Message")
}
func TestMessageService_Get(t *testing.T) {
expectResponse("messageGetResponse.json", 200)
uuid := "5b40a428-bfc7-4daf-9d06-726c558bf3b8"
if _, err := client.Messages.Get(uuid); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
if _, err := client.Messages.Get(uuid); err == nil {
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "GET", "Message/%s", uuid)
}
func TestMessageService_ListMedia(t *testing.T) {
expectResponse("mmsMediaListResponse.json", 200)
uuid := "5b40a428-bfc7-4daf-9d06-726c558bf3b8"
if _, err := client.Messages.ListMedia(uuid); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
if _, err := client.Messages.ListMedia(uuid); err == nil {
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "GET", "Message/%s/Media", uuid)
}
func TestMessageService_Create(t *testing.T) {
expectResponse("messageSendResponse.json", 202)
if _, err := client.Messages.Create(MessageCreateParams{
Src: "+911231231230",
Dst: "+911231231231",
Text: "Testing",
}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
if _, err := client.Messages.Create(MessageCreateParams{
Src: "+911231231230",
Dst: "+911231231231",
Text: "Testing",
}); err == nil {
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "POST", "Message")
}