summaryrefslogtreecommitdiffstats
path: root/app/team_test.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2017-01-30 15:39:00 +0100
committerCorey Hulen <corey@hulen.com>2017-01-30 09:39:00 -0500
commit95e3395a3b3f4920f6f426b75ff031999dcbeb64 (patch)
tree341d3eb30a94278c8da35f132ae081383f5ef60a /app/team_test.go
parent83ead5cac7bb0d274c84d20d443c125ea0391f37 (diff)
downloadchat-95e3395a3b3f4920f6f426b75ff031999dcbeb64.tar.gz
chat-95e3395a3b3f4920f6f426b75ff031999dcbeb64.tar.bz2
chat-95e3395a3b3f4920f6f426b75ff031999dcbeb64.zip
Add initial tests for app/team.go (#5208)
* . * add initial tests for app/team.go
Diffstat (limited to 'app/team_test.go')
-rw-r--r--app/team_test.go114
1 files changed, 114 insertions, 0 deletions
diff --git a/app/team_test.go b/app/team_test.go
new file mode 100644
index 000000000..64af0c4af
--- /dev/null
+++ b/app/team_test.go
@@ -0,0 +1,114 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package app
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/mattermost/platform/model"
+)
+
+func TestCreateTeam(t *testing.T) {
+ th := Setup().InitBasic()
+
+ id := model.NewId()
+ team := &model.Team{
+ DisplayName: "dn_" + id,
+ Name: "name" + id,
+ Email: "success+" + id + "@simulator.amazonses.com",
+ Type: model.TEAM_OPEN,
+ }
+
+ if _, err := CreateTeam(team); err != nil {
+ t.Log(err)
+ t.Fatal("Should create a new team")
+ }
+
+ if _, err := CreateTeam(th.BasicTeam); err == nil {
+ t.Fatal("Should not create a new team - team already exist")
+ }
+}
+
+func TestCreateTeamWithUser(t *testing.T) {
+ th := Setup().InitBasic()
+
+ id := model.NewId()
+ team := &model.Team{
+ DisplayName: "dn_" + id,
+ Name: "name" + id,
+ Email: "success+" + id + "@simulator.amazonses.com",
+ Type: model.TEAM_OPEN,
+ }
+
+ if _, err := CreateTeamWithUser(team, th.BasicUser.Id); err != nil {
+ t.Log(err)
+ t.Fatal("Should create a new team with existing user")
+ }
+
+ if _, err := CreateTeamWithUser(team, model.NewId()); err == nil {
+ t.Fatal("Should not create a new team - user does not exist")
+ }
+
+ user := model.User{Email: strings.ToLower(model.NewId()) + "success+test", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
+ ruser, _ := CreateUser(&user)
+
+ id = model.NewId()
+ team2 := &model.Team{
+ DisplayName: "dn_" + id,
+ Name: "name" + id,
+ Email: "success2+" + id + "@simulator.amazonses.com",
+ Type: model.TEAM_OPEN,
+ }
+
+ //Fail to create a team with user when user has set email without domain
+ if _, err := CreateTeamWithUser(team2, ruser.Id); err == nil {
+ t.Log(err.Message)
+ t.Fatal("Should not create a team with user when user has set email without domain")
+ } else {
+ if err.Message != "model.team.is_valid.email.app_error" {
+ t.Log(err)
+ t.Fatal("Invalid error message")
+ }
+ }
+}
+
+func TestUpdateTeam(t *testing.T) {
+ th := Setup().InitBasic()
+
+ th.BasicTeam.DisplayName = "Testing 123"
+
+ if updatedTeam, err := UpdateTeam(th.BasicTeam); err != nil {
+ t.Log(err)
+ t.Fatal("Should update the team")
+ } else {
+ if updatedTeam.DisplayName != "Testing 123" {
+ t.Fatal("Wrong Team DisplayName")
+ }
+ }
+}
+
+func TestAddUserToTeam(t *testing.T) {
+ th := Setup().InitBasic()
+
+ user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
+ ruser, _ := CreateUser(&user)
+
+ if _, err := AddUserToTeam(th.BasicTeam.Id, ruser.Id); err != nil {
+ t.Log(err)
+ t.Fatal("Should add user to the team")
+ }
+}
+
+func TestAddUserToTeamByTeamId(t *testing.T) {
+ th := Setup().InitBasic()
+
+ user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
+ ruser, _ := CreateUser(&user)
+
+ if err := AddUserToTeamByTeamId(th.BasicTeam.Id, ruser); err != nil {
+ t.Log(err)
+ t.Fatal("Should add user to the team")
+ }
+}