Templates fields, additional validation in UpdateTemplate
This commit is contained in:
commit
26a69c2e5d
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user