summaryrefslogtreecommitdiffstats
path: root/api4/team_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-04-04 02:34:14 +0900
committerCorey Hulen <corey@hulen.com>2017-04-03 10:34:14 -0700
commit43e795448f62fa86f3dad7940fc2297c44a6ea9c (patch)
treeaec7f651c2177f9cc02824f014bccd81e96c542a /api4/team_test.go
parent6b61834ab14e9a4e51c29dd2904a1332c327aae6 (diff)
downloadchat-43e795448f62fa86f3dad7940fc2297c44a6ea9c.tar.gz
chat-43e795448f62fa86f3dad7940fc2297c44a6ea9c.tar.bz2
chat-43e795448f62fa86f3dad7940fc2297c44a6ea9c.zip
APIv4 post /teams/search (#5931)
Diffstat (limited to 'api4/team_test.go')
-rw-r--r--api4/team_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/api4/team_test.go b/api4/team_test.go
index 6127919c1..227b0958b 100644
--- a/api4/team_test.go
+++ b/api4/team_test.go
@@ -7,6 +7,7 @@ import (
"encoding/binary"
"fmt"
"net/http"
+ "reflect"
"strconv"
"strings"
"testing"
@@ -405,6 +406,81 @@ func TestGetTeamByName(t *testing.T) {
CheckForbiddenStatus(t, resp)
}
+func TestSearchAllTeams(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+ oTeam := th.BasicTeam
+
+ pTeam := &model.Team{DisplayName: "PName", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE}
+ Client.CreateTeam(pTeam)
+
+ rteams, resp := Client.SearchTeams(&model.TeamSearch{Term: oTeam.Name})
+ CheckNoError(t, resp)
+
+ if len(rteams) != 1 {
+ t.Fatal("should have returned 1 team")
+ }
+
+ if !reflect.DeepEqual(rteams[0], oTeam) {
+ t.Fatal("invalid team")
+ }
+
+ rteams, resp = Client.SearchTeams(&model.TeamSearch{Term: oTeam.DisplayName})
+ CheckNoError(t, resp)
+
+ if len(rteams) != 1 {
+ t.Fatal("should have returned 1 team")
+ }
+
+ if !reflect.DeepEqual(rteams[0], oTeam) {
+ t.Fatal("invalid team")
+ }
+
+ rteams, resp = Client.SearchTeams(&model.TeamSearch{Term: pTeam.Name})
+ CheckNoError(t, resp)
+
+ if len(rteams) != 0 {
+ t.Fatal("should have not returned team")
+ }
+
+ rteams, resp = Client.SearchTeams(&model.TeamSearch{Term: pTeam.DisplayName})
+ CheckNoError(t, resp)
+
+ if len(rteams) != 0 {
+ t.Fatal("should have not returned team")
+ }
+
+ rteams, resp = th.SystemAdminClient.SearchTeams(&model.TeamSearch{Term: oTeam.Name})
+ CheckNoError(t, resp)
+
+ if len(rteams) != 1 {
+ t.Fatal("should have returned 1 team")
+ }
+
+ rteams, resp = th.SystemAdminClient.SearchTeams(&model.TeamSearch{Term: pTeam.DisplayName})
+ CheckNoError(t, resp)
+
+ if len(rteams) != 1 {
+ t.Fatal("should have returned 1 team")
+ }
+
+ rteams, resp = Client.SearchTeams(&model.TeamSearch{Term: "junk"})
+ CheckNoError(t, resp)
+
+ if len(rteams) != 0 {
+ t.Fatal("should have not returned team")
+ }
+
+ Client.Logout()
+
+ rteams, resp = Client.SearchTeams(&model.TeamSearch{Term: pTeam.Name})
+ CheckUnauthorizedStatus(t, resp)
+
+ rteams, resp = Client.SearchTeams(&model.TeamSearch{Term: pTeam.DisplayName})
+ CheckUnauthorizedStatus(t, resp)
+}
+
func TestGetTeamsForUser(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()