1
0
mirror of synced 2024-11-21 20:46:05 +03:00

Templates fields, additional validation in UpdateTemplate

This commit is contained in:
Akolzin Dmitry 2020-05-11 17:41:17 +03:00
parent e144eba7c0
commit 4206ad2695
3 changed files with 32 additions and 0 deletions

View File

@ -136,6 +136,10 @@ func (c *MgClient) ActivateTemplate(channelID uint64, request ActivateTemplateRe
func (c *MgClient) UpdateTemplate(request Template) (int, error) {
outgoing, _ := json.Marshal(&request)
if request.ChannelID == 0 || request.Code == "" {
return 0, errors.New("`ChannelID` and `Code` cannot be blank")
}
data, status, err := c.PutRequest(fmt.Sprintf("/channels/%d/templates/%s", request.ChannelID, request.Code), outgoing)
if err != nil {
return status, err

View File

@ -329,6 +329,32 @@ func TestMgClient_UpdateTemplate(t *testing.T) {
}
}
func TestMgClient_UpdateTemplateFail(t *testing.T) {
c := client()
tpl := Template{
Name: "updated name",
Enabled: true,
Type: TemplateTypeText,
Template: []TemplateItem{
{
Type: TemplateItemTypeText,
Text: "Welcome ",
},
{
Type: TemplateItemTypeVar,
VarType: TemplateVarFirstName,
},
{
Type: TemplateItemTypeText,
Text: "!",
},
},
}
status, err := c.UpdateTemplate(tpl)
assert.Error(t, err, fmt.Sprintf("%d %s", status, err))
}
func TestMgClient_DeactivateTemplate(t *testing.T) {
c := client()
status, err := c.DeactivateTemplate(templateChannel(t), tplCode)

View File

@ -314,6 +314,8 @@ type WebhookData struct {
Product *MessageDataProduct `json:"product,omitempty"`
Order *MessageDataOrder `json:"order,omitempty"`
Items *[]FileItem `json:"items,omitempty"`
TemplateCode string `json:"template_code,omitempty"`
TemplateArgs []string `json:"template_args,omitempty"`
}
// FileItem struct