-
Notifications
You must be signed in to change notification settings - Fork 26
/
ussd_test.go
63 lines (54 loc) · 1.86 KB
/
ussd_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
// +build messages
// Tests in this file will only be run if the build tag messages is set:
// `go test -tag messages`
// Test with only sending one message using:
// `go test -test.run UssdPush -tags messages`
package nexmo
import (
"strconv"
"testing"
"time"
)
func TestUssdPushMessage(t *testing.T) {
time.Sleep(1 * time.Second) // Sleep 1 second due to API limitation
if TEST_PHONE_NUMBER == "" {
t.Fatal("No test phone number specified. Please set NEXMO_NUM")
}
nexmo, err := NewClientFromAPI(API_KEY, API_SECRET)
if err != nil {
t.Error("Failed to create Client with error:", err)
}
message := &USSDMessage{
From: TEST_FROM,
To: TEST_PHONE_NUMBER,
Text: "Gonexmo test USSD push message, sent at " + time.Now().String(),
ClientReference: "gonexmo-test " + strconv.FormatInt(time.Now().Unix(), 10),
}
messageResponse, err := nexmo.USSD.Send(message)
if err != nil {
t.Error("Failed to send USSD push message with error:", err)
}
t.Logf("Sent USSD push, response was: %#v\n", messageResponse)
}
func TestUssdPromptMessage(t *testing.T) {
time.Sleep(1 * time.Second) // Sleep 1 second due to API limitation
if TEST_PHONE_NUMBER == "" {
t.Fatal("No test phone number specified. Please set NEXMO_NUM")
}
nexmo, err := NewClientFromAPI(API_KEY, API_SECRET)
if err != nil {
t.Error("Failed to create Client with error:", err)
}
message := &USSDMessage{
From: TEST_FROM,
To: TEST_PHONE_NUMBER,
Text: "Gonexmo test USSD prompt message, sent at " + time.Now().String(),
ClientReference: "gonexmo-test " + strconv.FormatInt(time.Now().Unix(), 10),
Prompt: true,
}
messageResponse, err := nexmo.USSD.Send(message)
if err != nil {
t.Error("Failed to send USSD prompt message with error:", err)
}
t.Logf("Sent USSD prompt, response was: %#v\n", messageResponse)
}