diff options
Diffstat (limited to 'spec/models/integrations')
17 files changed, 223 insertions, 72 deletions
diff --git a/spec/models/integrations/apple_app_store_spec.rb b/spec/models/integrations/apple_app_store_spec.rb index 9864fe38d3f..ea66c382726 100644 --- a/spec/models/integrations/apple_app_store_spec.rb +++ b/spec/models/integrations/apple_app_store_spec.rb @@ -13,8 +13,7 @@ RSpec.describe Integrations::AppleAppStore, feature_category: :mobile_devops do it { is_expected.to validate_presence_of :app_store_key_id } it { is_expected.to validate_presence_of :app_store_private_key } it { is_expected.to validate_presence_of :app_store_private_key_file_name } - it { is_expected.to allow_value(true, false).for(:app_store_protected_refs) } - it { is_expected.not_to allow_value(nil).for(:app_store_protected_refs) } + it { is_expected.to validate_inclusion_of(:app_store_protected_refs).in_array([true, false]) } it { is_expected.to allow_value('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee').for(:app_store_issuer_id) } it { is_expected.not_to allow_value('abcde').for(:app_store_issuer_id) } it { is_expected.to allow_value(File.read('spec/fixtures/ssl_key.pem')).for(:app_store_private_key) } diff --git a/spec/models/integrations/asana_spec.rb b/spec/models/integrations/asana_spec.rb index 376aec1088e..70c56d35a04 100644 --- a/spec/models/integrations/asana_spec.rb +++ b/spec/models/integrations/asana_spec.rb @@ -22,7 +22,7 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do let_it_be(:project) { build(:project) } let(:gid) { "123456789ABCD" } - let(:asana_task) { double(::Asana::Resources::Task) } + let(:asana_task) { double(data: { gid: gid }) } let(:asana_integration) { described_class.new } let(:ref) { 'main' } let(:restrict_to_branch) { nil } @@ -41,6 +41,15 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do } end + let(:completed_message) do + { + body: { + completed: true + }, + headers: { "Authorization" => "Bearer verySecret" } + } + end + before do allow(asana_integration).to receive_messages( project: project, @@ -60,9 +69,10 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do let(:ref) { 'main' } it 'calls the Asana integration' do - expect(asana_task).to receive(:add_comment) - expect(asana_task).to receive(:update).with(completed: true) - expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '456789').once.and_return(asana_task) + expect(Gitlab::HTTP).to receive(:post) + .with("https://app.asana.com/api/1.0/tasks/456789/stories", anything).once.and_return(asana_task) + expect(Gitlab::HTTP).to receive(:put) + .with("https://app.asana.com/api/1.0/tasks/456789", completed_message).once.and_return(asana_task) execute_integration end @@ -72,8 +82,8 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do let(:ref) { 'mai' } it 'does not call the Asana integration' do - expect(asana_task).not_to receive(:add_comment) - expect(::Asana::Resources::Task).not_to receive(:find_by_id) + expect(Gitlab::HTTP).not_to receive(:post) + expect(Gitlab::HTTP).not_to receive(:put) execute_integration end @@ -83,12 +93,17 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do context 'when creating a story' do let(:message) { "Message from commit. related to ##{gid}" } let(:expected_message) do - "#{user.name} pushed to branch main of #{project.full_name} ( https://gitlab.com/ ): #{message}" + { + body: { + text: "#{user.name} pushed to branch main of #{project.full_name} ( https://gitlab.com/ ): #{message}" + }, + headers: { "Authorization" => "Bearer verySecret" } + } end it 'calls Asana integration to create a story' do - expect(asana_task).to receive(:add_comment).with(text: expected_message) - expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, gid).once.and_return(asana_task) + expect(Gitlab::HTTP).to receive(:post) + .with("https://app.asana.com/api/1.0/tasks/#{gid}/stories", expected_message).once.and_return(asana_task) execute_integration end @@ -98,9 +113,10 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do let(:message) { 'fix #456789' } it 'calls Asana integration to create a story and close a task' do - expect(asana_task).to receive(:add_comment) - expect(asana_task).to receive(:update).with(completed: true) - expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '456789').once.and_return(asana_task) + expect(Gitlab::HTTP).to receive(:post) + .with("https://app.asana.com/api/1.0/tasks/456789/stories", anything).once.and_return(asana_task) + expect(Gitlab::HTTP).to receive(:put) + .with("https://app.asana.com/api/1.0/tasks/456789", completed_message).once.and_return(asana_task) execute_integration end @@ -110,9 +126,10 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do let(:message) { 'closes https://app.asana.com/19292/956299/42' } it 'calls Asana integration to close via url' do - expect(asana_task).to receive(:add_comment) - expect(asana_task).to receive(:update).with(completed: true) - expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '42').once.and_return(asana_task) + expect(Gitlab::HTTP).to receive(:post) + .with("https://app.asana.com/api/1.0/tasks/42/stories", anything).once.and_return(asana_task) + expect(Gitlab::HTTP).to receive(:put) + .with("https://app.asana.com/api/1.0/tasks/42", completed_message).once.and_return(asana_task) execute_integration end @@ -127,27 +144,30 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do end it 'allows multiple matches per line' do - expect(asana_task).to receive(:add_comment) - expect(asana_task).to receive(:update).with(completed: true) - expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '123').once.and_return(asana_task) - - asana_task_2 = double(Asana::Resources::Task) - expect(asana_task_2).to receive(:add_comment) - expect(asana_task_2).to receive(:update).with(completed: true) - expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '456').once.and_return(asana_task_2) - - asana_task_3 = double(Asana::Resources::Task) - expect(asana_task_3).to receive(:add_comment) - expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '789').once.and_return(asana_task_3) - - asana_task_4 = double(Asana::Resources::Task) - expect(asana_task_4).to receive(:add_comment) - expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '42').once.and_return(asana_task_4) - - asana_task_5 = double(Asana::Resources::Task) - expect(asana_task_5).to receive(:add_comment) - expect(asana_task_5).to receive(:update).with(completed: true) - expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '12').once.and_return(asana_task_5) + expect(Gitlab::HTTP).to receive(:post) + .with("https://app.asana.com/api/1.0/tasks/123/stories", anything).once.and_return(asana_task) + expect(Gitlab::HTTP).to receive(:put) + .with("https://app.asana.com/api/1.0/tasks/123", completed_message).once.and_return(asana_task) + + asana_task_2 = double(double(data: { gid: 456 })) + expect(Gitlab::HTTP).to receive(:post) + .with("https://app.asana.com/api/1.0/tasks/456/stories", anything).once.and_return(asana_task_2) + expect(Gitlab::HTTP).to receive(:put) + .with("https://app.asana.com/api/1.0/tasks/456", completed_message).once.and_return(asana_task_2) + + asana_task_3 = double(double(data: { gid: 789 })) + expect(Gitlab::HTTP).to receive(:post) + .with("https://app.asana.com/api/1.0/tasks/789/stories", anything).once.and_return(asana_task_3) + + asana_task_4 = double(double(data: { gid: 42 })) + expect(Gitlab::HTTP).to receive(:post) + .with("https://app.asana.com/api/1.0/tasks/42/stories", anything).once.and_return(asana_task_4) + + asana_task_5 = double(double(data: { gid: 12 })) + expect(Gitlab::HTTP).to receive(:post) + .with("https://app.asana.com/api/1.0/tasks/12/stories", anything).once.and_return(asana_task_5) + expect(Gitlab::HTTP).to receive(:put) + .with("https://app.asana.com/api/1.0/tasks/12", completed_message).once.and_return(asana_task_5) execute_integration end diff --git a/spec/models/integrations/bamboo_spec.rb b/spec/models/integrations/bamboo_spec.rb index 3b459ab9d5b..62080fa7a12 100644 --- a/spec/models/integrations/bamboo_spec.rb +++ b/spec/models/integrations/bamboo_spec.rb @@ -116,7 +116,7 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching, feat is_expected.to eq('http://gitlab.com/bamboo/browse/42') end - context 'bamboo_url has trailing slash' do + context 'when bamboo_url has trailing slash' do let(:bamboo_url) { 'http://gitlab.com/bamboo/' } it 'returns a build URL' do @@ -198,13 +198,22 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching, feat context 'when Bamboo API returns an array of results and we only consider the last one' do let(:bamboo_response_template) do - %q({"results":{"results":{"size":"2","result":[{"buildState":"%{build_state}","planResultKey":{"key":"41"}},{"buildState":"%{build_state}","planResultKey":{"key":"42"}}]}}}) + '{"results":{"results":{"size":"2","result":[{"buildState":"%{build_state}","planResultKey":{"key":"41"}}, ' \ + '{"buildState":"%{build_state}","planResultKey":{"key":"42"}}]}}}' end it_behaves_like 'reactive cache calculation' end end + describe '#avatar_url' do + it 'returns the avatar image path' do + expect(subject.avatar_url).to eq(ActionController::Base.helpers.image_path( + 'illustrations/third-party-logos/integrations-logos/atlassian-bamboo.svg' + )) + end + end + def stub_update_and_build_request(status: 200, body: nil) bamboo_full_url = 'http://gitlab.com/bamboo/updateAndBuild.action?buildKey=foo&os_authType=basic' @@ -222,11 +231,11 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching, feat status: status, headers: { 'Content-Type' => 'application/json' }, body: body - ).with(basic_auth: %w(mic password)) + ).with(basic_auth: %w[mic password]) end def bamboo_response(build_state: 'success') # reference: https://docs.atlassian.com/atlassian-bamboo/REST/6.2.5/#d2e786 - bamboo_response_template % { build_state: build_state } + format(bamboo_response_template, build_state: build_state) end end diff --git a/spec/models/integrations/chat_message/alert_message_spec.rb b/spec/models/integrations/chat_message/alert_message_spec.rb index 162df1a774c..a9db9e14883 100644 --- a/spec/models/integrations/chat_message/alert_message_spec.rb +++ b/spec/models/integrations/chat_message/alert_message_spec.rb @@ -57,4 +57,10 @@ RSpec.describe Integrations::ChatMessage::AlertMessage do expect(time_item[:value]).to eq(expected_time) end end + + describe '#attachment_color' do + it 'returns the correct color' do + expect(subject.attachment_color).to eq('#C95823') + end + end end diff --git a/spec/models/integrations/chat_message/deployment_message_spec.rb b/spec/models/integrations/chat_message/deployment_message_spec.rb index 630ae902331..afbf1d1c0d1 100644 --- a/spec/models/integrations/chat_message/deployment_message_spec.rb +++ b/spec/models/integrations/chat_message/deployment_message_spec.rb @@ -19,6 +19,29 @@ RSpec.describe Integrations::ChatMessage::DeploymentMessage, feature_category: : it_behaves_like Integrations::ChatMessage + def deployment_data(params) + { + object_kind: "deployment", + status: "success", + deployable_id: 3, + deployable_url: "deployable_url", + environment: "sandbox", + project: { + name: "greatproject", + web_url: "project_web_url", + path_with_namespace: "project_path_with_namespace" + }, + user: { + name: "Jane Person", + username: "jane" + }, + user_url: "user_url", + short_sha: "12345678", + commit_url: "commit_url", + commit_title: "commit title text" + }.merge(params) + end + describe '#pretext' do it 'returns a message with the data returned by the deployment data builder' do expect(subject.pretext).to eq("Deploy to myenvironment succeeded") @@ -80,29 +103,6 @@ RSpec.describe Integrations::ChatMessage::DeploymentMessage, feature_category: : end describe '#attachments' do - def deployment_data(params) - { - object_kind: "deployment", - status: "success", - deployable_id: 3, - deployable_url: "deployable_url", - environment: "sandbox", - project: { - name: "greatproject", - web_url: "project_web_url", - path_with_namespace: "project_path_with_namespace" - }, - user: { - name: "Jane Person", - username: "jane" - }, - user_url: "user_url", - short_sha: "12345678", - commit_url: "commit_url", - commit_title: "commit title text" - }.merge(params) - end - context 'without markdown' do it 'returns attachments with the data returned by the deployment data builder' do job_url = Gitlab::Routing.url_helpers.project_job_url(project, ci_build) @@ -165,4 +165,23 @@ RSpec.describe Integrations::ChatMessage::DeploymentMessage, feature_category: : }]) end end + + describe '#attachment_color' do + using RSpec::Parameterized::TableSyntax + where(:status, :expected_color) do + 'success' | 'good' + 'canceled' | 'warning' + 'failed' | 'danger' + 'blub' | '#334455' + end + + with_them do + it 'returns the correct color' do + data = deployment_data(status: status) + message = described_class.new(data) + + expect(message.attachment_color).to eq(expected_color) + end + end + end end diff --git a/spec/models/integrations/chat_message/issue_message_spec.rb b/spec/models/integrations/chat_message/issue_message_spec.rb index 14451427a5a..7b09b5d08b0 100644 --- a/spec/models/integrations/chat_message/issue_message_spec.rb +++ b/spec/models/integrations/chat_message/issue_message_spec.rb @@ -125,4 +125,10 @@ RSpec.describe Integrations::ChatMessage::IssueMessage, feature_category: :integ end end end + + describe '#attachment_color' do + it 'returns the correct color' do + expect(subject.attachment_color).to eq('#C95823') + 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 4d371ca0899..5eb3915018e 100644 --- a/spec/models/integrations/chat_message/pipeline_message_spec.rb +++ b/spec/models/integrations/chat_message/pipeline_message_spec.rb @@ -388,4 +388,31 @@ RSpec.describe Integrations::ChatMessage::PipelineMessage do ) end end + + describe '#attachment_color' do + context 'when success' do + before do + args[:object_attributes][:status] = 'success' + end + + it { expect(subject.attachment_color).to eq('good') } + end + + context 'when passed with warnings' do + before do + args[:object_attributes][:status] = 'success' + args[:object_attributes][:detailed_status] = 'passed with warnings' + end + + it { expect(subject.attachment_color).to eq('warning') } + end + + context 'when failed' do + before do + args[:object_attributes][:status] = 'failed' + end + + it { expect(subject.attachment_color).to eq('danger') } + end + end end diff --git a/spec/models/integrations/chat_message/push_message_spec.rb b/spec/models/integrations/chat_message/push_message_spec.rb index 5c9c5c64d7e..a9d0f801406 100644 --- a/spec/models/integrations/chat_message/push_message_spec.rb +++ b/spec/models/integrations/chat_message/push_message_spec.rb @@ -214,4 +214,10 @@ RSpec.describe Integrations::ChatMessage::PushMessage do end end end + + describe '#attachment_color' do + it 'returns the correct color' do + expect(subject.attachment_color).to eq('#345') + end + end end diff --git a/spec/models/integrations/discord_spec.rb b/spec/models/integrations/discord_spec.rb index 7ab7308ac1c..89c4dcd7e0e 100644 --- a/spec/models/integrations/discord_spec.rb +++ b/spec/models/integrations/discord_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" RSpec.describe Integrations::Discord, feature_category: :integrations do - it_behaves_like "chat integration", "Discord notifications" do + it_behaves_like "chat integration", "Discord notifications", supports_deployments: true do let(:client) { Discordrb::Webhooks::Client } let(:client_arguments) { { url: webhook_url } } let(:payload) do @@ -18,6 +18,8 @@ RSpec.describe Integrations::Discord, feature_category: :integrations do ] } end + + it_behaves_like 'supports group mentions', :discord_integration end describe 'validations' do @@ -77,7 +79,7 @@ RSpec.describe Integrations::Discord, feature_category: :integrations do icon_url: start_with('https://www.gravatar.com/avatar/'), name: user.name ), - color: 16543014, + color: 3359829, timestamp: Time.now.utc.iso8601 ) end diff --git a/spec/models/integrations/google_play_spec.rb b/spec/models/integrations/google_play_spec.rb index a0bc73378d3..c5b0c058809 100644 --- a/spec/models/integrations/google_play_spec.rb +++ b/spec/models/integrations/google_play_spec.rb @@ -20,8 +20,7 @@ RSpec.describe Integrations::GooglePlay, feature_category: :mobile_devops do it { is_expected.to allow_value('a.a.a').for(:package_name) } it { is_expected.to allow_value('com.example').for(:package_name) } it { is_expected.not_to allow_value('com').for(:package_name) } - it { is_expected.to allow_value(true, false).for(:google_play_protected_refs) } - it { is_expected.not_to allow_value(nil).for(:google_play_protected_refs) } + it { is_expected.to validate_inclusion_of(:google_play_protected_refs).in_array([true, false]) } it { is_expected.not_to allow_value('com.example.my app').for(:package_name) } it { is_expected.not_to allow_value('1com.example.myapp').for(:package_name) } it { is_expected.not_to allow_value('com.1example.myapp').for(:package_name) } diff --git a/spec/models/integrations/hangouts_chat_spec.rb b/spec/models/integrations/hangouts_chat_spec.rb index bcb80768ffb..a1ecfd436c2 100644 --- a/spec/models/integrations/hangouts_chat_spec.rb +++ b/spec/models/integrations/hangouts_chat_spec.rb @@ -4,7 +4,7 @@ require "spec_helper" RSpec.describe Integrations::HangoutsChat, feature_category: :integrations do it_behaves_like "chat integration", "Hangouts Chat" do - let(:client) { HangoutsChat::Sender } + let(:client) { Gitlab::HTTP } let(:client_arguments) { webhook_url } let(:payload) do { diff --git a/spec/models/integrations/integration_list_spec.rb b/spec/models/integrations/integration_list_spec.rb new file mode 100644 index 00000000000..b7ccbcecf6b --- /dev/null +++ b/spec/models/integrations/integration_list_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Integrations::IntegrationList, feature_category: :integrations do + let_it_be(:projects) { create_pair(:project, :small_repo) } + let(:batch) { Project.where(id: projects.pluck(:id)) } + let(:integration_hash) { { 'active' => 'true', 'category' => 'common' } } + let(:association) { 'project' } + + subject { described_class.new(batch, integration_hash, association) } + + describe '#to_array' do + it 'returns array of Integration, columns, and values' do + expect(subject.to_array).to eq([ + Integration, + %w[active category project_id], + [['true', 'common', projects.first.id], ['true', 'common', projects.second.id]] + ]) + end + end +end diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb index 9bb77f6d6d4..c87128db221 100644 --- a/spec/models/integrations/jira_spec.rb +++ b/spec/models/integrations/jira_spec.rb @@ -597,7 +597,7 @@ RSpec.describe Integrations::Jira, feature_category: :integrations do it 'uses the default GitLab::HTTP timeouts' do timeouts = Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS - expect(Gitlab::HTTP).to receive(:httparty_perform_request) + expect(Gitlab::HTTP_V2::Client).to receive(:httparty_perform_request) .with(Net::HTTP::Get, '/foo', hash_including(timeouts)).and_call_original jira_integration.client.get('/foo') @@ -1372,4 +1372,12 @@ RSpec.describe Integrations::Jira, feature_category: :integrations do end end end + + describe '#avatar_url' do + it 'returns the avatar image path' do + expect(subject.avatar_url).to eq( + ActionController::Base.helpers.image_path('illustrations/third-party-logos/integrations-logos/jira.svg') + ) + end + end end diff --git a/spec/models/integrations/pivotaltracker_spec.rb b/spec/models/integrations/pivotaltracker_spec.rb index bf8458a376c..babe9119ccf 100644 --- a/spec/models/integrations/pivotaltracker_spec.rb +++ b/spec/models/integrations/pivotaltracker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::Pivotaltracker do +RSpec.describe Integrations::Pivotaltracker, feature_category: :integrations do include StubRequests describe 'Validations' do @@ -93,4 +93,14 @@ RSpec.describe Integrations::Pivotaltracker do end end end + + describe '#avatar_url' do + it 'returns the avatar image path' do + expect(subject.avatar_url).to eq( + ActionController::Base.helpers.image_path( + 'illustrations/third-party-logos/integrations-logos/pivotal-tracker.svg' + ) + ) + end + end end diff --git a/spec/models/integrations/pushover_spec.rb b/spec/models/integrations/pushover_spec.rb index 8286fd20669..c576340a78a 100644 --- a/spec/models/integrations/pushover_spec.rb +++ b/spec/models/integrations/pushover_spec.rb @@ -62,4 +62,12 @@ RSpec.describe Integrations::Pushover do expect(WebMock).to have_requested(:post, 'https://8.8.8.8/1/messages.json').once end end + + describe '#avatar_url' do + it 'returns the avatar image path' do + expect(subject.avatar_url).to eq( + ActionController::Base.helpers.image_path('illustrations/third-party-logos/integrations-logos/pushover.svg') + ) + end + end end diff --git a/spec/models/integrations/slack_spec.rb b/spec/models/integrations/slack_spec.rb index 59ee3746d8f..0d82abd9e3d 100644 --- a/spec/models/integrations/slack_spec.rb +++ b/spec/models/integrations/slack_spec.rb @@ -9,4 +9,6 @@ RSpec.describe Integrations::Slack, feature_category: :integrations do stub_request(:post, integration.webhook) end end + + it_behaves_like 'supports group mentions', :integrations_slack end diff --git a/spec/models/integrations/telegram_spec.rb b/spec/models/integrations/telegram_spec.rb index c3a66c84f09..4c814dedd66 100644 --- a/spec/models/integrations/telegram_spec.rb +++ b/spec/models/integrations/telegram_spec.rb @@ -50,4 +50,12 @@ RSpec.describe Integrations::Telegram, feature_category: :integrations do end end end + + describe '#avatar_url' do + it 'returns the avatar image path' do + expect(subject.avatar_url).to eq( + ActionController::Base.helpers.image_path('illustrations/third-party-logos/integrations-logos/telegram.svg') + ) + end + end end |