summaryrefslogtreecommitdiffstats
path: root/cmd/platform/channelargs_test.go.disabled
blob: 5447a061d8e092b474d572bc0b86a6fa7d7bc92f (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package main

import (
	"testing"

	"github.com/mattermost/platform/app"
	"github.com/mattermost/platform/model"
)

func TestParseChannelArg(t *testing.T) {
	if team, channel := parseChannelArg("channel"); team != "" {
		t.Fatal("got incorrect team", team)
	} else if channel != "channel" {
		t.Fatal("got incorrect channel", channel)
	}

	if team, channel := parseChannelArg("team:channel"); team != "team" {
		t.Fatal("got incorrect team", team)
	} else if channel != "channel" {
		t.Fatal("got incorrect channel", channel)
	}
}

func TestGetChannelFromChannelArg(t *testing.T) {
	th := app.Setup().InitBasic()

	team := th.BasicTeam
	channel := th.BasicChannel

	if found := getChannelFromChannelArg(""); found != nil {
		t.Fatal("shoudn't have gotten a channel", found)
	}

	if found := getChannelFromChannelArg(channel.Id); found == nil || found.Id != channel.Id {
		t.Fatal("got incorrect channel", found)
	}

	if found := getChannelFromChannelArg(model.NewId()); found != nil {
		t.Fatal("shouldn't have gotten a channel that doesn't exist", found)
	}

	if found := getChannelFromChannelArg(channel.Name); found != nil {
		t.Fatal("shouldn't have gotten a channel by name without team", found)
	}

	if found := getChannelFromChannelArg(team.Id + ":" + channel.Name); found == nil || found.Id != channel.Id {
		t.Fatal("got incorrect channel", found)
	}

	if found := getChannelFromChannelArg(team.Name + ":" + channel.Name); found == nil || found.Id != channel.Id {
		t.Fatal("got incorrect channel", found)
	}

	if found := getChannelFromChannelArg(team.Name + ":" + channel.Id); found == nil || found.Id != channel.Id {
		t.Fatal("got incorrect channel", found)
	}

	if found := getChannelFromChannelArg("notateam" + ":" + channel.Name); found != nil {
		t.Fatal("shouldn't have gotten a channel by name on incorrect team", found)
	}

	if found := getChannelFromChannelArg(team.Name + ":" + "notachannel"); found != nil {
		t.Fatal("shouldn't have gotten a channel that doesn't exist", found)
	}
}

func TestGetChannelsFromChannelArg(t *testing.T) {
	th := app.Setup().InitBasic()

	team := th.BasicTeam
	channel := th.BasicChannel
	channel2 := th.CreateChannel(team)

	if found := getChannelsFromChannelArgs([]string{}); len(found) != 0 {
		t.Fatal("shoudn't have gotten any channels", found)
	}

	if found := getChannelsFromChannelArgs([]string{channel.Id}); len(found) == 1 && found[0].Id != channel.Id {
		t.Fatal("got incorrect channel", found)
	}

	if found := getChannelsFromChannelArgs([]string{team.Name + ":" + channel2.Name}); len(found) == 1 && found[0].Id != channel2.Id {
		t.Fatal("got incorrect channel", found)
	}

	if found := getChannelsFromChannelArgs([]string{team.Name + ":" + channel.Name, team.Name + ":" + channel2.Name}); len(found) != 2 {
		t.Fatal("got incorrect number of channels", found)
	} else if !(found[0].Id == channel.Id && found[1].Id == channel2.Id) && !(found[1].Id == channel.Id && found[0].Id == channel2.Id) {
		t.Fatal("got incorrect channels", found[0], found[1])
	}

	if found := getChannelsFromChannelArgs([]string{channel.Id, channel2.Id}); len(found) != 2 {
		t.Fatal("got incorrect number of channels", found)
	} else if !(found[0].Id == channel.Id && found[1].Id == channel2.Id) && !(found[1].Id == channel.Id && found[0].Id == channel2.Id) {
		t.Fatal("got incorrect channels", found[0], found[1])
	}

	if found := getChannelsFromChannelArgs([]string{channel.Id, team.Name + ":" + channel2.Name}); len(found) != 2 {
		t.Fatal("got incorrect number of channels", found)
	} else if !(found[0].Id == channel.Id && found[1].Id == channel2.Id) && !(found[1].Id == channel.Id && found[0].Id == channel2.Id) {
		t.Fatal("got incorrect channels", found[0], found[1])
	}
}