github.com/lologarithm/mattermost-server@v5.3.2-0.20181002060438-c82a84ed765b+incompatible/app/command_test.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 11 "github.com/mattermost/mattermost-server/model" 12 ) 13 14 func TestMoveCommand(t *testing.T) { 15 th := Setup().InitBasic() 16 defer th.TearDown() 17 18 sourceTeam := th.CreateTeam() 19 targetTeam := th.CreateTeam() 20 21 command := &model.Command{} 22 command.CreatorId = model.NewId() 23 command.Method = model.COMMAND_METHOD_POST 24 command.TeamId = sourceTeam.Id 25 command.URL = "http://nowhere.com/" 26 command.Trigger = "trigger1" 27 28 command, err := th.App.CreateCommand(command) 29 assert.Nil(t, err) 30 31 defer func() { 32 th.App.PermanentDeleteTeam(sourceTeam) 33 th.App.PermanentDeleteTeam(targetTeam) 34 }() 35 36 // Move a command and check the team is updated. 37 assert.Nil(t, th.App.MoveCommand(targetTeam, command)) 38 retrievedCommand, err := th.App.GetCommand(command.Id) 39 assert.Nil(t, err) 40 assert.EqualValues(t, targetTeam.Id, retrievedCommand.TeamId) 41 42 // Move it to the team it's already in. Nothing should change. 43 assert.Nil(t, th.App.MoveCommand(targetTeam, command)) 44 retrievedCommand, err = th.App.GetCommand(command.Id) 45 assert.Nil(t, err) 46 assert.EqualValues(t, targetTeam.Id, retrievedCommand.TeamId) 47 } 48 49 func TestCreateCommandPost(t *testing.T) { 50 th := Setup().InitBasic() 51 defer th.TearDown() 52 53 post := &model.Post{ 54 ChannelId: th.BasicChannel.Id, 55 UserId: th.BasicUser.Id, 56 Type: model.POST_SYSTEM_GENERIC, 57 } 58 59 resp := &model.CommandResponse{ 60 Text: "some message", 61 } 62 63 _, err := th.App.CreateCommandPost(post, th.BasicTeam.Id, resp) 64 if err == nil && err.Id != "api.context.invalid_param.app_error" { 65 t.Fatal("should have failed - bad post type") 66 } 67 }