diff options
Diffstat (limited to 'spec/models/integrations')
-rw-r--r-- | spec/models/integrations/bamboo_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/integrations/base_chat_notification_spec.rb | 19 | ||||
-rw-r--r-- | spec/models/integrations/buildkite_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/integrations/drone_ci_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/integrations/jenkins_spec.rb | 15 | ||||
-rw-r--r-- | spec/models/integrations/jira_spec.rb | 192 | ||||
-rw-r--r-- | spec/models/integrations/microsoft_teams_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/integrations/prometheus_spec.rb | 28 | ||||
-rw-r--r-- | spec/models/integrations/teamcity_spec.rb | 4 |
9 files changed, 77 insertions, 189 deletions
diff --git a/spec/models/integrations/bamboo_spec.rb b/spec/models/integrations/bamboo_spec.rb index b5684d153f2..574b87d6c60 100644 --- a/spec/models/integrations/bamboo_spec.rb +++ b/spec/models/integrations/bamboo_spec.rb @@ -227,7 +227,7 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do expect(Gitlab::ErrorTracking) .to receive(:log_exception) - .with(instance_of(http_error), project_id: project.id) + .with(instance_of(http_error), { project_id: project.id }) is_expected.to eq(:error) end diff --git a/spec/models/integrations/base_chat_notification_spec.rb b/spec/models/integrations/base_chat_notification_spec.rb index ac4031a9b7d..672d8de1e14 100644 --- a/spec/models/integrations/base_chat_notification_spec.rb +++ b/spec/models/integrations/base_chat_notification_spec.rb @@ -3,15 +3,14 @@ require 'spec_helper' RSpec.describe Integrations::BaseChatNotification do - describe 'Associations' do + describe 'validations' do before do allow(subject).to receive(:activated?).and_return(true) + allow(subject).to receive(:default_channel_placeholder).and_return('placeholder') + allow(subject).to receive(:webhook_placeholder).and_return('placeholder') end it { is_expected.to validate_presence_of :webhook } - end - - describe 'validations' do it { is_expected.to validate_inclusion_of(:labels_to_be_notified_behavior).in_array(%w[match_any match_all]).allow_blank } end @@ -274,4 +273,16 @@ RSpec.describe Integrations::BaseChatNotification do it_behaves_like 'with channel specified', 'slack-integration, #slack-test, @UDLP91W0A', ['slack-integration', '#slack-test', '@UDLP91W0A'] end end + + describe '#default_channel_placeholder' do + it 'raises an error' do + expect { subject.default_channel_placeholder }.to raise_error(NotImplementedError) + end + end + + describe '#webhook_placeholder' do + it 'raises an error' do + expect { subject.webhook_placeholder }.to raise_error(NotImplementedError) + end + end end diff --git a/spec/models/integrations/buildkite_spec.rb b/spec/models/integrations/buildkite_spec.rb index 4207ae0d555..af2e587dc7b 100644 --- a/spec/models/integrations/buildkite_spec.rb +++ b/spec/models/integrations/buildkite_spec.rb @@ -129,7 +129,7 @@ RSpec.describe Integrations::Buildkite, :use_clean_rails_memory_store_caching do expect(Gitlab::ErrorTracking) .to receive(:log_exception) - .with(instance_of(http_error), project_id: project.id) + .with(instance_of(http_error), { project_id: project.id }) is_expected.to eq(:error) end diff --git a/spec/models/integrations/drone_ci_spec.rb b/spec/models/integrations/drone_ci_spec.rb index dd64dcfc52c..78d55c49e7b 100644 --- a/spec/models/integrations/drone_ci_spec.rb +++ b/spec/models/integrations/drone_ci_spec.rb @@ -163,7 +163,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do expect(Gitlab::ErrorTracking) .to receive(:log_exception) - .with(instance_of(http_error), project_id: project.id) + .with(instance_of(http_error), { project_id: project.id }) is_expected.to eq(:error) end diff --git a/spec/models/integrations/jenkins_spec.rb b/spec/models/integrations/jenkins_spec.rb index 3d6393f2793..200de1305e2 100644 --- a/spec/models/integrations/jenkins_spec.rb +++ b/spec/models/integrations/jenkins_spec.rb @@ -4,11 +4,12 @@ require 'spec_helper' RSpec.describe Integrations::Jenkins do let(:project) { create(:project) } + let(:jenkins_integration) { described_class.new(jenkins_params) } let(:jenkins_url) { 'http://jenkins.example.com/' } let(:jenkins_hook_url) { jenkins_url + 'project/my_project' } let(:jenkins_username) { 'u$er name%2520' } let(:jenkins_password) { 'pas$ word' } - + let(:jenkins_authorization) { 'Basic ' + ::Base64.strict_encode64(jenkins_username + ':' + jenkins_password) } let(:jenkins_params) do { active: true, @@ -22,17 +23,21 @@ RSpec.describe Integrations::Jenkins do } end - let(:jenkins_authorization) { "Basic " + ::Base64.strict_encode64(jenkins_username + ':' + jenkins_password) } - include_context Integrations::EnableSslVerification do - let(:integration) { described_class.new(jenkins_params) } + let(:integration) { jenkins_integration } end it_behaves_like Integrations::HasWebHook do - let(:integration) { described_class.new(jenkins_params) } + let(:integration) { jenkins_integration } let(:hook_url) { "http://#{ERB::Util.url_encode jenkins_username}:#{ERB::Util.url_encode jenkins_password}@jenkins.example.com/project/my_project" } end + it 'sets the default values', :aggregate_failures do + expect(jenkins_integration.push_events).to eq(true) + expect(jenkins_integration.merge_requests_events).to eq(false) + expect(jenkins_integration.tag_push_events).to eq(false) + end + describe 'username validation' do let(:jenkins_integration) do described_class.create!( diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb index d244b1d33d5..061c770a61a 100644 --- a/spec/models/integrations/jira_spec.rb +++ b/spec/models/integrations/jira_spec.rb @@ -27,6 +27,10 @@ RSpec.describe Integrations::Jira do WebMock.stub_request(:get, /serverInfo/).to_return(body: server_info_results.to_json ) end + it_behaves_like Integrations::ResetSecretFields do + let(:integration) { jira_integration } + end + describe '#options' do let(:options) do { @@ -122,6 +126,11 @@ RSpec.describe Integrations::Jira do it 'includes SECTION_TYPE_JIRA_ISSUES' do expect(sections).to include(described_class::SECTION_TYPE_JIRA_ISSUES) end + + it 'section SECTION_TYPE_JIRA_ISSUES has `plan` attribute' do + jira_issues_section = integration.sections.find { |s| s[:type] == described_class::SECTION_TYPE_JIRA_ISSUES } + expect(jira_issues_section[:plan]).to eq('premium') + end end context 'when project_level? is false' do @@ -301,7 +310,7 @@ RSpec.describe Integrations::Jira do let_it_be(:new_url) { 'http://jira-new.example.com' } before do - integration.update!(username: new_username, url: new_url) + integration.update!(username: new_username, url: new_url, password: password) end it 'stores updated data in jira_tracker_data table' do @@ -318,7 +327,7 @@ RSpec.describe Integrations::Jira do context 'when updating the url, api_url, username, or password' do context 'when updating the integration' do it 'updates deployment type' do - integration.update!(url: 'http://first.url') + integration.update!(url: 'http://first.url', password: password) integration.jira_tracker_data.update!(deployment_type: 'server') expect(integration.jira_tracker_data.deployment_server?).to be_truthy @@ -376,135 +385,6 @@ RSpec.describe Integrations::Jira do expect(WebMock).not_to have_requested(:get, /serverInfo/) end end - - context 'stored password invalidation' do - context 'when a password was previously set' do - context 'when only web url present' do - let(:data_params) do - { - url: url, api_url: nil, - username: username, password: password, - jira_issue_transition_id: transition_id - } - end - - it 'resets password if url changed' do - integration - integration.url = 'http://jira_edited.example.com' - - expect(integration).not_to be_valid - expect(integration.url).to eq('http://jira_edited.example.com') - expect(integration.password).to be_nil - end - - it 'does not reset password if url "changed" to the same url as before' do - integration.url = 'http://jira.example.com' - - expect(integration).to be_valid - expect(integration.url).to eq('http://jira.example.com') - expect(integration.password).not_to be_nil - end - - it 'resets password if url not changed but api url added' do - integration.api_url = 'http://jira_edited.example.com/rest/api/2' - - expect(integration).not_to be_valid - expect(integration.api_url).to eq('http://jira_edited.example.com/rest/api/2') - expect(integration.password).to be_nil - end - - it 'does not reset password if new url is set together with password, even if it\'s the same password' do - integration.url = 'http://jira_edited.example.com' - integration.password = password - - expect(integration).to be_valid - expect(integration.password).to eq(password) - expect(integration.url).to eq('http://jira_edited.example.com') - end - - it 'resets password if url changed, even if setter called multiple times' do - integration.url = 'http://jira1.example.com/rest/api/2' - integration.url = 'http://jira1.example.com/rest/api/2' - - expect(integration).not_to be_valid - expect(integration.password).to be_nil - end - - it 'does not reset password if username changed' do - integration.username = 'some_name' - - expect(integration).to be_valid - expect(integration.password).to eq(password) - end - - it 'does not reset password if password changed' do - integration.url = 'http://jira_edited.example.com' - integration.password = 'new_password' - - expect(integration).to be_valid - expect(integration.password).to eq('new_password') - end - - it 'does not reset password if the password is touched and same as before' do - integration.url = 'http://jira_edited.example.com' - integration.password = password - - expect(integration).to be_valid - expect(integration.password).to eq(password) - end - end - - context 'when both web and api url present' do - let(:data_params) do - { - url: url, api_url: 'http://jira.example.com/rest/api/2', - username: username, password: password, - jira_issue_transition_id: transition_id - } - end - - it 'resets password if api url changed' do - integration.api_url = 'http://jira_edited.example.com/rest/api/2' - - expect(integration).not_to be_valid - expect(integration.password).to be_nil - end - - it 'does not reset password if url changed' do - integration.url = 'http://jira_edited.example.com' - - expect(integration).to be_valid - expect(integration.password).to eq(password) - end - - it 'resets password if api url set to empty' do - integration.api_url = '' - - expect(integration).not_to be_valid - expect(integration.password).to be_nil - end - end - end - - context 'when no password was previously set' do - let(:data_params) do - { - url: url, username: username - } - end - - it 'saves password if new url is set together with password' do - integration.url = 'http://jira_edited.example.com/rest/api/2' - integration.password = 'password' - integration.save! - - expect(integration.reload).to have_attributes( - url: 'http://jira_edited.example.com/rest/api/2', - password: 'password' - ) - end - end - end end end @@ -539,8 +419,7 @@ RSpec.describe Integrations::Jira do end describe '#client' do - it 'uses the default GitLab::HTTP timeouts' do - timeouts = Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS + subject do stub_request(:get, 'http://jira.example.com/foo') expect(Gitlab::HTTP).to receive(:httparty_perform_request) @@ -548,6 +427,32 @@ 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 @@ -746,17 +651,14 @@ RSpec.describe Integrations::Jira do end it 'logs exception when transition id is not valid' do - allow(jira_integration).to receive(:log_error) + allow(jira_integration).to receive(:log_exception) WebMock.stub_request(:post, transitions_url).with(basic_auth: %w(jira-username jira-password)).and_raise("Bad Request") close_issue - expect(jira_integration).to have_received(:log_error).with( - "Issue transition failed", - error: hash_including( - exception_class: 'StandardError', - exception_message: "Bad Request" - ), + expect(jira_integration).to have_received(:log_exception).with( + kind_of(StandardError), + message: 'Issue transition failed', client_url: "http://jira.example.com" ) end @@ -1054,12 +956,10 @@ RSpec.describe Integrations::Jira do WebMock.stub_request(:get, test_url).with(basic_auth: [username, password]) .to_raise(JIRA::HTTPError.new(double(message: error_message))) - expect(jira_integration).to receive(:log_error).with( - 'Error sending message', - client_url: 'http://jira.example.com', - 'exception.class' => anything, - 'exception.message' => error_message, - 'exception.backtrace' => anything + expect(jira_integration).to receive(:log_exception).with( + kind_of(JIRA::HTTPError), + message: 'Error sending message', + client_url: 'http://jira.example.com' ) expect(jira_integration.test(nil)).to eq(success: false, result: error_message) diff --git a/spec/models/integrations/microsoft_teams_spec.rb b/spec/models/integrations/microsoft_teams_spec.rb index 06b285a855c..af6c142525c 100644 --- a/spec/models/integrations/microsoft_teams_spec.rb +++ b/spec/models/integrations/microsoft_teams_spec.rb @@ -123,7 +123,7 @@ RSpec.describe Integrations::MicrosoftTeams do { title: "Awesome wiki_page", content: "Some text describing some thing or another", - format: "md", + format: :markdown, message: "user created page: Awesome wiki_page" } end diff --git a/spec/models/integrations/prometheus_spec.rb b/spec/models/integrations/prometheus_spec.rb index 76e20f20a00..a7495cb9574 100644 --- a/spec/models/integrations/prometheus_spec.rb +++ b/spec/models/integrations/prometheus_spec.rb @@ -122,34 +122,6 @@ RSpec.describe Integrations::Prometheus, :use_clean_rails_memory_store_caching, end end - describe 'callbacks' do - context 'after_create' do - let(:project) { create(:project) } - let(:integration) { build(:prometheus_integration, project: project) } - - subject(:create_integration) { integration.save! } - - it 'creates default alerts' do - expect(Prometheus::CreateDefaultAlertsWorker) - .to receive(:perform_async) - .with(project.id) - - create_integration - end - - context 'no project exists' do - let(:integration) { build(:prometheus_integration, :instance) } - - it 'does not create default alerts' do - expect(Prometheus::CreateDefaultAlertsWorker) - .not_to receive(:perform_async) - - create_integration - end - end - end - end - describe '#test' do before do integration.manual_configuration = true diff --git a/spec/models/integrations/teamcity_spec.rb b/spec/models/integrations/teamcity_spec.rb index e1f4e577503..046476225a6 100644 --- a/spec/models/integrations/teamcity_spec.rb +++ b/spec/models/integrations/teamcity_spec.rb @@ -210,7 +210,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do expect(Gitlab::ErrorTracking) .to receive(:log_exception) - .with(instance_of(Errno::ECONNREFUSED), project_id: project.id) + .with(instance_of(Errno::ECONNREFUSED), { project_id: project.id }) is_expected.to eq(teamcity_url) end @@ -260,7 +260,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do expect(Gitlab::ErrorTracking) .to receive(:log_exception) - .with(instance_of(Errno::ECONNREFUSED), project_id: project.id) + .with(instance_of(Errno::ECONNREFUSED), { project_id: project.id }) is_expected.to eq(:error) end |