summaryrefslogtreecommitdiffstats
path: root/api/command_test.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-01-08 22:57:38 -0600
committer=Corey Hulen <corey@hulen.com>2016-01-08 22:57:38 -0600
commite1f4cc4bb004a0a0d4bb6d68ff328233f9f72aa0 (patch)
tree8cf6a2257e43fae745bca6e5da14edd6bb5493f9 /api/command_test.go
parent3fba8e42b140c1189bf3c06882cce5e2231e63da (diff)
downloadchat-e1f4cc4bb004a0a0d4bb6d68ff328233f9f72aa0.tar.gz
chat-e1f4cc4bb004a0a0d4bb6d68ff328233f9f72aa0.tar.bz2
chat-e1f4cc4bb004a0a0d4bb6d68ff328233f9f72aa0.zip
Adding web service methods
Diffstat (limited to 'api/command_test.go')
-rw-r--r--api/command_test.go75
1 files changed, 74 insertions, 1 deletions
diff --git a/api/command_test.go b/api/command_test.go
index 8e0c2580e..b5c0558b8 100644
--- a/api/command_test.go
+++ b/api/command_test.go
@@ -107,6 +107,10 @@ func TestListTeamCommands(t *testing.T) {
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(user.Id))
+ c := &Context{}
+ c.RequestId = model.NewId()
+ c.IpAddress = "cmd_line"
+ UpdateRoles(c, user, model.ROLE_SYSTEM_ADMIN)
Client.LoginByEmail(team.Name, user.Email, "pwd")
cmd1 := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST}
@@ -117,7 +121,7 @@ func TestListTeamCommands(t *testing.T) {
} else {
cmds := result.Data.([]*model.Command)
- if len(hooks) != 1 {
+ if len(cmds) != 1 {
t.Fatal("incorrect number of cmd")
}
}
@@ -125,6 +129,75 @@ func TestListTeamCommands(t *testing.T) {
*utils.Cfg.ServiceSettings.EnableCommands = false
}
+func TestRegenToken(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))
+
+ c := &Context{}
+ c.RequestId = model.NewId()
+ c.IpAddress = "cmd_line"
+ UpdateRoles(c, user, model.ROLE_SYSTEM_ADMIN)
+ Client.LoginByEmail(team.Name, user.Email, "pwd")
+
+ cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST}
+ cmd = Client.Must(Client.CreateCommand(cmd)).Data.(*model.Command)
+
+ data := make(map[string]string)
+ data["id"] = cmd.Id
+
+ if result, err := Client.RegenCommandToken(data); err != nil {
+ t.Fatal(err)
+ } else {
+ if result.Data.(*model.Command).Token == cmd.Token {
+ t.Fatal("regen didn't work properly")
+ }
+ }
+
+ *utils.Cfg.ServiceSettings.EnableCommands = false
+}
+
+func TestDeleteCommand(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))
+
+ c := &Context{}
+ c.RequestId = model.NewId()
+ c.IpAddress = "cmd_line"
+ UpdateRoles(c, user, model.ROLE_SYSTEM_ADMIN)
+ Client.LoginByEmail(team.Name, user.Email, "pwd")
+
+ cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST}
+ cmd = Client.Must(Client.CreateCommand(cmd)).Data.(*model.Command)
+
+ data := make(map[string]string)
+ data["id"] = cmd.Id
+
+ if _, err := Client.DeleteCommand(data); err != nil {
+ t.Fatal(err)
+ }
+
+ cmds := Client.Must(Client.ListTeamCommands()).Data.([]*model.Command)
+ if len(cmds) != 0 {
+ t.Fatal("delete didn't work properly")
+ }
+
+ *utils.Cfg.ServiceSettings.EnableCommands = false
+}
+
// func TestSuggestRootCommands(t *testing.T) {
// Setup()