коммит произвёл
GitHub
родитель
61cc7a8680
Коммит
c5c6a5ce53
@@ -1730,3 +1730,88 @@ func TestPluginAPISearchPostsInTeamByUser(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginAPICreateCommandAndListCommands(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
foundCommand := func(listXCommand func(teamId string) ([]*model.Command, error)) bool {
|
||||
cmds, appErr := listXCommand(th.BasicTeam.Id)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
for _, cmd := range cmds {
|
||||
if cmd.Trigger == "testcmd" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
require.False(t, foundCommand(api.ListCommands))
|
||||
|
||||
cmd := &model.Command{
|
||||
TeamId: th.BasicTeam.Id,
|
||||
Trigger: "testcmd",
|
||||
Method: "G",
|
||||
URL: "http://test.com/testcmd",
|
||||
}
|
||||
|
||||
cmd, appErr := api.CreateCommand(cmd)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
newCmd, appErr := api.GetCommand(cmd.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, "pluginid", newCmd.PluginId)
|
||||
require.Equal(t, "", newCmd.CreatorId)
|
||||
require.True(t, foundCommand(api.ListCommands))
|
||||
require.True(t, foundCommand(api.ListCustomCommands))
|
||||
require.False(t, foundCommand(api.ListPluginCommands))
|
||||
}
|
||||
|
||||
func TestPluginAPIUpdateCommand(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
cmd := &model.Command{
|
||||
TeamId: th.BasicTeam.Id,
|
||||
Trigger: "testcmd",
|
||||
Method: "G",
|
||||
URL: "http://test.com/testcmd",
|
||||
}
|
||||
|
||||
cmd, appErr := api.CreateCommand(cmd)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
newCmd, appErr := api.GetCommand(cmd.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, "pluginid", newCmd.PluginId)
|
||||
require.Equal(t, "", newCmd.CreatorId)
|
||||
|
||||
newCmd.Trigger = "NewTrigger"
|
||||
newCmd.PluginId = "CannotChangeMe"
|
||||
newCmd2, appErr := api.UpdateCommand(newCmd.Id, newCmd)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, "pluginid", newCmd2.PluginId)
|
||||
require.Equal(t, "newtrigger", newCmd2.Trigger)
|
||||
|
||||
team1 := th.CreateTeam()
|
||||
|
||||
newCmd2.PluginId = "CannotChangeMe"
|
||||
newCmd2.Trigger = "anotherNewTrigger"
|
||||
newCmd2.TeamId = team1.Id
|
||||
newCmd3, appErr := api.UpdateCommand(newCmd2.Id, newCmd2)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, "pluginid", newCmd3.PluginId)
|
||||
require.Equal(t, "anothernewtrigger", newCmd3.Trigger)
|
||||
require.Equal(t, team1.Id, newCmd3.TeamId)
|
||||
|
||||
newCmd3.Trigger = "anotherNewTriggerAgain"
|
||||
newCmd3.TeamId = ""
|
||||
newCmd4, appErr := api.UpdateCommand(newCmd2.Id, newCmd2)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, "anothernewtriggeragain", newCmd4.Trigger)
|
||||
require.Equal(t, team1.Id, newCmd4.TeamId)
|
||||
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user