diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
commit | e4384360a16dd9a19d4d2d25d0ef1f2b862ed2a6 (patch) | |
tree | 2fcdfa7dcdb9db8f5208b2562f4b4e803d671243 /spec/models/integrations | |
parent | ffda4e7bcac36987f936b4ba515995a6698698f0 (diff) |
Add latest changes from gitlab-org/gitlab@16-2-stable-eev16.2.0-rc42
Diffstat (limited to 'spec/models/integrations')
19 files changed, 265 insertions, 68 deletions
diff --git a/spec/models/integrations/apple_app_store_spec.rb b/spec/models/integrations/apple_app_store_spec.rb index f3346acae0a..9864fe38d3f 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).for(:app_store_protected_refs) } - it { is_expected.to allow_value(false).for(:app_store_protected_refs) } + 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 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) } diff --git a/spec/models/integrations/asana_spec.rb b/spec/models/integrations/asana_spec.rb index 43e876a4f47..376aec1088e 100644 --- a/spec/models/integrations/asana_spec.rb +++ b/spec/models/integrations/asana_spec.rb @@ -2,20 +2,24 @@ require 'spec_helper' -RSpec.describe Integrations::Asana do +RSpec.describe Integrations::Asana, feature_category: :integrations do describe 'Validations' do - context 'active' do + context 'when active' do before do subject.active = true end it { is_expected.to validate_presence_of :api_key } end + + context 'when inactive' do + it { is_expected.not_to validate_presence_of :api_key } + end end - describe 'Execute' do - let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project) } + describe '#execute' do + let_it_be(:user) { build(:user) } + let_it_be(:project) { build(:project) } let(:gid) { "123456789ABCD" } let(:asana_task) { double(::Asana::Resources::Task) } diff --git a/spec/models/integrations/assembla_spec.rb b/spec/models/integrations/assembla_spec.rb index e9f4274952d..28cda0a1e75 100644 --- a/spec/models/integrations/assembla_spec.rb +++ b/spec/models/integrations/assembla_spec.rb @@ -2,34 +2,49 @@ require 'spec_helper' -RSpec.describe Integrations::Assembla do +RSpec.describe Integrations::Assembla, feature_category: :integrations do include StubRequests it_behaves_like Integrations::ResetSecretFields do let(:integration) { described_class.new } end - describe "Execute" do - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } + describe 'Validations' do + context 'when active' do + before do + subject.active = true + end + + it { is_expected.to validate_presence_of :token } + end + + context 'when inactive' do + it { is_expected.not_to validate_presence_of :token } + end + end + + describe "#execute" do + let_it_be(:user) { build(:user) } + let_it_be(:project) { create(:project, :repository) } + + let(:assembla_integration) { described_class.new } + let(:sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) } + let(:api_url) { 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret' } before do - @assembla_integration = described_class.new - allow(@assembla_integration).to receive_messages( + allow(assembla_integration).to receive_messages( project_id: project.id, project: project, token: 'verySecret', subdomain: 'project_name' ) - @sample_data = Gitlab::DataBuilder::Push.build_sample(project, user) - @api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret' - stub_full_request(@api_url, method: :post) + stub_full_request(api_url, method: :post) end it "calls Assembla API" do - @assembla_integration.execute(@sample_data) - expect(WebMock).to have_requested(:post, stubbed_hostname(@api_url)).with( - body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ + assembla_integration.execute(sample_data) + expect(WebMock).to have_requested(:post, stubbed_hostname(api_url)).with( + body: /#{sample_data[:before]}.*#{sample_data[:after]}.*#{project.path}/ ).once end end diff --git a/spec/models/integrations/bamboo_spec.rb b/spec/models/integrations/bamboo_spec.rb index 1d2c90dad51..3b459ab9d5b 100644 --- a/spec/models/integrations/bamboo_spec.rb +++ b/spec/models/integrations/bamboo_spec.rb @@ -2,26 +2,15 @@ require 'spec_helper' -RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do +RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching, feature_category: :integrations do include ReactiveCachingHelpers include StubRequests let(:bamboo_url) { 'http://gitlab.com/bamboo' } - let_it_be(:project) { create(:project) } - - subject(:integration) do - described_class.create!( - active: true, - project: project, - properties: { - bamboo_url: bamboo_url, - username: 'mic', - password: 'password', - build_key: 'foo' - } - ) - end + let_it_be(:project) { build(:project) } + + subject(:integration) { build(:bamboo_integration, project: project, bamboo_url: bamboo_url) } it_behaves_like Integrations::BaseCi diff --git a/spec/models/integrations/base_chat_notification_spec.rb b/spec/models/integrations/base_chat_notification_spec.rb index 13dd9e03ab1..675035095c5 100644 --- a/spec/models/integrations/base_chat_notification_spec.rb +++ b/spec/models/integrations/base_chat_notification_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Integrations::BaseChatNotification, feature_category: :integratio it { expect(subject.category).to eq(:chat) } end - describe 'validations' do + describe 'Validations' do before do subject.active = active @@ -112,9 +112,9 @@ RSpec.describe Integrations::BaseChatNotification, feature_category: :integratio end context 'when the data object has a label' do - let_it_be(:label) { create(:label, project: project, name: 'Bug') } - let_it_be(:label_2) { create(:label, project: project, name: 'Community contribution') } - let_it_be(:label_3) { create(:label, project: project, name: 'Backend') } + let_it_be(:label) { build(:label, project: project, name: 'Bug') } + let_it_be(:label_2) { build(:label, project: project, name: 'Community contribution') } + let_it_be(:label_3) { build(:label, project: project, name: 'Backend') } let_it_be(:issue) { create(:labeled_issue, project: project, labels: [label, label_2, label_3]) } let_it_be(:note) { create(:note, noteable: issue, project: project) } diff --git a/spec/models/integrations/base_issue_tracker_spec.rb b/spec/models/integrations/base_issue_tracker_spec.rb index e1a764cd7cb..1bb24876222 100644 --- a/spec/models/integrations/base_issue_tracker_spec.rb +++ b/spec/models/integrations/base_issue_tracker_spec.rb @@ -2,10 +2,10 @@ require 'spec_helper' -RSpec.describe Integrations::BaseIssueTracker do - let(:integration) { Integrations::Redmine.new(project: project, active: true, issue_tracker_data: build(:issue_tracker_data)) } +RSpec.describe Integrations::BaseIssueTracker, feature_category: :integrations do + let(:integration) { build(:redmine_integration, project: project, active: true, issue_tracker_data: build(:issue_tracker_data)) } - let_it_be_with_refind(:project) { create :project } + let_it_be_with_refind(:project) { create(:project) } describe 'default values' do it { expect(subject.category).to eq(:issue_tracker) } diff --git a/spec/models/integrations/base_slack_notification_spec.rb b/spec/models/integrations/base_slack_notification_spec.rb index 8f7f4e8858d..ab977ca8fcc 100644 --- a/spec/models/integrations/base_slack_notification_spec.rb +++ b/spec/models/integrations/base_slack_notification_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::BaseSlackNotification do +RSpec.describe Integrations::BaseSlackNotification, feature_category: :integrations do # This spec should only contain tests that cannot be tested through # `base_slack_notification_shared_examples.rb`. diff --git a/spec/models/integrations/base_third_party_wiki_spec.rb b/spec/models/integrations/base_third_party_wiki_spec.rb index dbead636cb9..763f7131b94 100644 --- a/spec/models/integrations/base_third_party_wiki_spec.rb +++ b/spec/models/integrations/base_third_party_wiki_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::BaseThirdPartyWiki do +RSpec.describe Integrations::BaseThirdPartyWiki, feature_category: :integrations do describe 'default values' do it { expect(subject.category).to eq(:third_party_wiki) } end @@ -11,7 +11,7 @@ RSpec.describe Integrations::BaseThirdPartyWiki do let_it_be_with_reload(:project) { create(:project) } describe 'only one third party wiki per project' do - subject(:integration) { create(:shimo_integration, project: project, active: true) } + subject(:integration) { build(:shimo_integration, project: project, active: true) } before_all do create(:confluence_integration, project: project, active: true) @@ -35,7 +35,7 @@ RSpec.describe Integrations::BaseThirdPartyWiki do end context 'when integration is not on the project level' do - subject(:integration) { create(:shimo_integration, :instance, active: true) } + subject(:integration) { build(:shimo_integration, :instance, active: true) } it 'executes the validation' do expect(integration.valid?(:manual_change)).to be_truthy diff --git a/spec/models/integrations/bugzilla_spec.rb b/spec/models/integrations/bugzilla_spec.rb index f05bc26d066..cef58589231 100644 --- a/spec/models/integrations/bugzilla_spec.rb +++ b/spec/models/integrations/bugzilla_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::Bugzilla do +RSpec.describe Integrations::Bugzilla, feature_category: :integrations do describe 'Validations' do context 'when integration is active' do before do diff --git a/spec/models/integrations/buildkite_spec.rb b/spec/models/integrations/buildkite_spec.rb index 29c649af6c6..f3231d50eae 100644 --- a/spec/models/integrations/buildkite_spec.rb +++ b/spec/models/integrations/buildkite_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::Buildkite, :use_clean_rails_memory_store_caching do +RSpec.describe Integrations::Buildkite, :use_clean_rails_memory_store_caching, feature_category: :integrations do include ReactiveCachingHelpers include StubRequests @@ -71,9 +71,7 @@ RSpec.describe Integrations::Buildkite, :use_clean_rails_memory_store_caching do describe '#hook_url' do it 'returns the webhook url' do - expect(integration.hook_url).to eq( - 'https://webhook.buildkite.com/deliver/{webhook_token}' - ) + expect(integration.hook_url).to eq('https://webhook.buildkite.com/deliver/{webhook_token}') end end @@ -103,9 +101,7 @@ RSpec.describe Integrations::Buildkite, :use_clean_rails_memory_store_caching do describe '#calculate_reactive_cache' do describe '#commit_status' do - let(:buildkite_full_url) do - 'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123' - end + let(:buildkite_full_url) { 'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123' } subject { integration.calculate_reactive_cache('123', 'unused')[:commit_status] } diff --git a/spec/models/integrations/chat_message/group_mention_message_spec.rb b/spec/models/integrations/chat_message/group_mention_message_spec.rb new file mode 100644 index 00000000000..6fa486f3dc3 --- /dev/null +++ b/spec/models/integrations/chat_message/group_mention_message_spec.rb @@ -0,0 +1,193 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Integrations::ChatMessage::GroupMentionMessage, feature_category: :integrations do + subject { described_class.new(args) } + + let(:color) { '#345' } + let(:args) do + { + object_kind: 'group_mention', + mentioned: { + object_kind: 'group', + name: 'test/group', + url: 'http://test/group' + }, + user: { + name: 'Test User', + username: 'test.user', + avatar_url: 'http://avatar' + }, + project_name: 'Test Project', + project_url: 'http://project' + } + end + + context 'for issue descriptions' do + let(:attachments) { [{ text: "Issue\ndescription\n123", color: color }] } + + before do + args[:object_attributes] = { + object_kind: 'issue', + iid: '42', + title: 'Test Issue', + description: "Issue\ndescription\n123", + url: 'http://issue' + } + end + + it 'returns the appropriate message' do + expect(subject.pretext).to eq( + 'Group <http://test/group|test/group> was mentioned ' \ + 'in <http://issue|issue #42> ' \ + 'of <http://project|Test Project>: ' \ + '*Test Issue*' + ) + expect(subject.attachments).to eq(attachments) + end + + context 'with markdown' do + before do + args[:markdown] = true + end + + it 'returns the appropriate message' do + expect(subject.pretext).to eq( + 'Group [test/group](http://test/group) was mentioned ' \ + 'in [issue #42](http://issue) ' \ + 'of [Test Project](http://project): ' \ + '*Test Issue*' + ) + expect(subject.attachments).to eq("Issue\ndescription\n123") + expect(subject.activity).to eq( + { + title: 'Group [test/group](http://test/group) was mentioned in [issue #42](http://issue)', + subtitle: 'of [Test Project](http://project)', + text: 'Test Issue', + image: 'http://avatar' + } + ) + end + end + end + + context 'for merge request descriptions' do + let(:attachments) { [{ text: "MR\ndescription\n123", color: color }] } + + before do + args[:object_attributes] = { + object_kind: 'merge_request', + iid: '42', + title: 'Test MR', + description: "MR\ndescription\n123", + url: 'http://merge_request' + } + end + + it 'returns the appropriate message' do + expect(subject.pretext).to eq( + 'Group <http://test/group|test/group> was mentioned ' \ + 'in <http://merge_request|merge request !42> ' \ + 'of <http://project|Test Project>: ' \ + '*Test MR*' + ) + expect(subject.attachments).to eq(attachments) + end + end + + context 'for notes' do + let(:attachments) { [{ text: 'Test Comment', color: color }] } + + before do + args[:object_attributes] = { + object_kind: 'note', + note: 'Test Comment', + url: 'http://note' + } + end + + context 'on commits' do + before do + args[:commit] = { + id: '5f163b2b95e6f53cbd428f5f0b103702a52b9a23', + title: 'Test Commit', + message: "Commit\nmessage\n123\n" + } + end + + it 'returns the appropriate message' do + expect(subject.pretext).to eq( + 'Group <http://test/group|test/group> was mentioned ' \ + 'in <http://note|commit 5f163b2b> ' \ + 'of <http://project|Test Project>: ' \ + '*Test Commit*' + ) + expect(subject.attachments).to eq(attachments) + end + end + + context 'on issues' do + before do + args[:issue] = { + iid: '42', + title: 'Test Issue' + } + end + + it 'returns the appropriate message' do + expect(subject.pretext).to eq( + 'Group <http://test/group|test/group> was mentioned ' \ + 'in <http://note|issue #42> ' \ + 'of <http://project|Test Project>: ' \ + '*Test Issue*' + ) + expect(subject.attachments).to eq(attachments) + end + end + + context 'on merge requests' do + before do + args[:merge_request] = { + iid: '42', + title: 'Test MR' + } + end + + it 'returns the appropriate message' do + expect(subject.pretext).to eq( + 'Group <http://test/group|test/group> was mentioned ' \ + 'in <http://note|merge request !42> ' \ + 'of <http://project|Test Project>: ' \ + '*Test MR*' + ) + expect(subject.attachments).to eq(attachments) + end + end + end + + context 'for unsupported object types' do + before do + args[:object_attributes] = { object_kind: 'unsupported' } + end + + it 'raises an error' do + expect { described_class.new(args) }.to raise_error(NotImplementedError) + end + end + + context 'for notes on unsupported object types' do + before do + args[:object_attributes] = { + object_kind: 'note', + note: 'Test Comment', + url: 'http://note' + } + # Not adding a supported object type's attributes + end + + it 'raises an error' do + expect { described_class.new(args) }.to raise_error(NotImplementedError) + end + end +end diff --git a/spec/models/integrations/confluence_spec.rb b/spec/models/integrations/confluence_spec.rb index 999a532527d..d267e4a71c2 100644 --- a/spec/models/integrations/confluence_spec.rb +++ b/spec/models/integrations/confluence_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::Confluence do +RSpec.describe Integrations::Confluence, feature_category: :integrations do let_it_be(:project) { create(:project) } describe 'Validations' do @@ -49,10 +49,11 @@ RSpec.describe Integrations::Confluence do end context 'when the project wiki is not enabled' do - it 'returns nil when both active or inactive', :aggregate_failures do - project = create(:project, :wiki_disabled) - subject.project = project + before do + allow(project).to receive(:wiki_enabled?).and_return(false) + end + it 'returns nil when both active or inactive', :aggregate_failures do [true, false].each do |active| subject.active = active diff --git a/spec/models/integrations/custom_issue_tracker_spec.rb b/spec/models/integrations/custom_issue_tracker_spec.rb index 11f98b99bbe..4be95a25a43 100644 --- a/spec/models/integrations/custom_issue_tracker_spec.rb +++ b/spec/models/integrations/custom_issue_tracker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::CustomIssueTracker do +RSpec.describe Integrations::CustomIssueTracker, feature_category: :integrations do describe 'Validations' do context 'when integration is active' do before do diff --git a/spec/models/integrations/drone_ci_spec.rb b/spec/models/integrations/drone_ci_spec.rb index c46face9702..2cb86fb680a 100644 --- a/spec/models/integrations/drone_ci_spec.rb +++ b/spec/models/integrations/drone_ci_spec.rb @@ -184,7 +184,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do "success" => "success" }.each do |drone_status, our_status| it "sets commit status to #{our_status.inspect} when returned status is #{drone_status.inspect}" do - stub_request(body: %Q({"status":"#{drone_status}"})) + stub_request(body: %({"status":"#{drone_status}"})) is_expected.to eq(our_status) end diff --git a/spec/models/integrations/microsoft_teams_spec.rb b/spec/models/integrations/microsoft_teams_spec.rb index f1d9071d232..4f5b4daad42 100644 --- a/spec/models/integrations/microsoft_teams_spec.rb +++ b/spec/models/integrations/microsoft_teams_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::MicrosoftTeams do +RSpec.describe Integrations::MicrosoftTeams, feature_category: :integrations do it_behaves_like "chat integration", "Microsoft Teams" do let(:client) { ::MicrosoftTeams::Notifier } let(:client_arguments) { webhook_url } diff --git a/spec/models/integrations/prometheus_spec.rb b/spec/models/integrations/prometheus_spec.rb index 8aa9b12c4f0..da43d851b31 100644 --- a/spec/models/integrations/prometheus_spec.rb +++ b/spec/models/integrations/prometheus_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require 'googleauth' -RSpec.describe Integrations::Prometheus, :use_clean_rails_memory_store_caching, :snowplow do +RSpec.describe Integrations::Prometheus, :use_clean_rails_memory_store_caching, :snowplow, feature_category: :metrics do include PrometheusHelpers include ReactiveCachingHelpers @@ -37,8 +37,8 @@ RSpec.describe Integrations::Prometheus, :use_clean_rails_memory_store_caching, integration.manual_configuration = true end - it 'validates presence of api_url' do - expect(integration).to validate_presence_of(:api_url) + it 'does not validates presence of api_url' do + expect(integration).not_to validate_presence_of(:api_url) end end @@ -119,7 +119,7 @@ RSpec.describe Integrations::Prometheus, :use_clean_rails_memory_store_caching, context 'when configuration is not valid' do before do - integration.api_url = nil + integration.manual_configuration = nil end it 'returns failure message' do diff --git a/spec/models/integrations/teamcity_spec.rb b/spec/models/integrations/teamcity_spec.rb index e32088a2f79..c4c7202fae0 100644 --- a/spec/models/integrations/teamcity_spec.rb +++ b/spec/models/integrations/teamcity_spec.rb @@ -307,7 +307,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do def stub_post_to_build_queue(branch:) teamcity_full_url = "#{teamcity_url}/httpAuth/app/rest/buildQueue" - body ||= %Q(<build branchName=\"#{branch}\"><buildType id=\"foo\"/></build>) + body ||= %(<build branchName=\"#{branch}\"><buildType id=\"foo\"/></build>) auth = %w(mic password) stub_full_request(teamcity_full_url, method: :post).with( @@ -322,7 +322,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do def stub_request(status: 200, body: nil, build_status: 'success') auth = %w(mic password) - body ||= %Q({"build":{"status":"#{build_status}","id":"666"}}) + body ||= %({"build":{"status":"#{build_status}","id":"666"}}) stub_full_request(teamcity_full_url).with(basic_auth: auth).to_return( status: status, diff --git a/spec/models/integrations/unify_circuit_spec.rb b/spec/models/integrations/unify_circuit_spec.rb index 7a91b2d3c11..017443c799f 100644 --- a/spec/models/integrations/unify_circuit_spec.rb +++ b/spec/models/integrations/unify_circuit_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Integrations::UnifyCircuit do +RSpec.describe Integrations::UnifyCircuit, feature_category: :integrations do it_behaves_like "chat integration", "Unify Circuit" do let(:client_arguments) { webhook_url } let(:payload) do diff --git a/spec/models/integrations/webex_teams_spec.rb b/spec/models/integrations/webex_teams_spec.rb index b5cba6762aa..50a1383292b 100644 --- a/spec/models/integrations/webex_teams_spec.rb +++ b/spec/models/integrations/webex_teams_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Integrations::WebexTeams do +RSpec.describe Integrations::WebexTeams, feature_category: :integrations do it_behaves_like "chat integration", "Webex Teams" do let(:client_arguments) { webhook_url } let(:payload) do |