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/project_services')
-rw-r--r--spec/models/project_services/alerts_service_spec.rb39
-rw-r--r--spec/models/project_services/chat_notification_service_spec.rb33
-rw-r--r--spec/models/project_services/confluence_service_spec.rb6
-rw-r--r--spec/models/project_services/datadog_service_spec.rb36
-rw-r--r--spec/models/project_services/jira_service_spec.rb61
-rw-r--r--spec/models/project_services/jira_tracker_data_spec.rb21
6 files changed, 122 insertions, 74 deletions
diff --git a/spec/models/project_services/alerts_service_spec.rb b/spec/models/project_services/alerts_service_spec.rb
deleted file mode 100644
index 75b91c29914..00000000000
--- a/spec/models/project_services/alerts_service_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-# AlertsService is stripped down to only required methods
-# to avoid errors loading integration-related pages if
-# records are present.
-RSpec.describe AlertsService do
- let_it_be(:project) { create(:project) }
- subject(:service) { described_class.new(project: project) }
-
- it { is_expected.to be_valid }
-
- describe '#to_param' do
- subject { service.to_param }
-
- it { is_expected.to eq('alerts') }
- end
-
- describe '#supported_events' do
- subject { service.supported_events }
-
- it { is_expected.to be_empty }
- end
-
- describe '#save' do
- it 'prevents records from being created or updated' do
- expect(Gitlab::ProjectServiceLogger).to receive(:error).with(
- hash_including(message: 'Prevented attempt to save or update deprecated AlertsService')
- )
-
- expect(service.save).to be_falsey
-
- expect(service.errors.full_messages).to include(
- 'Alerts endpoint is deprecated and should not be created or modified. Use HTTP Integrations instead.'
- )
- end
- end
-end
diff --git a/spec/models/project_services/chat_notification_service_spec.rb b/spec/models/project_services/chat_notification_service_spec.rb
index 77a1377c138..476d99364b6 100644
--- a/spec/models/project_services/chat_notification_service_spec.rb
+++ b/spec/models/project_services/chat_notification_service_spec.rb
@@ -75,6 +75,39 @@ RSpec.describe ChatNotificationService do
end
end
+ context 'when the data object has a label' do
+ let(:label) { create(:label, project: project, name: 'Bug')}
+ let(:issue) { create(:labeled_issue, project: project, labels: [label]) }
+ let(:note) { create(:note, noteable: issue, project: project)}
+ let(:data) { Gitlab::DataBuilder::Note.build(note, user) }
+
+ it 'notifies the chat service' do
+ expect(chat_service).to receive(:notify).with(any_args)
+
+ chat_service.execute(data)
+ end
+
+ context 'and the chat_service has a label filter that does not matches the label' do
+ subject(:chat_service) { described_class.new(labels_to_be_notified: '~some random label') }
+
+ it 'does not notify the chat service' do
+ expect(chat_service).not_to receive(:notify)
+
+ chat_service.execute(data)
+ end
+ end
+
+ context 'and the chat_service has a label filter that matches the label' do
+ subject(:chat_service) { described_class.new(labels_to_be_notified: '~Backend, ~Bug') }
+
+ it 'notifies the chat service' do
+ expect(chat_service).to receive(:notify).with(any_args)
+
+ chat_service.execute(data)
+ end
+ end
+ end
+
context 'with "channel" property' do
before do
allow(chat_service).to receive(:channel).and_return(channel)
diff --git a/spec/models/project_services/confluence_service_spec.rb b/spec/models/project_services/confluence_service_spec.rb
index 5d153b17070..6c7ba2c9f32 100644
--- a/spec/models/project_services/confluence_service_spec.rb
+++ b/spec/models/project_services/confluence_service_spec.rb
@@ -43,13 +43,13 @@ RSpec.describe ConfluenceService do
end
end
- describe '#detailed_description' do
+ describe '#help' do
it 'can correctly return a link to the project wiki when active' do
project = create(:project)
subject.project = project
subject.active = true
- expect(subject.detailed_description).to include(Gitlab::Routing.url_helpers.project_wikis_url(project))
+ expect(subject.help).to include(Gitlab::Routing.url_helpers.project_wikis_url(project))
end
context 'when the project wiki is not enabled' do
@@ -60,7 +60,7 @@ RSpec.describe ConfluenceService do
[true, false].each do |active|
subject.active = active
- expect(subject.detailed_description).to be_nil
+ expect(subject.help).to be_nil
end
end
end
diff --git a/spec/models/project_services/datadog_service_spec.rb b/spec/models/project_services/datadog_service_spec.rb
index 1d9f49e4824..d15ea1f351b 100644
--- a/spec/models/project_services/datadog_service_spec.rb
+++ b/spec/models/project_services/datadog_service_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe DatadogService, :model do
let(:active) { true }
let(:dd_site) { 'datadoghq.com' }
let(:default_url) { 'https://webhooks-http-intake.logs.datadoghq.com/v1/input/' }
- let(:api_url) { nil }
+ let(:api_url) { '' }
let(:api_key) { SecureRandom.hex(32) }
let(:dd_env) { 'ci' }
let(:dd_service) { 'awesome-gitlab' }
@@ -22,13 +22,11 @@ RSpec.describe DatadogService, :model do
described_class.new(
active: active,
project: project,
- properties: {
- datadog_site: dd_site,
- api_url: api_url,
- api_key: api_key,
- datadog_env: dd_env,
- datadog_service: dd_service
- }
+ datadog_site: dd_site,
+ api_url: api_url,
+ api_key: api_key,
+ datadog_env: dd_env,
+ datadog_service: dd_service
)
end
@@ -58,7 +56,7 @@ RSpec.describe DatadogService, :model do
context 'when selecting site' do
let(:dd_site) { 'datadoghq.com' }
- let(:api_url) { nil }
+ let(:api_url) { '' }
it { is_expected.to validate_presence_of(:datadog_site) }
it { is_expected.not_to validate_presence_of(:api_url) }
@@ -66,7 +64,7 @@ RSpec.describe DatadogService, :model do
end
context 'with custom api_url' do
- let(:dd_site) { nil }
+ let(:dd_site) { '' }
let(:api_url) { 'https://webhooks-http-intake.logs.datad0g.com/v1/input/' }
it { is_expected.not_to validate_presence_of(:datadog_site) }
@@ -76,13 +74,21 @@ RSpec.describe DatadogService, :model do
end
context 'when missing site and api_url' do
- let(:dd_site) { nil }
- let(:api_url) { nil }
+ let(:dd_site) { '' }
+ let(:api_url) { '' }
it { is_expected.not_to be_valid }
it { is_expected.to validate_presence_of(:datadog_site) }
it { is_expected.to validate_presence_of(:api_url) }
end
+
+ context 'when providing both site and api_url' do
+ let(:dd_site) { 'datadoghq.com' }
+ let(:api_url) { default_url }
+
+ it { is_expected.not_to allow_value('datadog hq.com').for(:datadog_site) }
+ it { is_expected.not_to allow_value('example.com').for(:api_url) }
+ end
end
context 'when service is not active' do
@@ -113,8 +119,8 @@ RSpec.describe DatadogService, :model do
end
context 'without optional params' do
- let(:dd_service) { nil }
- let(:dd_env) { nil }
+ let(:dd_service) { '' }
+ let(:dd_env) { '' }
it { is_expected.to eq(default_url + api_key) }
end
@@ -126,7 +132,7 @@ RSpec.describe DatadogService, :model do
it { is_expected.to eq("https://app.#{dd_site}/account/settings#api") }
context 'with unset datadog_site' do
- let(:dd_site) { nil }
+ let(:dd_site) { '' }
it { is_expected.to eq("https://docs.datadoghq.com/account_management/api-app-keys/") }
end
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb
index cd0873bddd2..78bd0e91208 100644
--- a/spec/models/project_services/jira_service_spec.rb
+++ b/spec/models/project_services/jira_service_spec.rb
@@ -6,6 +6,8 @@ RSpec.describe JiraService do
include AssetsHelpers
let_it_be(:project) { create(:project, :repository) }
+
+ let(:current_user) { build_stubbed(:user) }
let(:url) { 'http://jira.example.com' }
let(:api_url) { 'http://api-jira.example.com' }
let(:username) { 'jira-username' }
@@ -456,6 +458,16 @@ RSpec.describe JiraService do
expect(WebMock).to have_requested(:get, issue_url)
end
+
+ context 'with options' do
+ let(:issue_url) { "#{url}/rest/api/2/issue/#{issue_key}?expand=renderedFields" }
+
+ it 'calls the Jira API with the options to get the issue' do
+ jira_service.find_issue(issue_key, rendered_fields: true)
+
+ expect(WebMock).to have_requested(:get, issue_url)
+ end
+ end
end
describe '#close_issue' do
@@ -498,25 +510,38 @@ RSpec.describe JiraService do
WebMock.stub_request(:post, @remote_link_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password))
end
+ let(:external_issue) { ExternalIssue.new('JIRA-123', project) }
+
+ def close_issue
+ @jira_service.close_issue(resource, external_issue, current_user)
+ end
+
it 'calls Jira API' do
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
expect(WebMock).to have_requested(:post, @comment_url).with(
body: /Issue solved with/
).once
end
+ it 'tracks usage' do
+ expect(Gitlab::UsageDataCounters::HLLRedisCounter)
+ .to receive(:track_event)
+ .with('i_ecosystem_jira_service_close_issue', values: current_user.id)
+
+ close_issue
+ end
+
it 'does not fail if remote_link.all on issue returns nil' do
allow(JIRA::Resource::Remotelink).to receive(:all).and_return(nil)
- expect { @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project)) }
- .not_to raise_error
+ expect { close_issue }.not_to raise_error
end
# Check https://developer.atlassian.com/jiradev/jira-platform/guides/other/guide-jira-remote-issue-links/fields-in-remote-issue-links
# for more information
it 'creates Remote Link reference in Jira for comment' do
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
favicon_path = "http://localhost/assets/#{find_asset('favicon.png').digest_path}"
@@ -540,7 +565,7 @@ RSpec.describe JiraService do
context 'when "comment_on_event_enabled" is set to false' do
it 'creates Remote Link reference but does not create comment' do
allow(@jira_service).to receive_messages(comment_on_event_enabled: false)
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
expect(WebMock).not_to have_requested(:post, @comment_url)
expect(WebMock).to have_requested(:post, @remote_link_url)
@@ -562,7 +587,7 @@ RSpec.describe JiraService do
expect(remote_link).to receive(:save!)
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
expect(WebMock).not_to have_requested(:post, @comment_url)
end
@@ -571,7 +596,7 @@ RSpec.describe JiraService do
it 'does not send comment or remote links to issues already closed' do
allow_any_instance_of(JIRA::Resource::Issue).to receive(:resolution).and_return(true)
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
expect(WebMock).not_to have_requested(:post, @comment_url)
expect(WebMock).not_to have_requested(:post, @remote_link_url)
@@ -580,7 +605,7 @@ RSpec.describe JiraService do
it 'does not send comment or remote links to issues with unknown resolution' do
allow_any_instance_of(JIRA::Resource::Issue).to receive(:respond_to?).with(:resolution).and_return(false)
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
expect(WebMock).not_to have_requested(:post, @comment_url)
expect(WebMock).not_to have_requested(:post, @remote_link_url)
@@ -589,7 +614,7 @@ RSpec.describe JiraService do
it 'references the GitLab commit' do
stub_config_setting(base_url: custom_base_url)
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
expect(WebMock).to have_requested(:post, @comment_url).with(
body: %r{#{custom_base_url}/#{project.full_path}/-/commit/#{commit_id}}
@@ -604,7 +629,7 @@ RSpec.describe JiraService do
{ script_name: '/gitlab' }
end
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
expect(WebMock).to have_requested(:post, @comment_url).with(
body: %r{#{Gitlab.config.gitlab.url}/#{project.full_path}/-/commit/#{commit_id}}
@@ -615,7 +640,7 @@ RSpec.describe JiraService do
allow(@jira_service).to receive(:log_error)
WebMock.stub_request(:post, @transitions_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).and_raise("Bad Request")
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
expect(@jira_service).to have_received(:log_error).with(
"Issue transition failed",
@@ -628,7 +653,7 @@ RSpec.describe JiraService do
end
it 'calls the api with jira_issue_transition_id' do
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
expect(WebMock).to have_requested(:post, @transitions_url).with(
body: /999/
@@ -639,7 +664,7 @@ RSpec.describe JiraService do
it 'calls the api with transition ids separated by comma' do
allow(@jira_service).to receive_messages(jira_issue_transition_id: '1,2,3')
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
1.upto(3) do |transition_id|
expect(WebMock).to have_requested(:post, @transitions_url).with(
@@ -651,7 +676,7 @@ RSpec.describe JiraService do
it 'calls the api with transition ids separated by semicolon' do
allow(@jira_service).to receive_messages(jira_issue_transition_id: '1;2;3')
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ close_issue
1.upto(3) do |transition_id|
expect(WebMock).to have_requested(:post, @transitions_url).with(
@@ -702,6 +727,14 @@ RSpec.describe JiraService do
body: /mentioned this issue in/
).once
end
+
+ it 'tracks usage' do
+ expect(Gitlab::UsageDataCounters::HLLRedisCounter)
+ .to receive(:track_event)
+ .with('i_ecosystem_jira_service_cross_reference', values: user.id)
+
+ subject
+ end
end
context 'when resource is a commit' do
diff --git a/spec/models/project_services/jira_tracker_data_spec.rb b/spec/models/project_services/jira_tracker_data_spec.rb
index f2e2fa65e93..46194efcb3d 100644
--- a/spec/models/project_services/jira_tracker_data_spec.rb
+++ b/spec/models/project_services/jira_tracker_data_spec.rb
@@ -3,13 +3,28 @@
require 'spec_helper'
RSpec.describe JiraTrackerData do
- let(:service) { build(:jira_service) }
-
- describe 'Associations' do
+ describe 'associations' do
it { is_expected.to belong_to(:service) }
end
describe 'deployment_type' do
it { is_expected.to define_enum_for(:deployment_type).with_values([:unknown, :server, :cloud]).with_prefix(:deployment) }
end
+
+ describe 'proxy settings' do
+ it { is_expected.to validate_length_of(:proxy_address).is_at_most(2048) }
+ it { is_expected.to validate_length_of(:proxy_port).is_at_most(5) }
+ it { is_expected.to validate_length_of(:proxy_username).is_at_most(255) }
+ it { is_expected.to validate_length_of(:proxy_password).is_at_most(255) }
+ end
+
+ describe 'encrypted attributes' do
+ subject { described_class.encrypted_attributes.keys }
+
+ it {
+ is_expected.to contain_exactly(
+ :api_url, :password, :proxy_address, :proxy_password, :proxy_port, :proxy_username, :url, :username
+ )
+ }
+ end
end