github.com/jlevesy/mattermost-server@v5.3.2-0.20181003190404-7468f35cb0c8+incompatible/app/command_invite_people_test.go (about) 1 // Copyright (c) 2015-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 TestInvitePeopleProvider(t *testing.T) { 15 th := Setup().InitBasic() 16 defer th.TearDown() 17 18 enableEmailInvitations := *th.App.Config().ServiceSettings.EnableEmailInvitations 19 defer func() { 20 th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableEmailInvitations = &enableEmailInvitations }) 21 }() 22 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableEmailInvitations = true }) 23 24 cmd := InvitePeopleProvider{} 25 26 // Test without required permissions 27 args := &model.CommandArgs{ 28 T: func(s string, args ...interface{}) string { return s }, 29 ChannelId: th.BasicChannel.Id, 30 TeamId: th.BasicTeam.Id, 31 UserId: th.BasicUser.Id, 32 Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: ""}}}, 33 } 34 35 actual := cmd.DoCommand(th.App, args, model.NewId()+"@simulator.amazonses.com") 36 assert.Equal(t, "api.command_invite_people.permission.app_error", actual.Text) 37 38 // Test with required permissions. 39 args.Session.TeamMembers[0].Roles = model.TEAM_USER_ROLE_ID 40 actual = cmd.DoCommand(th.App, args, model.NewId()+"@simulator.amazonses.com") 41 assert.Equal(t, "api.command.invite_people.sent", actual.Text) 42 }