summaryrefslogtreecommitdiffstats
path: root/app/command_join_test.go
blob: 77574217b92355b6d6542d51fca5d80b161358da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package app

import (
	"testing"
	"github.com/mattermost/mattermost-server/model"
	"github.com/nicksnyder/go-i18n/i18n"
	"github.com/stretchr/testify/assert"
)

func TestJoinCommandNoChannel(t *testing.T) {
	th := Setup().InitBasic()
	defer th.TearDown()

	if testing.Short() {
		t.SkipNow()
	}

	cmd := &JoinProvider{}
	resp := cmd.DoCommand(th.App, &model.CommandArgs{
		T:      i18n.IdentityTfunc(),
		UserId: th.BasicUser2.Id,
		SiteURL: "http://test.url",
		TeamId:      th.BasicTeam.Id,
	}, "asdsad")

	assert.Equal(t, "api.command_join.list.app_error", resp.Text)
}

func TestJoinCommandForExistingChannel(t *testing.T) {
	th := Setup().InitBasic()
	defer th.TearDown()

	if testing.Short() {
		t.SkipNow()
	}

	channel2, _ := th.App.CreateChannel(&model.Channel{
	  DisplayName: "AA",
	  Name:        "aa" + model.NewId() + "a",
	  Type:        model.CHANNEL_OPEN,
	  TeamId:      th.BasicTeam.Id,
	  CreatorId:   th.BasicUser.Id,
	}, false)


	cmd := &JoinProvider{}
	resp := cmd.DoCommand(th.App, &model.CommandArgs{
		T:      i18n.IdentityTfunc(),
		UserId: th.BasicUser2.Id,
		SiteURL: "http://test.url",
		TeamId:      th.BasicTeam.Id,
	}, channel2.Name)

	assert.Equal(t, "", resp.Text)
	assert.Equal(t, "http://test.url/"+th.BasicTeam.Name+"/channels/"+channel2.Name, resp.GotoLocation)
}

func TestJoinCommandWithTilde(t *testing.T) {
	th := Setup().InitBasic()
	defer th.TearDown()

	if testing.Short() {
		t.SkipNow()
	}

	channel2, _ := th.App.CreateChannel(&model.Channel{
	  DisplayName: "AA",
	  Name:        "aa" + model.NewId() + "a",
	  Type:        model.CHANNEL_OPEN,
	  TeamId:      th.BasicTeam.Id,
	  CreatorId:   th.BasicUser.Id,
	}, false)


	cmd := &JoinProvider{}
	resp := cmd.DoCommand(th.App, &model.CommandArgs{
		T:      i18n.IdentityTfunc(),
		UserId: th.BasicUser2.Id,
		SiteURL: "http://test.url",
		TeamId:      th.BasicTeam.Id,
	}, "~"+channel2.Name)

	assert.Equal(t, "", resp.Text)
	assert.Equal(t, "http://test.url/"+th.BasicTeam.Name+"/channels/"+channel2.Name, resp.GotoLocation)
}