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-05-27 22:25:52 +05:30
|
|
|
context 'using a regular build' do
|
|
|
|
it 'returns nil' do
|
|
|
|
build = create(:ci_build)
|
2023-04-23 21:23:45 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(described_class.responder_for(build)).to be_nil
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context 'using a chat build' do
|
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline) }
|
|
|
|
let_it_be(:build) { create(:ci_build, pipeline: pipeline) }
|
2023-04-23 21:23:45 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context "when response_url starts with 'https://hooks.slack.com/'" do
|
|
|
|
before do
|
|
|
|
pipeline.build_chat_data(response_url: 'https://hooks.slack.com/services/12345', chat_name_id: 'U123')
|
2023-04-23 21:23:45 +05:30
|
|
|
end
|
2023-05-27 22:25:52 +05:30
|
|
|
|
|
|
|
it { expect(described_class.responder_for(build)).to be_an_instance_of(Gitlab::Chat::Responder::Slack) }
|
2023-04-23 21:23:45 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context "when response_url does not start with 'https://hooks.slack.com/'" do
|
|
|
|
before do
|
|
|
|
pipeline.build_chat_data(response_url: 'https://mattermost.example.com/services/12345', chat_name_id: 'U123')
|
2023-04-23 21:23:45 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it { expect(described_class.responder_for(build)).to be_an_instance_of(Gitlab::Chat::Responder::Mattermost) }
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|