Skip to content

Commit

Permalink
Merge pull request #902 from sryoya/add_condition_to_the_validation_f…
Browse files Browse the repository at this point in the history
…unction_for_TextBlockObject

Add the new condition to the validation func for TextBlockObject
  • Loading branch information
kanata2 authored Mar 7, 2021
2 parents bf8fbd5 + 1af992a commit 87fa263
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions block_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (s TextBlockObject) MixedElementType() MixedElementType {

// Validate checks if TextBlockObject has valid values
func (s TextBlockObject) Validate() error {
if s.Type != "plain_text" && s.Type != "mrkdwn" {
return errors.New("type must be either of plain_text or mrkdwn")
}

// https://github.com/slack-go/slack/issues/881
if s.Type == "mrkdwn" && s.Emoji {
return errors.New("emoji cannot be true in mrkdown")
Expand Down
18 changes: 18 additions & 0 deletions block_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ func TestValidateTextBlockObject(t *testing.T) {
},
expected: nil,
},
{
input: TextBlockObject{
Type: "mrkdwn",
Text: "testText",
Emoji: false,
Verbatim: false,
},
expected: nil,
},
{
input: TextBlockObject{
Type: "invalid",
Text: "testText",
Emoji: false,
Verbatim: false,
},
expected: errors.New("type must be either of plain_text or mrkdwn"),
},
{
input: TextBlockObject{
Type: "mrkdwn",
Expand Down

0 comments on commit 87fa263

Please sign in to comment.