diff options
Diffstat (limited to 'spec/models/integrations')
-rw-r--r-- | spec/models/integrations/campfire_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/integrations/field_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/integrations/harbor_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/integrations/irker_spec.rb | 36 | ||||
-rw-r--r-- | spec/models/integrations/issue_tracker_data_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/integrations/jira_spec.rb | 55 | ||||
-rw-r--r-- | spec/models/integrations/jira_tracker_data_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/integrations/prometheus_spec.rb | 11 | ||||
-rw-r--r-- | spec/models/integrations/zentao_tracker_data_spec.rb | 6 |
9 files changed, 133 insertions, 26 deletions
diff --git a/spec/models/integrations/campfire_spec.rb b/spec/models/integrations/campfire_spec.rb index 0044e6fae21..405a9ff4b3f 100644 --- a/spec/models/integrations/campfire_spec.rb +++ b/spec/models/integrations/campfire_spec.rb @@ -44,7 +44,7 @@ RSpec.describe Integrations::Campfire do it "calls Campfire API to get a list of rooms and speak in a room" do # make sure a valid list of rooms is returned - body = File.read(Rails.root + 'spec/fixtures/project_services/campfire/rooms.json') + body = File.read(Rails.root + 'spec/fixtures/integrations/campfire/rooms.json') stub_full_request(@rooms_url).with(basic_auth: @auth).to_return( body: body, @@ -65,7 +65,7 @@ RSpec.describe Integrations::Campfire do it "calls Campfire API to get a list of rooms but shouldn't speak in a room" do # return a list of rooms that do not contain a room named 'test-room' - body = File.read(Rails.root + 'spec/fixtures/project_services/campfire/rooms2.json') + body = File.read(Rails.root + 'spec/fixtures/integrations/campfire/rooms2.json') stub_full_request(@rooms_url).with(basic_auth: @auth).to_return( body: body, status: 200, diff --git a/spec/models/integrations/field_spec.rb b/spec/models/integrations/field_spec.rb index c8caf831191..6b1ce7fcbde 100644 --- a/spec/models/integrations/field_spec.rb +++ b/spec/models/integrations/field_spec.rb @@ -5,7 +5,14 @@ require 'spec_helper' RSpec.describe ::Integrations::Field do subject(:field) { described_class.new(**attrs) } - let(:attrs) { { name: nil } } + let(:attrs) { { name: nil, integration_class: test_integration } } + let(:test_integration) do + Class.new(Integration) do + def self.default_placeholder + 'my placeholder' + end + end + end describe '#name' do before do @@ -68,11 +75,8 @@ RSpec.describe ::Integrations::Field do end context 'when set to a dynamic value' do - before do - attrs[name] = -> { Time.current } - end - it 'is computed' do + attrs[name] = -> { Time.current } start = Time.current travel_to(start + 1.minute) do @@ -80,6 +84,13 @@ RSpec.describe ::Integrations::Field do expect(field.send(name)).to be_after(start) end end + + it 'is executed in the class scope' do + attrs[name] = -> { default_placeholder } + + expect(field[name]).to eq('my placeholder') + expect(field.send(name)).to eq('my placeholder') + end end end end diff --git a/spec/models/integrations/harbor_spec.rb b/spec/models/integrations/harbor_spec.rb index 4a6eb27d63a..9e3d4b524a6 100644 --- a/spec/models/integrations/harbor_spec.rb +++ b/spec/models/integrations/harbor_spec.rb @@ -67,6 +67,16 @@ RSpec.describe Integrations::Harbor do harbor_integration.update!(active: false) expect(harbor_integration.ci_variables).to match_array([]) end + + context 'with robot username' do + it 'returns username variable with $$' do + harbor_integration.username = 'robot$project+user' + + expect(harbor_integration.ci_variables).to include( + { key: 'HARBOR_USERNAME', value: 'robot$$project+user' } + ) + end + end end describe 'before_validation :reset_username_and_password' do diff --git a/spec/models/integrations/irker_spec.rb b/spec/models/integrations/irker_spec.rb index 8aea2c26dc5..16487aa36e7 100644 --- a/spec/models/integrations/irker_spec.rb +++ b/spec/models/integrations/irker_spec.rb @@ -25,9 +25,11 @@ RSpec.describe Integrations::Irker do end describe 'Execute' do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } + let(:irker) { described_class.new } - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } + let(:irker_server) { TCPServer.new('localhost', 0) } let(:sample_data) do Gitlab::DataBuilder::Push.build_sample(project, user) end @@ -36,15 +38,13 @@ RSpec.describe Integrations::Irker do let(:colorize_messages) { '1' } before do - @irker_server = TCPServer.new 'localhost', 0 - allow(Gitlab::CurrentSettings).to receive(:allow_local_requests_from_web_hooks_and_services?).and_return(true) allow(irker).to receive_messages( active: true, project: project, project_id: project.id, - server_host: @irker_server.addr[2], - server_port: @irker_server.addr[1], + server_host: irker_server.addr[2], + server_port: irker_server.addr[1], default_irc_uri: 'irc://chat.freenode.net/', recipients: recipients, colorize_messages: colorize_messages) @@ -53,18 +53,22 @@ RSpec.describe Integrations::Irker do end after do - @irker_server.close + irker_server.close end it 'sends valid JSON messages to an Irker listener', :sidekiq_might_not_need_inline do + expect(Integrations::IrkerWorker).to receive(:perform_async) + .with(project.id, irker.channels, colorize_messages, sample_data, irker.settings) + .and_call_original + irker.execute(sample_data) - conn = @irker_server.accept + conn = irker_server.accept Timeout.timeout(5) do conn.each_line do |line| msg = Gitlab::Json.parse(line.chomp("\n")) - expect(msg.keys).to match_array(%w(to privmsg)) + expect(msg.keys).to match_array(%w[to privmsg]) expect(msg['to']).to match_array(["irc://chat.freenode.net/#commits", "irc://test.net/#test"]) end @@ -72,5 +76,19 @@ RSpec.describe Integrations::Irker do ensure conn.close if conn end + + context 'when the FF :rename_integrations_workers is disabled' do + before do + stub_feature_flags(rename_integrations_workers: false) + end + + it 'queues a IrkerWorker' do + expect(::IrkerWorker).to receive(:perform_async) + .with(project.id, irker.channels, colorize_messages, sample_data, irker.settings) + expect(Integrations::IrkerWorker).not_to receive(:perform_async) + + irker.execute(sample_data) + end + end end end diff --git a/spec/models/integrations/issue_tracker_data_spec.rb b/spec/models/integrations/issue_tracker_data_spec.rb index 597df237c67..233ed7b8475 100644 --- a/spec/models/integrations/issue_tracker_data_spec.rb +++ b/spec/models/integrations/issue_tracker_data_spec.rb @@ -3,7 +3,11 @@ require 'spec_helper' RSpec.describe Integrations::IssueTrackerData do - describe 'associations' do - it { is_expected.to belong_to :integration } + it_behaves_like Integrations::BaseDataFields + + describe 'encrypted attributes' do + subject { described_class.encrypted_attributes.keys } + + it { is_expected.to contain_exactly(:issues_url, :new_issue_url, :project_url) } end end diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb index 061c770a61a..28d97b74adb 100644 --- a/spec/models/integrations/jira_spec.rb +++ b/spec/models/integrations/jira_spec.rb @@ -31,6 +31,61 @@ RSpec.describe Integrations::Jira do let(:integration) { jira_integration } end + describe 'validations' do + subject { jira_integration } + + context 'when integration is active' do + before do + jira_integration.active = true + + # Don't auto-fill URLs from gitlab.yml + stub_config(issues_tracker: {}) + end + + it { is_expected.to be_valid } + it { is_expected.to validate_presence_of(:url) } + it { is_expected.to validate_presence_of(:username) } + it { is_expected.to validate_presence_of(:password) } + + it_behaves_like 'issue tracker integration URL attribute', :url + it_behaves_like 'issue tracker integration URL attribute', :api_url + end + + context 'when integration is inactive' do + before do + jira_integration.active = false + end + + it { is_expected.to be_valid } + it { is_expected.not_to validate_presence_of(:url) } + it { is_expected.not_to validate_presence_of(:username) } + it { is_expected.not_to validate_presence_of(:password) } + end + + describe 'jira_issue_transition_id' do + it 'accepts a blank value' do + jira_integration.jira_issue_transition_id = ' ' + + expect(jira_integration).to be_valid + end + + it 'accepts any string containing numbers' do + jira_integration.jira_issue_transition_id = 'foo 23 bar' + + expect(jira_integration).to be_valid + end + + it 'does not accept a string without numbers' do + jira_integration.jira_issue_transition_id = 'foo bar' + + expect(jira_integration).not_to be_valid + expect(jira_integration.errors.full_messages).to eq([ + 'Jira issue transition IDs must be a list of numbers that can be split with , or ;' + ]) + end + end + end + describe '#options' do let(:options) do { diff --git a/spec/models/integrations/jira_tracker_data_spec.rb b/spec/models/integrations/jira_tracker_data_spec.rb index 5430dd2eb52..d9f91527fbb 100644 --- a/spec/models/integrations/jira_tracker_data_spec.rb +++ b/spec/models/integrations/jira_tracker_data_spec.rb @@ -3,12 +3,12 @@ require 'spec_helper' RSpec.describe Integrations::JiraTrackerData do - describe 'associations' do - it { is_expected.to belong_to(:integration) } - end + it_behaves_like Integrations::BaseDataFields describe 'deployment_type' do - it { is_expected.to define_enum_for(:deployment_type).with_values([:unknown, :server, :cloud]).with_prefix(:deployment) } + specify do + is_expected.to define_enum_for(:deployment_type).with_values([:unknown, :server, :cloud]).with_prefix(:deployment) + end end describe 'encrypted attributes' do diff --git a/spec/models/integrations/prometheus_spec.rb b/spec/models/integrations/prometheus_spec.rb index a7495cb9574..fbeaebfd807 100644 --- a/spec/models/integrations/prometheus_spec.rb +++ b/spec/models/integrations/prometheus_spec.rb @@ -145,6 +145,17 @@ RSpec.describe Integrations::Prometheus, :use_clean_rails_memory_store_caching, expect(req_stub).to have_been_requested end end + + context 'when configuration is not valid' do + before do + integration.api_url = nil + end + + it 'returns failure message' do + expect(integration.test[:success]).to be_falsy + expect(integration.test[:result]).to eq('Prometheus configuration error') + end + end end describe '#prometheus_client' do diff --git a/spec/models/integrations/zentao_tracker_data_spec.rb b/spec/models/integrations/zentao_tracker_data_spec.rb index b078c57830b..dca5c4d79ae 100644 --- a/spec/models/integrations/zentao_tracker_data_spec.rb +++ b/spec/models/integrations/zentao_tracker_data_spec.rb @@ -3,16 +3,14 @@ require 'spec_helper' RSpec.describe Integrations::ZentaoTrackerData do + it_behaves_like Integrations::BaseDataFields + describe 'factory available' do let(:zentao_tracker_data) { create(:zentao_tracker_data) } it { expect(zentao_tracker_data.valid?).to eq true } end - describe 'associations' do - it { is_expected.to belong_to(:integration) } - end - describe 'encrypted attributes' do subject { described_class.encrypted_attributes.keys } |