diff options
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/helpers/email_helpers.rb | 12 | ||||
-rw-r--r-- | spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb | 72 |
2 files changed, 65 insertions, 19 deletions
diff --git a/spec/support/helpers/email_helpers.rb b/spec/support/helpers/email_helpers.rb index 9dffe035b2a..0bfcd88de4b 100644 --- a/spec/support/helpers/email_helpers.rb +++ b/spec/support/helpers/email_helpers.rb @@ -14,6 +14,18 @@ module EmailHelpers ActiveJob::Base.queue_adapter.enqueued_jobs.clear end + def expect_only_one_email_to_be_sent(subject:, to:) + count_of_sent_emails = ActionMailer::Base.deliveries.count + expect(count_of_sent_emails).to eq(1), "Expected only one email to be sent, but #{count_of_sent_emails} emails were sent instead" + + return unless count_of_sent_emails == 1 + + message = ActionMailer::Base.deliveries.first + + expect(message.subject).to eq(subject), "Expected '#{subject}' email to be sent, but '#{message.subject}' email was sent instead" + expect(message.to).to match_array(to), "Expected the email to be sent to #{to}, but it was sent to #{message.to} instead" + end + def should_only_email(*users, kind: :to) recipients = email_recipients(kind: kind) 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 |