Merge pull request #124 from Neur0toxine/allow-trailing-slash-url
allow trailing slash in MG URL
This commit is contained in:
commit
0312ddcdd2
@ -10,6 +10,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
@ -23,7 +24,7 @@ func New(url string, token string) *MgClient {
|
|||||||
// NewWithClient initializes the MgClient with specified *http.Client.
|
// NewWithClient initializes the MgClient with specified *http.Client.
|
||||||
func NewWithClient(url string, token string, client *http.Client) *MgClient {
|
func NewWithClient(url string, token string, client *http.Client) *MgClient {
|
||||||
return &MgClient{
|
return &MgClient{
|
||||||
URL: url,
|
URL: strings.TrimRight(url, "/"),
|
||||||
Token: token,
|
Token: token,
|
||||||
httpClient: client,
|
httpClient: client,
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,23 @@ func (t *MGClientTest) transportURL(path string) string {
|
|||||||
return "/api/transport/v1/" + strings.TrimLeft(path, "/")
|
return "/api/transport/v1/" + strings.TrimLeft(path, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *MGClientTest) Test_URLWithTrailingSlash() {
|
||||||
|
c := New("https://mg-test.retailcrm.pro/", "mg_token")
|
||||||
|
c.Debug = true
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
t.gock().
|
||||||
|
Get(t.transportURL("channels")).
|
||||||
|
Reply(http.StatusOK).
|
||||||
|
JSON([]ChannelListItem{{ID: 1}})
|
||||||
|
|
||||||
|
data, status, err := c.TransportChannels(Channels{Active: true})
|
||||||
|
t.Require().NoError(err)
|
||||||
|
t.Assert().Equal(http.StatusOK, status)
|
||||||
|
|
||||||
|
t.Assert().Len(data, 1)
|
||||||
|
}
|
||||||
|
|
||||||
func (t *MGClientTest) Test_TransportChannels() {
|
func (t *MGClientTest) Test_TransportChannels() {
|
||||||
c := t.client()
|
c := t.client()
|
||||||
chName := "WhatsApp Channel"
|
chName := "WhatsApp Channel"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user