1
0
mirror of synced 2024-11-22 04:56:06 +03:00
mg-transport-api-client-go/v1/client_test.go
Alex Lushpai 11ed32136e
Init (#1)
* Channels methods
* Messages methods
* Partial tests
* Docs
2018-05-17 17:26:18 +03:00

128 lines
2.1 KiB
Go

package v1
import (
"net/http"
"os"
"strconv"
"testing"
)
var (
mgURL = os.Getenv("MG_URL")
mgToken = os.Getenv("MG_TOKEN")
channelId, _ = strconv.ParseUint(os.Getenv("MG_CHANNEL"), 10, 64)
)
func client() *MgClient {
return New(mgURL, mgToken)
}
func TestMgClient_ActivateTransportChannel(t *testing.T) {
c := client()
ch := Channel{
ID: channelId,
Type: "telegram",
Events: []string{
"message_sent",
"message_updated",
"message_deleted",
"message_read",
},
}
data, status, err := c.ActivateTransportChannel(ch)
if err != nil {
t.Errorf("%d %v", status, err)
}
t.Logf("%v", data.ChannelID)
}
func TestMgClient_ActivateNewTransportChannel(t *testing.T) {
c := client()
ch := Channel{
Type: "telegram",
Events: []string{
"message_sent",
"message_updated",
"message_deleted",
"message_read",
},
}
data, status, err := c.ActivateTransportChannel(ch)
if err != nil {
t.Errorf("%d %v", status, err)
}
t.Logf("%v", data.ChannelID)
}
func TestMgClient_UpdateTransportChannel(t *testing.T) {
c := client()
ch := Channel{
ID: channelId,
Events: []string{
"message_sent",
"message_read",
},
}
data, status, err := c.UpdateTransportChannel(ch)
if status != http.StatusOK {
t.Errorf("%v", err)
}
t.Logf("%v", data.ChannelID)
}
func TestMgClient_DeactivateTransportChannel(t *testing.T) {
c := client()
deleteData, status, err := c.DeactivateTransportChannel(channelId)
if err != nil {
t.Errorf("%d %v", status, err)
}
if deleteData.DectivatedAt.String() == "" {
t.Errorf("%v", err)
}
t.Logf("%v", deleteData.ChannelID)
}
/*func TestMgClient_Messages(t *testing.T) {
c := client()
snd := SendData{
SendMessage{
Message{
ExternalID: "23e23e23",
Channel: channelId,
Type: "text",
Text: "hello!",
},
time.Now(),
},
User{
ExternalID: "8",
Nickname: "@octopulus",
Firstname: "Joe",
},
channelId,
}
data, status, err := c.Messages(snd)
if status != http.StatusOK {
t.Errorf("%v", err)
}
if data.Time.String() == "" {
t.Errorf("%v", err)
}
}*/