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