1
0
mirror of synced 2024-11-22 04:56:06 +03:00

Templates fields, additional validation in UpdateTemplate

This commit is contained in:
Alex Lushpai 2020-06-11 14:12:46 +03:00 committed by GitHub
commit 26a69c2e5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 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,12 @@ type WebhookData struct {
Product *MessageDataProduct `json:"product,omitempty"`
Order *MessageDataOrder `json:"order,omitempty"`
Items *[]FileItem `json:"items,omitempty"`
Template *TemplateInfo `json:"template,omitempty"`
}
type TemplateInfo struct {
Code string `json:"code,omitempty"`
Args []string `json:"args,omitempty"`
}
// FileItem struct