diff options
author | James Fargher <proglottis@gmail.com> | 2019-01-30 11:10:04 +1300 |
---|---|---|
committer | James Fargher <proglottis@gmail.com> | 2019-02-07 10:55:30 +1300 |
commit | bdd1bac2f0ca6760376ae422c68ba9c787c199c3 (patch) | |
tree | 2b90be8ecb8f93c75ccd5247c6d47e330d70b7e1 /spec/lib/gitlab/chat/responder/slack_spec.rb | |
parent | f67690057b4711654f71565999040c1819aa0323 (diff) | |
download | gitlab-ce-bdd1bac2f0ca6760376ae422c68ba9c787c199c3.tar.gz |
Move ChatOps to Coremove_chatops_to_core
ChatOps used to be in the Ultimate tier.
Diffstat (limited to 'spec/lib/gitlab/chat/responder/slack_spec.rb')
-rw-r--r-- | spec/lib/gitlab/chat/responder/slack_spec.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/lib/gitlab/chat/responder/slack_spec.rb b/spec/lib/gitlab/chat/responder/slack_spec.rb new file mode 100644 index 00000000000..a1553232b32 --- /dev/null +++ b/spec/lib/gitlab/chat/responder/slack_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Chat::Responder::Slack do + let(:chat_name) { create(:chat_name, chat_id: 'U123') } + + let(:pipeline) do + pipeline = create(:ci_pipeline) + + pipeline.create_chat_data!( + response_url: 'http://example.com', + chat_name_id: chat_name.id + ) + + pipeline + end + + let(:build) { create(:ci_build, pipeline: pipeline) } + let(:responder) { described_class.new(build) } + + describe '#send_response' do + it 'sends a response back to Slack' do + expect(Gitlab::HTTP).to receive(:post).with( + 'http://example.com', + { headers: { Accept: 'application/json' }, body: 'hello'.to_json } + ) + + responder.send_response('hello') + end + end + + describe '#success' do + it 'returns the output for a successful build' do + expect(responder) + .to receive(:send_response) + .with(hash_including(text: /<@U123>:.+hello/, response_type: :in_channel)) + + responder.success('hello') + end + + it 'limits the output to a fixed size' do + expect(responder) + .to receive(:send_response) + .with(hash_including(text: /The output is too large/)) + + responder.success('a' * 4000) + end + + it 'does not send a response if the output is empty' do + expect(responder).not_to receive(:send_response) + + responder.success('') + end + end + + describe '#failure' do + it 'returns the output for a failed build' do + expect(responder).to receive(:send_response).with( + hash_including( + text: /<@U123>:.+Sorry, the build failed!/, + response_type: :in_channel + ) + ) + + responder.failure + end + end + + describe '#scheduled_output' do + it 'returns the output for a scheduled build' do + output = responder.scheduled_output + + expect(output).to eq({ text: '' }) + end + end +end |