forked from nexmo-community/nexmo-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsms_test.go
More file actions
87 lines (73 loc) · 2.03 KB
/
sms_test.go
File metadata and controls
87 lines (73 loc) · 2.03 KB
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
package nexmo
import (
"encoding/json"
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
func TestSendSMS(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("POST", "https://rest.nexmo.com/sms/json",
httpmock.NewStringResponder(200, `{
"message-count": "1",
"messages": [{
"to": "447520615146",
"message-id": "140000005494DDEB",
"status": "0",
"remaining-balance": "54.42941782",
"message-price": "0.03330000",
"network": "23409"
}]
}`))
response, _, err := _client.SMS.SendSMS(SendSMSRequest{
To: "447520615146",
From: "NEXMOTEST",
Text: "Nêxmö Tėšt",
Type: "unicode",
})
assert.Nil(t, err)
assert.Equal(t, "1", response.MessageCount)
}
func TestSMSRequest(t *testing.T) {
b, err := json.Marshal(SendSMSRequest{
To: "447520615146",
From: "NEXMOTEST",
Text: "Nêxmö Tėšt",
Type: MessageTypeUnicode,
})
assert.NoError(t, err)
var j map[string]interface{}
err = json.Unmarshal(b, &j)
assert.NoError(t, err)
assert.Equal(t, "unicode", j["type"])
assert.Equal(t, "Nêxmö Tėšt", j["text"])
}
func TestUserAgentHeader(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("POST", "https://rest.nexmo.com/sms/json", func(req *http.Request) (*http.Response, error) {
assert.Equal(t, 1, len(req.Header["User-Agent"]))
assert.Regexpf(t, "nexmo-go/[^ ]* Go/", req.Header["User-Agent"][0], "Unexpected User-Agent format")
return httpmock.NewStringResponse(200, `{
"message-count": "1",
"messages": [{
"to": "447520615146",
"message-id": "140000005494DDEB",
"status": "0",
"remaining-balance": "54.42941782",
"message-price": "0.03330000",
"network": "23409"
}]
}`), nil
})
response, _, err := _client.SMS.SendSMS(SendSMSRequest{
To: "447520615146",
From: "NEXMOTEST",
Text: "Nêxmö Tėšt",
Type: "unicode",
})
assert.Nil(t, err)
assert.Equal(t, "1", response.MessageCount)
}