-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_messages_test.go
223 lines (169 loc) · 6.45 KB
/
api_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
Messaging API v3.4.3
Testing MessagesAPIService
*/
package TelstraMessaging
import (
"context"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func Test_TelstraMessaging_MessagesAPIService(t *testing.T) {
t.Skip("skip test")
configuration := NewConfiguration()
apiClient := NewAPIClient(configuration)
messageId := "00f30ac0-ebb5-11ee-b9c0-5f8692f4ff9d"
clientId := "YOUR CLIENT ID"
clientSecret := "YOUR CLIENT SECRET"
authorization, _ := GetAuthorization(apiClient, clientId, clientSecret)
t.Run("Test MessagesAPIService DeleteMessageById", func(t *testing.T) {
//t.Skip("skip test") // remove to run test
messagesApi := apiClient.MessagesAPI.DeleteMessageById(context.Background(), messageId, authorization)
httpRes, err := messagesApi.DeleteMessageById()
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("httpRes Result: %+v\n", httpRes)
assert.Equal(t, 204, httpRes.StatusCode)
assert.NotEmpty(t, httpRes, "httpRes should not be empty")
assert.NoError(t, err, "Error encountered: %v", err)
})
t.Run("Test MessagesAPIService GetMessageById", func(t *testing.T) {
//t.Skip("skip test") // remove to run test
messagesApi := apiClient.MessagesAPI.GetMessageById(context.Background(), messageId, authorization)
resp, httpRes, err := messagesApi.GetMessageById()
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("httpRes Result: %+v\n", httpRes)
fmt.Printf("resp Result: %+v\n", resp)
assert.Equal(t, 200, httpRes.StatusCode)
assert.NotEmpty(t, httpRes, "httpRes should not be empty")
assert.NoError(t, err, "Error encountered: %v", err)
assert.NotNil(t, resp, "resp should not be nil")
})
t.Run("Test MessagesAPIService GetMessages", func(t *testing.T) {
messagesApi := apiClient.MessagesAPI.GetMessages(context.Background(), authorization)
reverse := true
messagesApi.reverse = &reverse
startTime := time.Now().AddDate(0, 0, -5).UTC()
messagesApi.startTime = &startTime
endTime := time.Now().AddDate(0, 0, -1).UTC()
messagesApi.endTime = &endTime
resp, httpRes, err := messagesApi.GetMessages()
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("httpRes Result: %+v\n", httpRes)
fmt.Printf("resp Result: %+v\n", resp)
assert.Equal(t, 200, httpRes.StatusCode)
assert.NotEmpty(t, httpRes, "httpRes should not be empty")
assert.NoError(t, err, "Error encountered: %v", err)
assert.NotNil(t, resp, "resp should not be nil")
})
t.Run("Test MessagesAPIService SendMessages", func(t *testing.T) {
//t.Skip("skip test") // remove to run test
sendMessagesSlice := []string{"0400000001", "0400000002"}
sendMessagesRequestTo := SendMessagesRequestTo{
ArrayOfString: &sendMessagesSlice,
String: new(string),
}
sendMessagesFrom := "0428180739"
sendMessagesRequest := NewSendMessagesRequest(sendMessagesRequestTo, sendMessagesFrom)
setMessageContent := "Hello customer, this is from CBA to confirme your offer!"
sendMessagesRequest.SetMessageContent(setMessageContent)
sendMessagesRequest.SetDeliveryNotification(false)
sendMessagesRequest.SetRetryTimeout(10)
sendMessagesRequest.SetStatusCallbackUrl("http://www.example.com")
multimedia1 := Multimedia{
Type: "image/jpeg",
FileName: "image/jpeg",
Payload: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
}
multimedia2 := Multimedia{
Type: "image/jpeg",
FileName: "image/jpeg",
Payload: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
}
sendMessagesRequest.SetMultimedia([]Multimedia{multimedia1, multimedia2})
tags := []string{
"ip",
"deserunt exercitation",
"id mollit magna proident ipsum",
"consequat proident",
"u",
"nulla ve",
"deserunt proident",
"deserunt nulla id esse",
"laboris velit",
"pr",
}
sendMessagesRequest.SetScheduleSend(time.Now().AddDate(0, 0, 5).UTC())
sendMessagesRequest.SetTags(tags)
messagesApi := apiClient.MessagesAPI.SendMessages(context.Background(), authorization)
resp, httpRes, err := messagesApi.SendMessages(*sendMessagesRequest)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("httpRes Result: %+v\n", httpRes)
fmt.Printf("resp Result: %+v\n", resp)
assert.Equal(t, 201, httpRes.StatusCode)
assert.NotEmpty(t, httpRes, "httpRes should not be empty")
assert.NoError(t, err, "Error encountered: %v", err)
assert.NotNil(t, resp, "resp should not be nil")
})
t.Run("Test MessagesAPIService UpdateMessageById", func(t *testing.T) {
//t.Skip("skip test") // remove to run test
updateMessageByIdRequest := NewUpdateMessageByIdRequest("0400000001", "0428180739")
setMessageContent := "Ut veniam in ipsum exercitation"
updateMessageByIdRequest.SetMessageContent(setMessageContent)
updateMessageByIdRequest.SetDeliveryNotification(false)
updateMessageByIdRequest.SetRetryTimeout(10)
updateMessageByIdRequest.SetStatusCallbackUrl("http://www.example.com")
tags := []string{
"ip",
"deserunt exercitation",
"id mollit magna proident ipsum",
"consequat proident",
"u",
"nulla ve",
"deserunt proident",
"deserunt nulla id esse",
"laboris velit",
"pr",
}
updateMessageByIdRequest.SetTags(tags)
messagesApi := apiClient.MessagesAPI.UpdateMessageById(context.Background(), messageId, authorization)
resp, httpRes, err := messagesApi.UpdateMessageById(*updateMessageByIdRequest)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("httpRes Result: %+v\n", httpRes)
fmt.Printf("resp Result: %+v\n", resp)
assert.Equal(t, 200, httpRes.StatusCode)
assert.NotEmpty(t, httpRes, "httpRes should not be empty")
assert.NoError(t, err, "Error encountered: %v", err)
assert.NotNil(t, resp, "resp should not be nil")
})
t.Run("Test MessagesAPIService UpdateMessageTags", func(t *testing.T) {
tags := []string{"marketing", "SMS"}
updateMessageTagsRequest := NewUpdateMessageTagsRequest(tags)
messagesApi := apiClient.MessagesAPI.UpdateMessageTags(context.Background(), messageId, authorization)
httpRes, err := messagesApi.UpdateMessageTags(*updateMessageTagsRequest)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("httpRes Result: %+v\n", httpRes)
assert.Equal(t, 204, httpRes.StatusCode)
assert.NotEmpty(t, httpRes, "httpRes should not be empty")
assert.NoError(t, err, "Error encountered: %v", err)
})
}