debian-mirror-gitlab/spec/lib/gitlab/chat/responder_spec.rb

73 lines
2.1 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Gitlab::Chat::Responder, feature_category: :integrations do
2019-07-07 11:18:12 +05:30
describe '.responder_for' do
2023-04-23 21:23:45 +05:30
context 'when the feature flag is disabled' do
before do
stub_feature_flags(use_response_url_for_chat_responder: false)
end
context 'using a regular build' do
it 'returns nil' do
build = create(:ci_build)
expect(described_class.responder_for(build)).to be_nil
end
end
context 'using a chat build' do
it 'returns the responder for the build' do
pipeline = create(:ci_pipeline)
build = create(:ci_build, pipeline: pipeline)
integration = double(:integration, chat_responder: Gitlab::Chat::Responder::Slack)
chat_name = double(:chat_name, integration: integration)
chat_data = double(:chat_data, chat_name: chat_name)
allow(pipeline)
.to receive(:chat_data)
.and_return(chat_data)
2019-07-07 11:18:12 +05:30
2023-04-23 21:23:45 +05:30
expect(described_class.responder_for(build))
.to be_an_instance_of(Gitlab::Chat::Responder::Slack)
end
2019-07-07 11:18:12 +05:30
end
end
2023-04-23 21:23:45 +05:30
context 'when the feature flag is enabled' do
before do
stub_feature_flags(use_response_url_for_chat_responder: true)
end
context 'using a regular build' do
it 'returns nil' do
build = create(:ci_build)
expect(described_class.responder_for(build)).to be_nil
end
end
context 'using a chat build' do
let(:chat_name) { create(:chat_name, chat_id: 'U123') }
let(:pipeline) do
pipeline = create(:ci_pipeline)
pipeline.create_chat_data!(
response_url: 'https://hooks.slack.com/services/12345',
chat_name_id: chat_name.id
)
pipeline
end
2019-07-07 11:18:12 +05:30
2023-04-23 21:23:45 +05:30
let(:build) { create(:ci_build, pipeline: pipeline) }
let(:responder) { described_class.new(build) }
2019-07-07 11:18:12 +05:30
2023-04-23 21:23:45 +05:30
it 'returns the responder for the build' do
expect(described_class.responder_for(build))
.to be_an_instance_of(Gitlab::Chat::Responder::Slack)
end
2019-07-07 11:18:12 +05:30
end
end
end
end