github.com/lologarithm/mattermost-server@v5.3.2-0.20181002060438-c82a84ed765b+incompatible/app/slack_test.go (about)

     1  package app
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mattermost/mattermost-server/model"
     7  )
     8  
     9  func TestProcessSlackText(t *testing.T) {
    10  	th := Setup().InitBasic()
    11  	defer th.TearDown()
    12  
    13  	if th.App.ProcessSlackText("<!channel> foo <!channel>") != "@channel foo @channel" {
    14  		t.Fail()
    15  	}
    16  
    17  	if th.App.ProcessSlackText("<!here> bar <!here>") != "@here bar @here" {
    18  		t.Fail()
    19  	}
    20  
    21  	if th.App.ProcessSlackText("<!all> bar <!all>") != "@all bar @all" {
    22  		t.Fail()
    23  	}
    24  
    25  	userId := th.BasicUser.Id
    26  	username := th.BasicUser.Username
    27  	if th.App.ProcessSlackText("<@"+userId+"> hello") != "@"+username+" hello" {
    28  		t.Fail()
    29  	}
    30  }
    31  
    32  func TestProcessSlackAnnouncement(t *testing.T) {
    33  	th := Setup().InitBasic()
    34  	defer th.TearDown()
    35  
    36  	userId := th.BasicUser.Id
    37  	username := th.BasicUser.Username
    38  
    39  	attachments := []*model.SlackAttachment{
    40  		{
    41  			Pretext: "<!channel> pretext <!here>",
    42  			Text:    "<!channel> text <!here>",
    43  			Title:   "<!channel> title <!here>",
    44  			Fields: []*model.SlackAttachmentField{
    45  				{
    46  					Title: "foo",
    47  					Value: "<!channel> bar <!here>",
    48  					Short: true,
    49  				},
    50  			},
    51  		},
    52  		{
    53  			Pretext: "<@" + userId + "> pretext",
    54  			Text:    "<@" + userId + "> text",
    55  			Title:   "<@" + userId + "> title",
    56  			Fields: []*model.SlackAttachmentField{
    57  				{
    58  					Title: "foo",
    59  					Value: "<@" + userId + "> bar",
    60  					Short: true,
    61  				},
    62  			},
    63  		},
    64  	}
    65  	attachments = th.App.ProcessSlackAttachments(attachments)
    66  	if len(attachments) != 2 || len(attachments[0].Fields) != 1 || len(attachments[1].Fields) != 1 {
    67  		t.Fail()
    68  	}
    69  
    70  	if attachments[0].Pretext != "@channel pretext @here" ||
    71  		attachments[0].Text != "@channel text @here" ||
    72  		attachments[0].Title != "@channel title @here" ||
    73  		attachments[0].Fields[0].Value != "@channel bar @here" {
    74  		t.Fail()
    75  	}
    76  
    77  	if attachments[1].Pretext != "@"+username+" pretext" ||
    78  		attachments[1].Text != "@"+username+" text" ||
    79  		attachments[1].Title != "@"+username+" title" ||
    80  		attachments[1].Fields[0].Value != "@"+username+" bar" {
    81  		t.Fail()
    82  	}
    83  }