From b066b6df138e88e75cb40f1ec3e58fbd13e61909 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 12 Sep 2017 09:19:52 -0500 Subject: Remove global app references (#7433) * remove global app references * test fix * fix api4 test compilation --- app/team_test.go | 62 +++++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'app/team_test.go') diff --git a/app/team_test.go b/app/team_test.go index 547904aa5..b074ed14f 100644 --- a/app/team_test.go +++ b/app/team_test.go @@ -11,8 +11,7 @@ import ( ) func TestCreateTeam(t *testing.T) { - a := Global() - th := a.Setup().InitBasic() + th := Setup().InitBasic() id := model.NewId() team := &model.Team{ @@ -22,19 +21,18 @@ func TestCreateTeam(t *testing.T) { Type: model.TEAM_OPEN, } - if _, err := a.CreateTeam(team); err != nil { + if _, err := th.App.CreateTeam(team); err != nil { t.Log(err) t.Fatal("Should create a new team") } - if _, err := a.CreateTeam(th.BasicTeam); err == nil { + if _, err := th.App.CreateTeam(th.BasicTeam); err == nil { t.Fatal("Should not create a new team - team already exist") } } func TestCreateTeamWithUser(t *testing.T) { - a := Global() - th := a.Setup().InitBasic() + th := Setup().InitBasic() id := model.NewId() team := &model.Team{ @@ -44,17 +42,17 @@ func TestCreateTeamWithUser(t *testing.T) { Type: model.TEAM_OPEN, } - if _, err := a.CreateTeamWithUser(team, th.BasicUser.Id); err != nil { + if _, err := th.App.CreateTeamWithUser(team, th.BasicUser.Id); err != nil { t.Log(err) t.Fatal("Should create a new team with existing user") } - if _, err := a.CreateTeamWithUser(team, model.NewId()); err == nil { + if _, err := th.App.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, _ := a.CreateUser(&user) + ruser, _ := th.App.CreateUser(&user) id = model.NewId() team2 := &model.Team{ @@ -65,7 +63,7 @@ func TestCreateTeamWithUser(t *testing.T) { } //Fail to create a team with user when user has set email without domain - if _, err := a.CreateTeamWithUser(team2, ruser.Id); err == nil { + if _, err := th.App.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 { @@ -77,12 +75,11 @@ func TestCreateTeamWithUser(t *testing.T) { } func TestUpdateTeam(t *testing.T) { - a := Global() - th := a.Setup().InitBasic() + th := Setup().InitBasic() th.BasicTeam.DisplayName = "Testing 123" - if updatedTeam, err := a.UpdateTeam(th.BasicTeam); err != nil { + if updatedTeam, err := th.App.UpdateTeam(th.BasicTeam); err != nil { t.Log(err) t.Fatal("Should update the team") } else { @@ -93,36 +90,33 @@ func TestUpdateTeam(t *testing.T) { } func TestAddUserToTeam(t *testing.T) { - a := Global() - th := a.Setup().InitBasic() + 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, _ := a.CreateUser(&user) + ruser, _ := th.App.CreateUser(&user) - if _, err := a.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err != nil { + if _, err := th.App.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err != nil { t.Log(err) t.Fatal("Should add user to the team") } } func TestAddUserToTeamByTeamId(t *testing.T) { - a := Global() - th := a.Setup().InitBasic() + 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, _ := a.CreateUser(&user) + ruser, _ := th.App.CreateUser(&user) - if err := a.AddUserToTeamByTeamId(th.BasicTeam.Id, ruser); err != nil { + if err := th.App.AddUserToTeamByTeamId(th.BasicTeam.Id, ruser); err != nil { t.Log(err) t.Fatal("Should add user to the team") } } func TestPermanentDeleteTeam(t *testing.T) { - a := Global() - th := a.Setup().InitBasic() + th := Setup().InitBasic() - team, err := a.CreateTeam(&model.Team{ + team, err := th.App.CreateTeam(&model.Team{ DisplayName: "deletion-test", Name: "deletion-test", Email: "foo@foo.com", @@ -132,10 +126,10 @@ func TestPermanentDeleteTeam(t *testing.T) { t.Fatal(err.Error()) } defer func() { - a.PermanentDeleteTeam(team) + th.App.PermanentDeleteTeam(team) }() - command, err := a.CreateCommand(&model.Command{ + command, err := th.App.CreateCommand(&model.Command{ CreatorId: th.BasicUser.Id, TeamId: team.Id, Trigger: "foo", @@ -145,37 +139,37 @@ func TestPermanentDeleteTeam(t *testing.T) { if err != nil { t.Fatal(err.Error()) } - defer a.DeleteCommand(command.Id) + defer th.App.DeleteCommand(command.Id) - if command, err = a.GetCommand(command.Id); command == nil || err != nil { + if command, err = th.App.GetCommand(command.Id); command == nil || err != nil { t.Fatal("unable to get new command") } - if err := a.PermanentDeleteTeam(team); err != nil { + if err := th.App.PermanentDeleteTeam(team); err != nil { t.Fatal(err.Error()) } - if command, err = a.GetCommand(command.Id); command != nil || err == nil { + if command, err = th.App.GetCommand(command.Id); command != nil || err == nil { t.Fatal("command wasn't deleted") } // Test deleting a team with no channels. team = th.CreateTeam() defer func() { - a.PermanentDeleteTeam(team) + th.App.PermanentDeleteTeam(team) }() - if channels, err := a.GetPublicChannelsForTeam(team.Id, 0, 1000); err != nil { + if channels, err := th.App.GetPublicChannelsForTeam(team.Id, 0, 1000); err != nil { t.Fatal(err) } else { for _, channel := range *channels { - if err2 := a.PermanentDeleteChannel(channel); err2 != nil { + if err2 := th.App.PermanentDeleteChannel(channel); err2 != nil { t.Fatal(err) } } } - if err := a.PermanentDeleteTeam(team); err != nil { + if err := th.App.PermanentDeleteTeam(team); err != nil { t.Fatal(err) } } -- cgit v1.2.3-1-g7c22