mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Fix /join command for non-admin accounts * Implement found check in join command unit test properly
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package api
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mattermost/platform/model"
|
|
)
|
|
|
|
func TestJoinCommands(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
Client := th.BasicClient
|
|
team := th.BasicTeam
|
|
user2 := th.BasicUser2
|
|
|
|
channel0 := &model.Channel{DisplayName: "00", Name: "00" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
|
channel0 = Client.Must(Client.CreateChannel(channel0)).Data.(*model.Channel)
|
|
|
|
channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
|
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
|
|
Client.Must(Client.LeaveChannel(channel1.Id))
|
|
|
|
channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
|
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
|
|
Client.Must(Client.LeaveChannel(channel2.Id))
|
|
|
|
channel3 := Client.Must(Client.CreateDirectChannel(user2.Id)).Data.(*model.Channel)
|
|
|
|
rs5 := Client.Must(Client.Command(channel0.Id, "/join "+channel2.Name, false)).Data.(*model.CommandResponse)
|
|
if !strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name) {
|
|
t.Fatal("failed to join channel")
|
|
}
|
|
|
|
rs6 := Client.Must(Client.Command(channel0.Id, "/join "+channel3.Name, false)).Data.(*model.CommandResponse)
|
|
if strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name) {
|
|
t.Fatal("should not have joined direct message channel")
|
|
}
|
|
|
|
c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
|
|
|
|
found := false
|
|
for _, c := range c1.Channels {
|
|
if c.Id == channel2.Id {
|
|
found = true
|
|
}
|
|
}
|
|
|
|
if !found {
|
|
t.Fatal("did not join channel")
|
|
}
|
|
}
|