diff options
Diffstat (limited to 'spec/lib/gitlab/slash_commands/verify_request_spec.rb')
-rw-r--r-- | spec/lib/gitlab/slash_commands/verify_request_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/lib/gitlab/slash_commands/verify_request_spec.rb b/spec/lib/gitlab/slash_commands/verify_request_spec.rb new file mode 100644 index 00000000000..df6052ded93 --- /dev/null +++ b/spec/lib/gitlab/slash_commands/verify_request_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::SlashCommands::VerifyRequest, feature_category: :integrations do + let_it_be(:integration) { create(:slack_slash_commands_integration) } + let_it_be(:chat_name) { create(:chat_name) } + let(:response_url) { 'http://www.example.com/' } + + subject(:verification) { described_class.new(integration, chat_name, response_url) } + + describe '#approve!' do + before do + stub_request(:post, "http://www.example.com/").to_return(status: 200, body: 'ok') + end + + it 'updates the token' do + expect { verification.approve! }.to change { chat_name.reload.token }.to(integration.token) + end + + it 'updates the ephemeral message' do + expect(Gitlab::HTTP).to receive(:post).with( + response_url, a_hash_including(body: an_instance_of(String), headers: an_instance_of(Hash)) + ).once + + verification.approve! + end + end + + describe '#valid?' do + it 'compares tokens' do + expect(ActiveSupport::SecurityUtils).to receive(:secure_compare).with(integration.token, chat_name.token) + verification.valid? + end + end +end |