command_invite_people_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
  2. // See LICENSE.txt for license information.
  3. package app
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/mattermost/mattermost-server/v5/model"
  8. )
  9. func TestInvitePeopleProvider(t *testing.T) {
  10. th := Setup(t).InitBasic()
  11. defer th.TearDown()
  12. th.App.UpdateConfig(func(cfg *model.Config) {
  13. *cfg.EmailSettings.SendEmailNotifications = true
  14. *cfg.ServiceSettings.EnableEmailInvitations = true
  15. })
  16. cmd := InvitePeopleProvider{}
  17. // Test without required permissions
  18. args := &model.CommandArgs{
  19. T: func(s string, args ...interface{}) string { return s },
  20. ChannelId: th.BasicChannel.Id,
  21. TeamId: th.BasicTeam.Id,
  22. UserId: th.BasicUser.Id,
  23. Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: ""}}},
  24. }
  25. actual := cmd.DoCommand(th.App, args, model.NewId()+"@simulator.amazonses.com")
  26. assert.Equal(t, "api.command_invite_people.permission.app_error", actual.Text)
  27. // Test with required permissions.
  28. args.Session.TeamMembers[0].Roles = model.TEAM_USER_ROLE_ID
  29. actual = cmd.DoCommand(th.App, args, model.NewId()+"@simulator.amazonses.com")
  30. assert.Equal(t, "api.command.invite_people.sent", actual.Text)
  31. }