Skip to content

Commit

Permalink
Templates fields, additional validation in UpdateTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
gwinn authored Jun 11, 2020
2 parents e144eba + b821553 commit 26a69c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions v1/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26a69c2

Please sign in to comment.