diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 14:22:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 14:22:11 +0000 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/models/integrations | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) | |
download | gitlab-ce-0c872e02b2c822e3397515ec324051ff540f0cd5.tar.gz |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/models/integrations')
-rw-r--r-- | spec/models/integrations/base_chat_notification_spec.rb | 29 | ||||
-rw-r--r-- | spec/models/integrations/base_slack_notification_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/integrations/chat_message/pipeline_message_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/integrations/drone_ci_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/integrations/flowdock_spec.rb | 54 | ||||
-rw-r--r-- | spec/models/integrations/jira_spec.rb | 33 | ||||
-rw-r--r-- | spec/models/integrations/slack_spec.rb | 6 |
7 files changed, 61 insertions, 93 deletions
diff --git a/spec/models/integrations/base_chat_notification_spec.rb b/spec/models/integrations/base_chat_notification_spec.rb index b959ead2cae..67fc09fd8b5 100644 --- a/spec/models/integrations/base_chat_notification_spec.rb +++ b/spec/models/integrations/base_chat_notification_spec.rb @@ -34,7 +34,7 @@ RSpec.describe Integrations::BaseChatNotification do webhook: webhook_url ) - WebMock.stub_request(:post, webhook_url) + WebMock.stub_request(:post, webhook_url) if webhook_url.present? subject.active = true end @@ -55,6 +55,33 @@ RSpec.describe Integrations::BaseChatNotification do end end + context 'when webhook is blank' do + let(:webhook_url) { '' } + + it 'returns false' do + expect(chat_integration).not_to receive(:notify) + expect(chat_integration.execute(data)).to be false + end + + context 'when webhook is not required' do + it 'returns true' do + allow(chat_integration).to receive(:requires_webhook?).and_return(false) + + expect(chat_integration).to receive(:notify).and_return(true) + expect(chat_integration.execute(data)).to be true + end + end + end + + context 'when event is not supported' do + it 'returns false' do + allow(chat_integration).to receive(:supported_events).and_return(['foo']) + + expect(chat_integration).not_to receive(:notify) + expect(chat_integration.execute(data)).to be false + end + end + context 'with a project with name containing spaces' do it 'does not remove spaces' do allow(project).to receive(:full_name).and_return('Project Name') diff --git a/spec/models/integrations/base_slack_notification_spec.rb b/spec/models/integrations/base_slack_notification_spec.rb new file mode 100644 index 00000000000..8f7f4e8858d --- /dev/null +++ b/spec/models/integrations/base_slack_notification_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Integrations::BaseSlackNotification do + # This spec should only contain tests that cannot be tested through + # `base_slack_notification_shared_examples.rb`. + + describe '#metrics_key_prefix (private method)' do + it 'raises a NotImplementedError error when not defined' do + subclass = Class.new(described_class) + + expect { subclass.new.send(:metrics_key_prefix) }.to raise_error(NotImplementedError) + end + end +end diff --git a/spec/models/integrations/chat_message/pipeline_message_spec.rb b/spec/models/integrations/chat_message/pipeline_message_spec.rb index f3388853b37..413cb097327 100644 --- a/spec/models/integrations/chat_message/pipeline_message_spec.rb +++ b/spec/models/integrations/chat_message/pipeline_message_spec.rb @@ -40,8 +40,6 @@ RSpec.describe Integrations::ChatMessage::PipelineMessage do let(:has_yaml_errors) { false } - it_behaves_like Integrations::ChatMessage - before do test_commit = double("A test commit", committer: args[:user], title: "A test commit message") test_project = build(:project, name: args[:project][:name]) @@ -62,6 +60,8 @@ RSpec.describe Integrations::ChatMessage::PipelineMessage do allow(Gitlab::UrlBuilder).to receive(:build).with(args[:user]).and_return("http://example.gitlab.com/hacker") end + it_behaves_like Integrations::ChatMessage + it 'returns an empty pretext' do expect(subject.pretext).to be_empty end diff --git a/spec/models/integrations/drone_ci_spec.rb b/spec/models/integrations/drone_ci_spec.rb index 6ff6888e0d3..c46face9702 100644 --- a/spec/models/integrations/drone_ci_spec.rb +++ b/spec/models/integrations/drone_ci_spec.rb @@ -37,7 +37,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do end end - shared_context :drone_ci_integration do + shared_context 'drone ci integration' do subject(:drone) do described_class.new( project: project, @@ -116,7 +116,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do end it_behaves_like Integrations::HasWebHook do - include_context :drone_ci_integration + include_context 'drone ci integration' let(:integration) { drone } let(:hook_url) { "#{drone_url}/hook?owner=#{project.namespace.full_path}&name=#{project.path}&access_token={token}" } @@ -130,14 +130,14 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do end describe "integration page/path methods" do - include_context :drone_ci_integration + include_context 'drone ci integration' it { expect(drone.build_page(sha, branch)).to eq(build_page) } it { expect(drone.commit_status_path(sha, branch)).to eq(commit_status_path) } end describe '#commit_status' do - include_context :drone_ci_integration + include_context 'drone ci integration' it 'returns the contents of the reactive cache' do stub_reactive_cache(drone, { commit_status: 'foo' }, 'sha', 'ref') @@ -147,7 +147,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do end describe '#calculate_reactive_cache' do - include_context :drone_ci_integration + include_context 'drone ci integration' describe '#commit_status' do subject { drone.calculate_reactive_cache(sha, branch)[:commit_status] } @@ -193,7 +193,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do end describe "execute" do - include_context :drone_ci_integration + include_context 'drone ci integration' let(:user) { build(:user, username: 'username') } let(:push_sample_data) do diff --git a/spec/models/integrations/flowdock_spec.rb b/spec/models/integrations/flowdock_spec.rb deleted file mode 100644 index daafb1b3958..00000000000 --- a/spec/models/integrations/flowdock_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Integrations::Flowdock do - describe 'Validations' do - context 'when integration is active' do - before do - subject.active = true - end - - it { is_expected.to validate_presence_of(:token) } - end - - context 'when integration is inactive' do - before do - subject.active = false - end - - it { is_expected.not_to validate_presence_of(:token) } - end - end - - describe "Execute" do - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } - let(:sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) } - let(:api_url) { 'https://api.flowdock.com/v1/messages' } - - subject(:flowdock_integration) { described_class.new } - - before do - allow(flowdock_integration).to receive_messages( - project_id: project.id, - project: project, - token: 'verySecret' - ) - WebMock.stub_request(:post, api_url) - end - - it "calls FlowDock API" do - flowdock_integration.execute(sample_data) - - sample_data[:commits].each do |commit| - # One request to Flowdock per new commit - next if commit[:id] == sample_data[:before] - - expect(WebMock).to have_requested(:post, api_url).with( - body: /#{commit[:id]}.*#{project.path}/ - ).once - end - end - end -end diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb index af1112cf50d..a4ccae459cf 100644 --- a/spec/models/integrations/jira_spec.rb +++ b/spec/models/integrations/jira_spec.rb @@ -469,7 +469,8 @@ RSpec.describe Integrations::Jira do end describe '#client' do - subject do + it 'uses the default GitLab::HTTP timeouts' do + timeouts = Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS stub_request(:get, 'http://jira.example.com/foo') expect(Gitlab::HTTP).to receive(:httparty_perform_request) @@ -477,32 +478,6 @@ RSpec.describe Integrations::Jira do jira_integration.client.get('/foo') end - - context 'when the FF :jira_raise_timeouts is enabled' do - let(:timeouts) do - { - open_timeout: 2.minutes, - read_timeout: 2.minutes, - write_timeout: 2.minutes - } - end - - it 'uses custom timeouts' do - subject - end - end - - context 'when the FF :jira_raise_timeouts is disabled' do - before do - stub_feature_flags(jira_raise_timeouts: false) - end - - let(:timeouts) { Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS } - - it 'uses the default GitLab::HTTP timeouts' do - subject - end - end end describe '#find_issue' do @@ -612,7 +587,7 @@ RSpec.describe Integrations::Jira do close_issue end - it_behaves_like 'Snowplow event tracking' do + it_behaves_like 'Snowplow event tracking with RedisHLL context' do subject { close_issue } let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } @@ -968,7 +943,7 @@ RSpec.describe Integrations::Jira do subject end - it_behaves_like 'Snowplow event tracking' do + it_behaves_like 'Snowplow event tracking with RedisHLL context' do let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } let(:category) { 'Integrations::Jira' } let(:action) { 'perform_integrations_action' } diff --git a/spec/models/integrations/slack_spec.rb b/spec/models/integrations/slack_spec.rb index a12bc7f4831..218d92ffe05 100644 --- a/spec/models/integrations/slack_spec.rb +++ b/spec/models/integrations/slack_spec.rb @@ -4,5 +4,9 @@ require 'spec_helper' RSpec.describe Integrations::Slack do it_behaves_like Integrations::SlackMattermostNotifier, 'Slack' - it_behaves_like Integrations::BaseSlackNotification, factory: :integrations_slack + it_behaves_like Integrations::BaseSlackNotification, factory: :integrations_slack do + before do + stub_request(:post, integration.webhook) + end + end end |