From 8377a8789d06e00858b00cf3253a445a78a77fc0 Mon Sep 17 00:00:00 2001 From: Ruslan Efanov Date: Fri, 26 May 2023 16:52:34 +0300 Subject: [PATCH] fix model fields --- client.go | 8 ++++++++ client_test.go | 15 +++++++++++++++ testutils.go | 2 +- types.go | 5 +++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 0291ea3..6fe5207 100644 --- a/client.go +++ b/client.go @@ -6563,12 +6563,20 @@ func (c *Client) EditMGChannelTemplate(req EditMGChannelTemplateRequest) (int, e return 0, err } + if string(templates) == "null" { + templates = []byte(`[]`) + } + removed, err := json.Marshal(req.Removed) if err != nil { return 0, err } + if string(removed) == "null" { + removed = []byte(`[]`) + } + values := url.Values{ "templates": {string(templates)}, "removed": {string(removed)}, diff --git a/client_test.go b/client_test.go index 21b0ff6..94b84c1 100644 --- a/client_test.go +++ b/client_test.go @@ -7896,4 +7896,19 @@ func TestClient_EditMGChannelTemplate(t *testing.T) { code, err := client().EditMGChannelTemplate(request) assert.NoError(t, err) assert.True(t, statuses[code]) + + reqValue = url.Values{ + "templates": {tmplsJSON}, + "removed": {"[]"}, + } + + gock.New(crmURL). + Post("reference/mg-channels/templates/edit"). + Body(strings.NewReader(reqValue.Encode())). + Reply(http.StatusOK) + + request = EditMGChannelTemplateRequest{Templates: tmpls} + code, err = client().EditMGChannelTemplate(request) + assert.NoError(t, err) + assert.True(t, statuses[code]) } diff --git a/testutils.go b/testutils.go index 08ac619..ffa945f 100644 --- a/testutils.go +++ b/testutils.go @@ -517,5 +517,5 @@ func getMGTemplatesResponse() string { } func getMGTemplatesForEdit() string { - return `[{"header":{"text":{"parts":["Hello,",{"var":"custom"}],"example":["Henry"]},"document":{"example":"https://example.com/file/123.pdf"},"image":{"example":"https://example.com/file/123.png"},"video":{"example":"https://example.com/file/123.mp4"}},"lang":"en","category":"test_0","code":"namespace#name_0#ru","name":"name_0","namespace":"namespace","footer":"footer_0","verificationStatus":"REJECTED","template":["Text_0",{"var":"custom"}],"templateExample":["WIU"],"buttons":[{"type":"PHONE_NUMBER","text":"your-phone-button-text","phoneNumber":"+79895553535"},{"type":"QUICK_REPLY","text":"Yes"},{"type":"URL","url":"https://example.com/file/{{1}}","text":"button","example":["https://www.website.com/dynamic-url-example"]}],"channel":{"type":"fbmessenger","name":"JABAAAAAAAAAA","id":1,"externalId":1,"allowedSendByPhone":false,"active":true},"id":1,"externalId":10,"active":true}]` + return `[{"header":{"text":{"parts":["Hello,",{"var":"custom"}],"example":["Henry"]},"document":{"example":"https://example.com/file/123.pdf"},"image":{"example":"https://example.com/file/123.png"},"video":{"example":"https://example.com/file/123.mp4"}},"lang":"en","category":"test_0","code":"namespace#name_0#ru","name":"name_0","namespace":"namespace","footer":"footer_0","verificationStatus":"REJECTED","template":["Text_0",{"var":"custom"}],"buttons":[{"type":"PHONE_NUMBER","text":"your-phone-button-text","phoneNumber":"+79895553535"},{"type":"QUICK_REPLY","text":"Yes"},{"type":"URL","url":"https://example.com/file/{{1}}","text":"button","example":["https://www.website.com/dynamic-url-example"]}],"templateExample":["WIU"],"id":1,"externalId":10,"mgChannelId":110,"active":true}]` } diff --git a/types.go b/types.go index 21ff671..881ae7e 100644 --- a/types.go +++ b/types.go @@ -1474,6 +1474,7 @@ type MGChannel struct { } type MGChannelTemplate struct { + Channel *MGChannel `json:"channel,omitempty"` Header *Header `json:"header"` Lang string `json:"lang"` Category string `json:"category"` @@ -1483,10 +1484,10 @@ type MGChannelTemplate struct { Footer string `json:"footer,omitempty"` VerificationStatus string `json:"verificationStatus,omitempty"` BodyTemplate TemplateItemList `json:"template"` - BodyTemplateExample []string `json:"templateExample"` Buttons []Button `json:"buttons,omitempty"` - Channel MGChannel `json:"channel"` + BodyTemplateExample []string `json:"templateExample"` ID int `json:"id,omitempty"` ExternalID int `json:"externalId,omitempty"` + MGChannelID int `json:"mgChannelId"` Active bool `json:"active"` }