github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/api/command_msg_test.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package api
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/mattermost/mattermost-server/model"
    11  )
    12  
    13  func TestMsgCommands(t *testing.T) {
    14  	th := Setup().InitBasic()
    15  	defer th.TearDown()
    16  
    17  	Client := th.BasicClient
    18  	team := th.BasicTeam
    19  	user1 := th.BasicUser
    20  	user2 := th.BasicUser2
    21  	user3 := th.CreateUser(th.BasicClient)
    22  	th.LinkUserToTeam(user3, team)
    23  
    24  	Client.Must(Client.CreateDirectChannel(user2.Id))
    25  	Client.Must(Client.CreateDirectChannel(user3.Id))
    26  
    27  	rs1 := Client.Must(Client.Command("", "/msg "+user2.Username)).Data.(*model.CommandResponse)
    28  	if !strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user2.Id) && !strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+user2.Id+"__"+user1.Id) {
    29  		t.Fatal("failed to create direct channel")
    30  	}
    31  
    32  	rs2 := Client.Must(Client.Command("", "/msg "+user3.Username+" foobar")).Data.(*model.CommandResponse)
    33  	if !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user3.Id) && !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user3.Id+"__"+user1.Id) {
    34  		t.Fatal("failed to create second direct channel")
    35  	}
    36  	if result := Client.Must(Client.SearchPosts("foobar", false)).Data.(*model.PostList); len(result.Order) == 0 {
    37  		t.Fatalf("post did not get sent to direct message")
    38  	}
    39  
    40  	rs3 := Client.Must(Client.Command("", "/msg "+user2.Username)).Data.(*model.CommandResponse)
    41  	if !strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user2.Id) && !strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+user2.Id+"__"+user1.Id) {
    42  		t.Fatal("failed to go back to existing direct channel")
    43  	}
    44  
    45  	Client.Must(Client.Command("", "/msg "+th.BasicUser.Username+" foobar"))
    46  	Client.Must(Client.Command("", "/msg junk foobar"))
    47  }