summaryrefslogtreecommitdiffstats
path: root/api/command_test.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-01-08 12:41:26 -0600
committer=Corey Hulen <corey@hulen.com>2016-01-08 12:41:26 -0600
commit3fba8e42b140c1189bf3c06882cce5e2231e63da (patch)
tree7a0721cecf6624fc9c1fd71449628472b941ddeb /api/command_test.go
parent001a4448ca5fb0018eeb442915b473b121c04bf3 (diff)
downloadchat-3fba8e42b140c1189bf3c06882cce5e2231e63da.tar.gz
chat-3fba8e42b140c1189bf3c06882cce5e2231e63da.tar.bz2
chat-3fba8e42b140c1189bf3c06882cce5e2231e63da.zip
partial fix for UI
Diffstat (limited to 'api/command_test.go')
-rw-r--r--api/command_test.go130
1 files changed, 121 insertions, 9 deletions
diff --git a/api/command_test.go b/api/command_test.go
index 8b996b9eb..8e0c2580e 100644
--- a/api/command_test.go
+++ b/api/command_test.go
@@ -3,15 +3,127 @@
package api
-// import (
-// "strings"
-// "testing"
-// "time"
-
-// "github.com/mattermost/platform/model"
-// "github.com/mattermost/platform/store"
-// "github.com/mattermost/platform/utils"
-// )
+import (
+ "testing"
+
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/store"
+ "github.com/mattermost/platform/utils"
+)
+
+func TestListCommands(t *testing.T) {
+ Setup()
+
+ team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
+ team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
+
+ user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
+ user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
+ store.Must(Srv.Store.User().VerifyEmail(user1.Id))
+
+ Client.LoginByEmail(team.Name, user1.Email, "pwd")
+
+ if results, err := Client.ListCommands(); err != nil {
+ t.Fatal(err)
+ } else {
+ commands := results.Data.([]*model.Command)
+ foundEcho := false
+
+ for _, command := range commands {
+ if command.Trigger == "echo" {
+ foundEcho = true
+ }
+ }
+
+ if !foundEcho {
+ t.Fatal("Couldn't find echo command")
+ }
+ }
+}
+
+func TestCreateCommand(t *testing.T) {
+ Setup()
+ *utils.Cfg.ServiceSettings.EnableCommands = true
+
+ team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
+ team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
+
+ user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
+ user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
+ store.Must(Srv.Store.User().VerifyEmail(user.Id))
+
+ Client.LoginByEmail(team.Name, user.Email, "pwd")
+
+ cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST}
+
+ if _, err := Client.CreateCommand(cmd); err == nil {
+ t.Fatal("should have failed because not admin")
+ }
+
+ c := &Context{}
+ c.RequestId = model.NewId()
+ c.IpAddress = "cmd_line"
+ UpdateRoles(c, user, model.ROLE_SYSTEM_ADMIN)
+ Client.LoginByEmail(team.Name, user.Email, "pwd")
+
+ var rcmd *model.Command
+ if result, err := Client.CreateCommand(cmd); err != nil {
+ t.Fatal(err)
+ } else {
+ rcmd = result.Data.(*model.Command)
+ }
+
+ if rcmd.CreatorId != user.Id {
+ t.Fatal("user ids didn't match")
+ }
+
+ if rcmd.TeamId != team.Id {
+ t.Fatal("team ids didn't match")
+ }
+
+ cmd = &model.Command{CreatorId: "123", TeamId: "456", URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST}
+ if result, err := Client.CreateCommand(cmd); err != nil {
+ t.Fatal(err)
+ } else {
+ if result.Data.(*model.Command).CreatorId != user.Id {
+ t.Fatal("bad user id wasn't overwritten")
+ }
+ if result.Data.(*model.Command).TeamId != team.Id {
+ t.Fatal("bad team id wasn't overwritten")
+ }
+ }
+
+ *utils.Cfg.ServiceSettings.EnableCommands = false
+}
+
+func TestListTeamCommands(t *testing.T) {
+ Setup()
+ *utils.Cfg.ServiceSettings.EnableCommands = true
+
+ team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
+ team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
+
+ user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
+ user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
+ store.Must(Srv.Store.User().VerifyEmail(user.Id))
+
+ Client.LoginByEmail(team.Name, user.Email, "pwd")
+
+ cmd1 := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST}
+ cmd1 = Client.Must(Client.CreateCommand(cmd1)).Data.(*model.Command)
+
+ if result, err := Client.ListTeamCommands(); err != nil {
+ t.Fatal(err)
+ } else {
+ cmds := result.Data.([]*model.Command)
+
+ if len(hooks) != 1 {
+ t.Fatal("incorrect number of cmd")
+ }
+ }
+
+ *utils.Cfg.ServiceSettings.EnableCommands = false
+}
// func TestSuggestRootCommands(t *testing.T) {
// Setup()