Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/integrations')
-rw-r--r--spec/models/integrations/base_chat_notification_spec.rb21
-rw-r--r--spec/models/integrations/chat_message/deployment_message_spec.rb36
-rw-r--r--spec/models/integrations/confluence_spec.rb6
-rw-r--r--spec/models/integrations/mattermost_spec.rb2
-rw-r--r--spec/models/integrations/prometheus_spec.rb28
-rw-r--r--spec/models/integrations/shimo_spec.rb8
-rw-r--r--spec/models/integrations/slack_spec.rb2
-rw-r--r--spec/models/integrations/zentao_spec.rb8
8 files changed, 97 insertions, 14 deletions
diff --git a/spec/models/integrations/base_chat_notification_spec.rb b/spec/models/integrations/base_chat_notification_spec.rb
index 675035095c5..497f2f1e7c9 100644
--- a/spec/models/integrations/base_chat_notification_spec.rb
+++ b/spec/models/integrations/base_chat_notification_spec.rb
@@ -85,7 +85,7 @@ RSpec.describe Integrations::BaseChatNotification, feature_category: :integratio
context 'when webhook is not required' do
it 'returns true' do
- allow(chat_integration).to receive(:requires_webhook?).and_return(false)
+ allow(chat_integration.class).to receive(:requires_webhook?).and_return(false)
expect(chat_integration).to receive(:notify).and_return(true)
expect(chat_integration.execute(data)).to be true
@@ -347,6 +347,12 @@ RSpec.describe Integrations::BaseChatNotification, feature_category: :integratio
end
end
+ describe '#help' do
+ it 'raises an error' do
+ expect { subject.help }.to raise_error(NotImplementedError)
+ end
+ end
+
describe '#event_channel_name' do
it 'returns the channel field name for the given event' do
expect(subject.event_channel_name(:event)).to eq('event_channel')
@@ -364,4 +370,17 @@ RSpec.describe Integrations::BaseChatNotification, feature_category: :integratio
expect { subject.event_channel_value(:foo) }.to raise_error(NoMethodError)
end
end
+
+ describe '#api_field_names' do
+ context 'when channels are masked' do
+ let(:project) { build(:project) }
+ let(:integration) { build(:discord_integration, project: project, webhook: 'https://discord.com/api/') }
+
+ it 'does not include channel properties', :aggregate_failures do
+ integration.event_channel_names.each do |field|
+ expect(integration.api_field_names).not_to include(field)
+ end
+ end
+ 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 d16c191bd08..630ae902331 100644
--- a/spec/models/integrations/chat_message/deployment_message_spec.rb
+++ b/spec/models/integrations/chat_message/deployment_message_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Integrations::ChatMessage::DeploymentMessage do
+RSpec.describe Integrations::ChatMessage::DeploymentMessage, feature_category: :integrations do
subject { described_class.new(args) }
let_it_be(:user) { create(:user, name: 'John Smith', username: 'smith') }
@@ -103,15 +103,33 @@ RSpec.describe Integrations::ChatMessage::DeploymentMessage do
}.merge(params)
end
- 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)
- commit_url = Gitlab::UrlBuilder.build(deployment.commit)
- user_url = Gitlab::Routing.url_helpers.user_url(user)
+ 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)
+ commit_url = Gitlab::UrlBuilder.build(deployment.commit)
+ user_url = Gitlab::Routing.url_helpers.user_url(user)
+
+ expect(subject.attachments).to eq([{
+ text: "<#{project.web_url}|myspace/myproject> with job <#{job_url}|##{ci_build.id}> by <#{user_url}|John Smith (smith)>\n<#{commit_url}|#{deployment.short_sha}>: #{commit.title}",
+ color: "good"
+ }])
+ end
+ end
- expect(subject.attachments).to eq([{
- text: "[myspace/myproject](#{project.web_url}) with job [##{ci_build.id}](#{job_url}) by [John Smith (smith)](#{user_url})\n[#{deployment.short_sha}](#{commit_url}): #{commit.title}",
- color: "good"
- }])
+ context 'with markdown' do
+ before do
+ args.merge!(markdown: true)
+ end
+
+ 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)
+ commit_url = Gitlab::UrlBuilder.build(deployment.commit)
+ user_url = Gitlab::Routing.url_helpers.user_url(user)
+
+ expect(subject.attachments).to eq(
+ "[myspace/myproject](#{project.web_url}) with job [##{ci_build.id}](#{job_url}) by [John Smith (smith)](#{user_url})\n[#{deployment.short_sha}](#{commit_url}): #{commit.title}"
+ )
+ end
end
it 'returns attachments for a failed deployment' do
diff --git a/spec/models/integrations/confluence_spec.rb b/spec/models/integrations/confluence_spec.rb
index d267e4a71c2..a34b55c3c6b 100644
--- a/spec/models/integrations/confluence_spec.rb
+++ b/spec/models/integrations/confluence_spec.rb
@@ -63,6 +63,12 @@ RSpec.describe Integrations::Confluence, feature_category: :integrations do
end
end
+ describe '#avatar_url' do
+ it 'returns the avatar image path' do
+ expect(subject.avatar_url).to eq(ActionController::Base.helpers.image_path('confluence.svg'))
+ end
+ end
+
describe 'Caching has_confluence on project_settings' do
subject { project.project_setting.has_confluence? }
diff --git a/spec/models/integrations/mattermost_spec.rb b/spec/models/integrations/mattermost_spec.rb
index f7702846b6c..224bc4acdda 100644
--- a/spec/models/integrations/mattermost_spec.rb
+++ b/spec/models/integrations/mattermost_spec.rb
@@ -2,6 +2,6 @@
require 'spec_helper'
-RSpec.describe Integrations::Mattermost do
+RSpec.describe Integrations::Mattermost, feature_category: :integrations do
it_behaves_like Integrations::SlackMattermostNotifier, "Mattermost"
end
diff --git a/spec/models/integrations/prometheus_spec.rb b/spec/models/integrations/prometheus_spec.rb
index da43d851b31..4a998efe665 100644
--- a/spec/models/integrations/prometheus_spec.rb
+++ b/spec/models/integrations/prometheus_spec.rb
@@ -422,6 +422,34 @@ RSpec.describe Integrations::Prometheus, :use_clean_rails_memory_store_caching,
end
end
+ describe '#sync_http_integration after_save callback' do
+ context 'with corresponding HTTP integration' do
+ let_it_be_with_reload(:http_integration) { create(:alert_management_prometheus_integration, :legacy, project: project) }
+
+ it 'syncs the attribute' do
+ expect { integration.update!(manual_configuration: false) }
+ .to change { http_integration.reload.active }
+ .from(true).to(false)
+ end
+
+ context 'when changing a different attribute' do
+ it 'does not sync the attribute or execute extra queries' do
+ expect { integration.update!(api_url: 'https://any.url') }
+ .to issue_fewer_queries_than { integration.update!(manual_configuration: false) }
+ end
+ end
+ end
+
+ context 'without corresponding HTTP integration' do
+ let_it_be(:other_http_integration) { create(:alert_management_prometheus_integration, project: project) }
+
+ it 'does not sync the attribute or execute extra queries' do
+ expect { integration.update!(manual_configuration: false) }
+ .not_to change { other_http_integration.reload.active }
+ end
+ end
+ end
+
describe '#editable?' do
it 'is editable' do
expect(integration.editable?).to be(true)
diff --git a/spec/models/integrations/shimo_spec.rb b/spec/models/integrations/shimo_spec.rb
index be626012ab2..95289343d0d 100644
--- a/spec/models/integrations/shimo_spec.rb
+++ b/spec/models/integrations/shimo_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe ::Integrations::Shimo do
+RSpec.describe ::Integrations::Shimo, feature_category: :integrations do
describe '#fields' do
let(:shimo_integration) { build(:shimo_integration) }
@@ -60,4 +60,10 @@ RSpec.describe ::Integrations::Shimo do
expect { create(:shimo_integration) }.to change(ProjectSetting, :count).by(1)
end
end
+
+ describe '#avatar_url' do
+ it 'returns the avatar image path' do
+ expect(subject.avatar_url).to eq(ActionController::Base.helpers.image_path('logos/shimo.svg'))
+ end
+ end
end
diff --git a/spec/models/integrations/slack_spec.rb b/spec/models/integrations/slack_spec.rb
index 218d92ffe05..59ee3746d8f 100644
--- a/spec/models/integrations/slack_spec.rb
+++ b/spec/models/integrations/slack_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Integrations::Slack do
+RSpec.describe Integrations::Slack, feature_category: :integrations do
it_behaves_like Integrations::SlackMattermostNotifier, 'Slack'
it_behaves_like Integrations::BaseSlackNotification, factory: :integrations_slack do
before do
diff --git a/spec/models/integrations/zentao_spec.rb b/spec/models/integrations/zentao_spec.rb
index 2fa4df0e900..460ce7629cc 100644
--- a/spec/models/integrations/zentao_spec.rb
+++ b/spec/models/integrations/zentao_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Integrations::Zentao do
+RSpec.describe Integrations::Zentao, feature_category: :integrations do
let(:url) { 'https://jihudemo.zentao.net' }
let(:api_url) { 'https://jihudemo.zentao.net' }
let(:api_token) { 'ZENTAO_TOKEN' }
@@ -80,6 +80,12 @@ RSpec.describe Integrations::Zentao do
end
end
+ describe '#avatar_url' do
+ it 'returns the avatar image path' do
+ expect(subject.avatar_url).to eq(ActionController::Base.helpers.image_path('logos/zentao.svg'))
+ end
+ end
+
describe '#client_url' do
subject(:integration) { build(:zentao_integration, api_url: api_url, url: 'url').client_url }