diff options
Diffstat (limited to 'spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb | 72 |
1 files changed, 53 insertions, 19 deletions
diff --git a/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb b/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb index ff3cc1841b4..90bb75d402f 100644 --- a/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb +++ b/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb @@ -91,38 +91,72 @@ RSpec.shared_examples Integrations::BaseSlashCommands do described_class.create!(project: project, properties: { token: 'token' }) end - it 'triggers the command' do - expect_any_instance_of(Gitlab::SlashCommands::Command).to receive(:execute) + context 'with verified request' do + before do + allow_next_instance_of(::Gitlab::SlashCommands::VerifyRequest) do |instance| + allow(instance).to receive(:valid?).and_return(true) + end + end - subject.trigger(params) - end + it 'triggers the command' do + expect_any_instance_of(Gitlab::SlashCommands::Command).to receive(:execute) + + subject.trigger(params) + end - shared_examples_for 'blocks command execution' do - it do - expect_any_instance_of(Gitlab::SlashCommands::Command).not_to receive(:execute) + shared_examples_for 'blocks command execution' do + it do + expect_any_instance_of(Gitlab::SlashCommands::Command).not_to receive(:execute) - result = subject.trigger(params) - expect(result[:text]).to match(error_message) + result = subject.trigger(params) + expect(result[:text]).to match(error_message) + end end - end - context 'when user is blocked' do - before do - chat_name.user.block + context 'when user is blocked' do + before do + chat_name.user.block + end + + it_behaves_like 'blocks command execution' do + let(:error_message) { 'you do not have access to the GitLab project' } + end end - it_behaves_like 'blocks command execution' do - let(:error_message) { 'you do not have access to the GitLab project' } + context 'when user is deactivated' do + before do + chat_name.user.deactivate + end + + it_behaves_like 'blocks command execution' do + let(:error_message) { "your #{Gitlab.config.gitlab.url} account needs to be reactivated" } + end end end - context 'when user is deactivated' do + context 'with unverified request' do before do - chat_name.user.deactivate + allow_next_instance_of(::Gitlab::SlashCommands::VerifyRequest) do |instance| + allow(instance).to receive(:valid?).and_return(false) + end end - it_behaves_like 'blocks command execution' do - let(:error_message) { "your #{Gitlab.config.gitlab.url} account needs to be reactivated" } + let(:params) do + { + team_domain: 'http://domain.tld', + channel_name: 'channel-test', + team_id: chat_name.team_id, + user_id: chat_name.chat_id, + response_url: 'http://domain.tld/commands', + token: 'token' + } + end + + it 'caches the slash command params and returns confirmation message' do + expect(Rails.cache).to receive(:write).with(an_instance_of(String), params, { expires_in: 3.minutes }) + expect_any_instance_of(Gitlab::SlashCommands::Presenters::Access).to receive(:confirm) + + subject.trigger(params) end end end |