From 001a4448ca5fb0018eeb442915b473b121c04bf3 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 6 Jan 2016 21:09:05 -0600 Subject: PLT-1429 adding sql storage for slash commands --- api/command_test.go | 400 ++++++++++++++++++++++++++-------------------------- 1 file changed, 200 insertions(+), 200 deletions(-) (limited to 'api/command_test.go') diff --git a/api/command_test.go b/api/command_test.go index f38cf1397..8b996b9eb 100644 --- a/api/command_test.go +++ b/api/command_test.go @@ -3,240 +3,240 @@ package api -import ( - "strings" - "testing" - "time" +// import ( +// "strings" +// "testing" +// "time" - "github.com/mattermost/platform/model" - "github.com/mattermost/platform/store" - "github.com/mattermost/platform/utils" -) +// "github.com/mattermost/platform/model" +// "github.com/mattermost/platform/store" +// "github.com/mattermost/platform/utils" +// ) -func TestSuggestRootCommands(t *testing.T) { - Setup() +// func TestSuggestRootCommands(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) +// 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)) +// 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") +// Client.LoginByEmail(team.Name, user1.Email, "pwd") - if _, err := Client.Command("", "", true); err == nil { - t.Fatal("Should fail") - } +// if _, err := Client.Command("", "", true); err == nil { +// t.Fatal("Should fail") +// } - rs1 := Client.Must(Client.Command("", "/", true)).Data.(*model.Command) +// rs1 := Client.Must(Client.Command("", "/", true)).Data.(*model.Command) - hasLogout := false - for _, v := range rs1.Suggestions { - if v.Suggestion == "/logout" { - hasLogout = true - } - } +// hasLogout := false +// for _, v := range rs1.Suggestions { +// if v.Suggestion == "/logout" { +// hasLogout = true +// } +// } - if !hasLogout { - t.Log(rs1.Suggestions) - t.Fatal("should have logout cmd") - } +// if !hasLogout { +// t.Log(rs1.Suggestions) +// t.Fatal("should have logout cmd") +// } - rs2 := Client.Must(Client.Command("", "/log", true)).Data.(*model.Command) +// rs2 := Client.Must(Client.Command("", "/log", true)).Data.(*model.Command) - if rs2.Suggestions[0].Suggestion != "/logout" { - t.Fatal("should have logout cmd") - } +// if rs2.Suggestions[0].Suggestion != "/logout" { +// t.Fatal("should have logout cmd") +// } - rs3 := Client.Must(Client.Command("", "/joi", true)).Data.(*model.Command) +// rs3 := Client.Must(Client.Command("", "/joi", true)).Data.(*model.Command) - if rs3.Suggestions[0].Suggestion != "/join" { - t.Fatal("should have join cmd") - } - - rs4 := Client.Must(Client.Command("", "/ech", true)).Data.(*model.Command) +// if rs3.Suggestions[0].Suggestion != "/join" { +// t.Fatal("should have join cmd") +// } + +// rs4 := Client.Must(Client.Command("", "/ech", true)).Data.(*model.Command) - if rs4.Suggestions[0].Suggestion != "/echo" { - t.Fatal("should have echo cmd") - } -} +// if rs4.Suggestions[0].Suggestion != "/echo" { +// t.Fatal("should have echo cmd") +// } +// } -func TestLogoutCommands(t *testing.T) { - Setup() +// func TestLogoutCommands(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) +// 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)) +// 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") +// Client.LoginByEmail(team.Name, user1.Email, "pwd") - rs1 := Client.Must(Client.Command("", "/logout", false)).Data.(*model.Command) - if rs1.GotoLocation != "/logout" { - t.Fatal("failed to logout") - } -} +// rs1 := Client.Must(Client.Command("", "/logout", false)).Data.(*model.Command) +// if rs1.GotoLocation != "/logout" { +// t.Fatal("failed to logout") +// } +// } -func TestJoinCommands(t *testing.T) { - Setup() +// func TestJoinCommands(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) +// 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)) +// 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") +// Client.LoginByEmail(team.Name, user1.Email, "pwd") - channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} - channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) - Client.Must(Client.LeaveChannel(channel1.Id)) +// channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} +// channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) +// Client.Must(Client.LeaveChannel(channel1.Id)) - channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} - channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel) - Client.Must(Client.LeaveChannel(channel2.Id)) +// channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} +// channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel) +// Client.Must(Client.LeaveChannel(channel2.Id)) - user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} - user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) - store.Must(Srv.Store.User().VerifyEmail(user1.Id)) +// user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} +// user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) +// store.Must(Srv.Store.User().VerifyEmail(user1.Id)) - data := make(map[string]string) - data["user_id"] = user2.Id - channel3 := Client.Must(Client.CreateDirectChannel(data)).Data.(*model.Channel) +// data := make(map[string]string) +// data["user_id"] = user2.Id +// channel3 := Client.Must(Client.CreateDirectChannel(data)).Data.(*model.Channel) - rs1 := Client.Must(Client.Command("", "/join aa", true)).Data.(*model.Command) - if rs1.Suggestions[0].Suggestion != "/join "+channel1.Name { - t.Fatal("should have join cmd") - } +// rs1 := Client.Must(Client.Command("", "/join aa", true)).Data.(*model.Command) +// if rs1.Suggestions[0].Suggestion != "/join "+channel1.Name { +// t.Fatal("should have join cmd") +// } - rs2 := Client.Must(Client.Command("", "/join bb", true)).Data.(*model.Command) - if rs2.Suggestions[0].Suggestion != "/join "+channel2.Name { - t.Fatal("should have join cmd") - } +// rs2 := Client.Must(Client.Command("", "/join bb", true)).Data.(*model.Command) +// if rs2.Suggestions[0].Suggestion != "/join "+channel2.Name { +// t.Fatal("should have join cmd") +// } - rs3 := Client.Must(Client.Command("", "/join", true)).Data.(*model.Command) - if len(rs3.Suggestions) != 2 { - t.Fatal("should have 2 join cmd") - } +// rs3 := Client.Must(Client.Command("", "/join", true)).Data.(*model.Command) +// if len(rs3.Suggestions) != 2 { +// t.Fatal("should have 2 join cmd") +// } - rs4 := Client.Must(Client.Command("", "/join ", true)).Data.(*model.Command) - if len(rs4.Suggestions) != 2 { - t.Fatal("should have 2 join cmd") - } +// rs4 := Client.Must(Client.Command("", "/join ", true)).Data.(*model.Command) +// if len(rs4.Suggestions) != 2 { +// t.Fatal("should have 2 join cmd") +// } - rs5 := Client.Must(Client.Command("", "/join "+channel2.Name, false)).Data.(*model.Command) - if !strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name) { - t.Fatal("failed to join channel") - } +// rs5 := Client.Must(Client.Command("", "/join "+channel2.Name, false)).Data.(*model.Command) +// if !strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name) { +// t.Fatal("failed to join channel") +// } - rs6 := Client.Must(Client.Command("", "/join "+channel3.Name, false)).Data.(*model.Command) - if strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name) { - t.Fatal("should not have joined direct message channel") - } +// rs6 := Client.Must(Client.Command("", "/join "+channel3.Name, false)).Data.(*model.Command) +// if strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name) { +// t.Fatal("should not have joined direct message channel") +// } - c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList) +// c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList) - if len(c1.Channels) != 4 { // 4 because of town-square, off-topic and direct - t.Fatal("didn't join channel") - } +// if len(c1.Channels) != 4 { // 4 because of town-square, off-topic and direct +// t.Fatal("didn't join channel") +// } - found := false - for _, c := range c1.Channels { - if c.Name == channel2.Name { - found = true - break - } - } - if !found { - t.Fatal("didn't join channel") - } -} - -func TestEchoCommand(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) +// found := false +// for _, c := range c1.Channels { +// if c.Name == channel2.Name { +// found = true +// break +// } +// } +// if !found { +// t.Fatal("didn't join channel") +// } +// } + +// func TestEchoCommand(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") - - channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} - channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) - - echoTestString := "/echo test" - - r1 := Client.Must(Client.Command(channel1.Id, echoTestString, false)).Data.(*model.Command) - if r1.Response != model.RESP_EXECUTED { - t.Fatal("Echo command failed to execute") - } - - time.Sleep(100 * time.Millisecond) - - p1 := Client.Must(Client.GetPosts(channel1.Id, 0, 2, "")).Data.(*model.PostList) - if len(p1.Order) != 1 { - t.Fatal("Echo command failed to send") - } -} - -func TestLoadTestUrlCommand(t *testing.T) { - Setup() - - // enable testing to use /loadtest but don't save it since we don't want to overwrite config.json - enableTesting := utils.Cfg.ServiceSettings.EnableTesting - defer func() { - utils.Cfg.ServiceSettings.EnableTesting = enableTesting - }() - - utils.Cfg.ServiceSettings.EnableTesting = 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") - - channel := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} - channel = Client.Must(Client.CreateChannel(channel)).Data.(*model.Channel) - - command := "/loadtest url " - if _, err := Client.Command(channel.Id, command, false); err == nil { - t.Fatal("/loadtest url with no url should've failed") - } - - command = "/loadtest url http://www.hopefullynonexistent.file/path/asdf/qwerty" - if _, err := Client.Command(channel.Id, command, false); err == nil { - t.Fatal("/loadtest url with invalid url should've failed") - } - - command = "/loadtest url https://raw.githubusercontent.com/mattermost/platform/master/README.md" - if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED { - t.Fatal("/loadtest url for README.md should've executed") - } - - command = "/loadtest url test-emoticons.md" - if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED { - t.Fatal("/loadtest url for test-emoticons.md should've executed") - } - - command = "/loadtest url test-emoticons" - if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED { - t.Fatal("/loadtest url for test-emoticons should've executed") - } - - posts := Client.Must(Client.GetPosts(channel.Id, 0, 5, "")).Data.(*model.PostList) - // note that this may make more than 3 posts if files are too long to fit in an individual post - if len(posts.Order) < 3 { - t.Fatal("/loadtest url made too few posts, perhaps there needs to be a delay before GetPosts in the test?") - } -} +// 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") + +// channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} +// channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) + +// echoTestString := "/echo test" + +// r1 := Client.Must(Client.Command(channel1.Id, echoTestString, false)).Data.(*model.Command) +// if r1.Response != model.RESP_EXECUTED { +// t.Fatal("Echo command failed to execute") +// } + +// time.Sleep(100 * time.Millisecond) + +// p1 := Client.Must(Client.GetPosts(channel1.Id, 0, 2, "")).Data.(*model.PostList) +// if len(p1.Order) != 1 { +// t.Fatal("Echo command failed to send") +// } +// } + +// func TestLoadTestUrlCommand(t *testing.T) { +// Setup() + +// // enable testing to use /loadtest but don't save it since we don't want to overwrite config.json +// enableTesting := utils.Cfg.ServiceSettings.EnableTesting +// defer func() { +// utils.Cfg.ServiceSettings.EnableTesting = enableTesting +// }() + +// utils.Cfg.ServiceSettings.EnableTesting = 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") + +// channel := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} +// channel = Client.Must(Client.CreateChannel(channel)).Data.(*model.Channel) + +// command := "/loadtest url " +// if _, err := Client.Command(channel.Id, command, false); err == nil { +// t.Fatal("/loadtest url with no url should've failed") +// } + +// command = "/loadtest url http://www.hopefullynonexistent.file/path/asdf/qwerty" +// if _, err := Client.Command(channel.Id, command, false); err == nil { +// t.Fatal("/loadtest url with invalid url should've failed") +// } + +// command = "/loadtest url https://raw.githubusercontent.com/mattermost/platform/master/README.md" +// if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED { +// t.Fatal("/loadtest url for README.md should've executed") +// } + +// command = "/loadtest url test-emoticons.md" +// if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED { +// t.Fatal("/loadtest url for test-emoticons.md should've executed") +// } + +// command = "/loadtest url test-emoticons" +// if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED { +// t.Fatal("/loadtest url for test-emoticons should've executed") +// } + +// posts := Client.Must(Client.GetPosts(channel.Id, 0, 5, "")).Data.(*model.PostList) +// // note that this may make more than 3 posts if files are too long to fit in an individual post +// if len(posts.Order) < 3 { +// t.Fatal("/loadtest url made too few posts, perhaps there needs to be a delay before GetPosts in the test?") +// } +// } -- cgit v1.2.3-1-g7c22 From 3fba8e42b140c1189bf3c06882cce5e2231e63da Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Fri, 8 Jan 2016 12:41:26 -0600 Subject: partial fix for UI --- api/command_test.go | 130 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 121 insertions(+), 9 deletions(-) (limited to 'api/command_test.go') 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() -- cgit v1.2.3-1-g7c22 From e1f4cc4bb004a0a0d4bb6d68ff328233f9f72aa0 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Fri, 8 Jan 2016 22:57:38 -0600 Subject: Adding web service methods --- api/command_test.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) (limited to 'api/command_test.go') 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() -- cgit v1.2.3-1-g7c22 From b1a7c1acf139efbb5312b4aa939bd94155e6a9e6 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Sat, 9 Jan 2016 08:54:07 -0600 Subject: adding different commands --- api/command_test.go | 173 ---------------------------------------------------- 1 file changed, 173 deletions(-) (limited to 'api/command_test.go') diff --git a/api/command_test.go b/api/command_test.go index b5c0558b8..1583ac5bb 100644 --- a/api/command_test.go +++ b/api/command_test.go @@ -198,179 +198,6 @@ func TestDeleteCommand(t *testing.T) { *utils.Cfg.ServiceSettings.EnableCommands = false } -// func TestSuggestRootCommands(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 _, err := Client.Command("", "", true); err == nil { -// t.Fatal("Should fail") -// } - -// rs1 := Client.Must(Client.Command("", "/", true)).Data.(*model.Command) - -// hasLogout := false -// for _, v := range rs1.Suggestions { -// if v.Suggestion == "/logout" { -// hasLogout = true -// } -// } - -// if !hasLogout { -// t.Log(rs1.Suggestions) -// t.Fatal("should have logout cmd") -// } - -// rs2 := Client.Must(Client.Command("", "/log", true)).Data.(*model.Command) - -// if rs2.Suggestions[0].Suggestion != "/logout" { -// t.Fatal("should have logout cmd") -// } - -// rs3 := Client.Must(Client.Command("", "/joi", true)).Data.(*model.Command) - -// if rs3.Suggestions[0].Suggestion != "/join" { -// t.Fatal("should have join cmd") -// } - -// rs4 := Client.Must(Client.Command("", "/ech", true)).Data.(*model.Command) - -// if rs4.Suggestions[0].Suggestion != "/echo" { -// t.Fatal("should have echo cmd") -// } -// } - -// func TestLogoutCommands(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") - -// rs1 := Client.Must(Client.Command("", "/logout", false)).Data.(*model.Command) -// if rs1.GotoLocation != "/logout" { -// t.Fatal("failed to logout") -// } -// } - -// func TestJoinCommands(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") - -// channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} -// channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) -// Client.Must(Client.LeaveChannel(channel1.Id)) - -// channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} -// channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel) -// Client.Must(Client.LeaveChannel(channel2.Id)) - -// user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"} -// user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) -// store.Must(Srv.Store.User().VerifyEmail(user1.Id)) - -// data := make(map[string]string) -// data["user_id"] = user2.Id -// channel3 := Client.Must(Client.CreateDirectChannel(data)).Data.(*model.Channel) - -// rs1 := Client.Must(Client.Command("", "/join aa", true)).Data.(*model.Command) -// if rs1.Suggestions[0].Suggestion != "/join "+channel1.Name { -// t.Fatal("should have join cmd") -// } - -// rs2 := Client.Must(Client.Command("", "/join bb", true)).Data.(*model.Command) -// if rs2.Suggestions[0].Suggestion != "/join "+channel2.Name { -// t.Fatal("should have join cmd") -// } - -// rs3 := Client.Must(Client.Command("", "/join", true)).Data.(*model.Command) -// if len(rs3.Suggestions) != 2 { -// t.Fatal("should have 2 join cmd") -// } - -// rs4 := Client.Must(Client.Command("", "/join ", true)).Data.(*model.Command) -// if len(rs4.Suggestions) != 2 { -// t.Fatal("should have 2 join cmd") -// } - -// rs5 := Client.Must(Client.Command("", "/join "+channel2.Name, false)).Data.(*model.Command) -// if !strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name) { -// t.Fatal("failed to join channel") -// } - -// rs6 := Client.Must(Client.Command("", "/join "+channel3.Name, false)).Data.(*model.Command) -// if strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name) { -// t.Fatal("should not have joined direct message channel") -// } - -// c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList) - -// if len(c1.Channels) != 4 { // 4 because of town-square, off-topic and direct -// t.Fatal("didn't join channel") -// } - -// found := false -// for _, c := range c1.Channels { -// if c.Name == channel2.Name { -// found = true -// break -// } -// } -// if !found { -// t.Fatal("didn't join channel") -// } -// } - -// func TestEchoCommand(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") - -// channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} -// channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) - -// echoTestString := "/echo test" - -// r1 := Client.Must(Client.Command(channel1.Id, echoTestString, false)).Data.(*model.Command) -// if r1.Response != model.RESP_EXECUTED { -// t.Fatal("Echo command failed to execute") -// } - -// time.Sleep(100 * time.Millisecond) - -// p1 := Client.Must(Client.GetPosts(channel1.Id, 0, 2, "")).Data.(*model.PostList) -// if len(p1.Order) != 1 { -// t.Fatal("Echo command failed to send") -// } -// } - // func TestLoadTestUrlCommand(t *testing.T) { // Setup() -- cgit v1.2.3-1-g7c22 From a70d5504091b93773e3cc0290be32ae51660bf30 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Sun, 10 Jan 2016 01:13:51 -0600 Subject: Adding loading testing commands --- api/command_test.go | 55 ----------------------------------------------------- 1 file changed, 55 deletions(-) (limited to 'api/command_test.go') diff --git a/api/command_test.go b/api/command_test.go index 1583ac5bb..8243b0ddf 100644 --- a/api/command_test.go +++ b/api/command_test.go @@ -197,58 +197,3 @@ func TestDeleteCommand(t *testing.T) { *utils.Cfg.ServiceSettings.EnableCommands = false } - -// func TestLoadTestUrlCommand(t *testing.T) { -// Setup() - -// // enable testing to use /loadtest but don't save it since we don't want to overwrite config.json -// enableTesting := utils.Cfg.ServiceSettings.EnableTesting -// defer func() { -// utils.Cfg.ServiceSettings.EnableTesting = enableTesting -// }() - -// utils.Cfg.ServiceSettings.EnableTesting = 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") - -// channel := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} -// channel = Client.Must(Client.CreateChannel(channel)).Data.(*model.Channel) - -// command := "/loadtest url " -// if _, err := Client.Command(channel.Id, command, false); err == nil { -// t.Fatal("/loadtest url with no url should've failed") -// } - -// command = "/loadtest url http://www.hopefullynonexistent.file/path/asdf/qwerty" -// if _, err := Client.Command(channel.Id, command, false); err == nil { -// t.Fatal("/loadtest url with invalid url should've failed") -// } - -// command = "/loadtest url https://raw.githubusercontent.com/mattermost/platform/master/README.md" -// if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED { -// t.Fatal("/loadtest url for README.md should've executed") -// } - -// command = "/loadtest url test-emoticons.md" -// if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED { -// t.Fatal("/loadtest url for test-emoticons.md should've executed") -// } - -// command = "/loadtest url test-emoticons" -// if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED { -// t.Fatal("/loadtest url for test-emoticons should've executed") -// } - -// posts := Client.Must(Client.GetPosts(channel.Id, 0, 5, "")).Data.(*model.PostList) -// // note that this may make more than 3 posts if files are too long to fit in an individual post -// if len(posts.Order) < 3 { -// t.Fatal("/loadtest url made too few posts, perhaps there needs to be a delay before GetPosts in the test?") -// } -// } -- cgit v1.2.3-1-g7c22 From 2bf43e79582c2e8ca50caa29d7457716112b4796 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Mon, 11 Jan 2016 09:39:09 -0600 Subject: Switching to enable integrations for testing --- api/command_test.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'api/command_test.go') diff --git a/api/command_test.go b/api/command_test.go index 8243b0ddf..e5e954170 100644 --- a/api/command_test.go +++ b/api/command_test.go @@ -43,6 +43,11 @@ func TestListCommands(t *testing.T) { func TestCreateCommand(t *testing.T) { Setup() + + enableCommands := *utils.Cfg.ServiceSettings.EnableCommands + defer func() { + utils.Cfg.ServiceSettings.EnableCommands = &enableCommands + }() *utils.Cfg.ServiceSettings.EnableCommands = true team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} @@ -92,12 +97,14 @@ func TestCreateCommand(t *testing.T) { t.Fatal("bad team id wasn't overwritten") } } - - *utils.Cfg.ServiceSettings.EnableCommands = false } func TestListTeamCommands(t *testing.T) { Setup() + enableCommands := *utils.Cfg.ServiceSettings.EnableCommands + defer func() { + utils.Cfg.ServiceSettings.EnableCommands = &enableCommands + }() *utils.Cfg.ServiceSettings.EnableCommands = true team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} @@ -125,12 +132,14 @@ func TestListTeamCommands(t *testing.T) { t.Fatal("incorrect number of cmd") } } - - *utils.Cfg.ServiceSettings.EnableCommands = false } func TestRegenToken(t *testing.T) { Setup() + enableCommands := *utils.Cfg.ServiceSettings.EnableCommands + defer func() { + utils.Cfg.ServiceSettings.EnableCommands = &enableCommands + }() *utils.Cfg.ServiceSettings.EnableCommands = true team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} @@ -159,12 +168,14 @@ func TestRegenToken(t *testing.T) { t.Fatal("regen didn't work properly") } } - - *utils.Cfg.ServiceSettings.EnableCommands = false } func TestDeleteCommand(t *testing.T) { Setup() + enableCommands := *utils.Cfg.ServiceSettings.EnableCommands + defer func() { + utils.Cfg.ServiceSettings.EnableCommands = &enableCommands + }() *utils.Cfg.ServiceSettings.EnableCommands = true team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} @@ -194,6 +205,4 @@ func TestDeleteCommand(t *testing.T) { if len(cmds) != 0 { t.Fatal("delete didn't work properly") } - - *utils.Cfg.ServiceSettings.EnableCommands = false } -- cgit v1.2.3-1-g7c22 From 6e2c1b7fd5248c6a4a91edcd59fa124c8d3c744a Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Fri, 15 Jan 2016 10:58:51 -0600 Subject: Adding test command --- api/command_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'api/command_test.go') diff --git a/api/command_test.go b/api/command_test.go index e5e954170..541e62e51 100644 --- a/api/command_test.go +++ b/api/command_test.go @@ -5,6 +5,7 @@ package api import ( "testing" + "time" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" @@ -206,3 +207,68 @@ func TestDeleteCommand(t *testing.T) { t.Fatal("delete didn't work properly") } } + +func TestTestCommand(t *testing.T) { + Setup() + enableCommands := *utils.Cfg.ServiceSettings.EnableCommands + defer func() { + utils.Cfg.ServiceSettings.EnableCommands = &enableCommands + }() + *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") + + channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} + channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) + + cmd1 := &model.Command{ + URL: "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress + "/api/v1/commands/test", + Method: model.COMMAND_METHOD_POST, + Trigger: "test", + } + + cmd1 = Client.Must(Client.CreateCommand(cmd1)).Data.(*model.Command) + + r1 := Client.Must(Client.Command(channel1.Id, "/test", false)).Data.(*model.CommandResponse) + if r1 == nil { + t.Fatal("Test command failed to execute") + } + + time.Sleep(100 * time.Millisecond) + + p1 := Client.Must(Client.GetPosts(channel1.Id, 0, 2, "")).Data.(*model.PostList) + if len(p1.Order) != 1 { + t.Fatal("Test command failed to send") + } + + cmd2 := &model.Command{ + URL: "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress + "/api/v1/commands/test", + Method: model.COMMAND_METHOD_GET, + Trigger: "test2", + } + + cmd2 = Client.Must(Client.CreateCommand(cmd2)).Data.(*model.Command) + + r2 := Client.Must(Client.Command(channel1.Id, "/test2", false)).Data.(*model.CommandResponse) + if r2 == nil { + t.Fatal("Test2 command failed to execute") + } + + time.Sleep(100 * time.Millisecond) + + p2 := Client.Must(Client.GetPosts(channel1.Id, 0, 2, "")).Data.(*model.PostList) + if len(p2.Order) != 2 { + t.Fatal("Test command failed to send") + } +} -- cgit v1.2.3-1-g7c22