Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow trailing slash in MG URL #124

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"time"

"github.com/google/go-querystring/query"
Expand All @@ -23,7 +24,7 @@ func New(url string, token string) *MgClient {
// NewWithClient initializes the MgClient with specified *http.Client.
func NewWithClient(url string, token string, client *http.Client) *MgClient {
return &MgClient{
URL: url,
URL: strings.TrimRight(url, "/"),
Token: token,
httpClient: client,
}
Expand Down
17 changes: 17 additions & 0 deletions v1/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ func (t *MGClientTest) transportURL(path string) string {
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() {
c := t.client()
chName := "WhatsApp Channel"
Expand Down