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/chat_message/pipeline_message_spec.rb4
-rw-r--r--spec/models/integrations/datadog_spec.rb9
-rw-r--r--spec/models/integrations/discord_spec.rb4
-rw-r--r--spec/models/integrations/drone_ci_spec.rb4
-rw-r--r--spec/models/integrations/hangouts_chat_spec.rb171
-rw-r--r--spec/models/integrations/harbor_spec.rb6
6 files changed, 183 insertions, 15 deletions
diff --git a/spec/models/integrations/chat_message/pipeline_message_spec.rb b/spec/models/integrations/chat_message/pipeline_message_spec.rb
index 68ef0ccb2e4..a63cc0b6d83 100644
--- a/spec/models/integrations/chat_message/pipeline_message_spec.rb
+++ b/spec/models/integrations/chat_message/pipeline_message_spec.rb
@@ -49,8 +49,8 @@ RSpec.describe Integrations::ChatMessage::PipelineMessage do
allow(test_project).to receive(:avatar_url).with(only_path: false).and_return(args[:project][:avatar_url])
allow(Project).to receive(:find) { test_project }
- test_pipeline = double("A test pipeline", has_yaml_errors?: has_yaml_errors,
- yaml_errors: "yaml error description here")
+ test_pipeline = double("A test pipeline",
+ has_yaml_errors?: has_yaml_errors, yaml_errors: "yaml error description here")
allow(Ci::Pipeline).to receive(:find) { test_pipeline }
allow(Gitlab::UrlBuilder).to receive(:build).with(test_commit).and_return("http://example.com/commit")
diff --git a/spec/models/integrations/datadog_spec.rb b/spec/models/integrations/datadog_spec.rb
index cfc44b22a84..4ac684e8ff0 100644
--- a/spec/models/integrations/datadog_spec.rb
+++ b/spec/models/integrations/datadog_spec.rb
@@ -203,13 +203,10 @@ RSpec.describe Integrations::Datadog do
end
before do
- stub_feature_flags(datadog_integration_logs_collection: enable_logs_collection)
stub_request(:post, expected_hook_url)
saved_instance.execute(data)
end
- let(:enable_logs_collection) { true }
-
context 'with pipeline data' do
let(:data) { pipeline_data }
let(:expected_headers) { { ::Gitlab::WebHooks::GITLAB_EVENT_HEADER => 'Pipeline Hook' } }
@@ -232,12 +229,6 @@ RSpec.describe Integrations::Datadog do
let(:expected_body) { data.to_json }
it { expect(a_request(:post, expected_hook_url).with(headers: expected_headers, body: expected_body)).to have_been_made }
-
- context 'but feature flag disabled' do
- let(:enable_logs_collection) { false }
-
- it { expect(a_request(:post, expected_hook_url)).not_to have_been_made }
- end
end
end
end
diff --git a/spec/models/integrations/discord_spec.rb b/spec/models/integrations/discord_spec.rb
index b85620782c1..eb90acc73be 100644
--- a/spec/models/integrations/discord_spec.rb
+++ b/spec/models/integrations/discord_spec.rb
@@ -23,10 +23,10 @@ RSpec.describe Integrations::Discord do
describe '#execute' do
include StubRequests
+ let_it_be(:project) { create(:project, :repository) }
+
let(:user) { create(:user) }
- let(:project) { create(:project, :repository) }
let(:webhook_url) { "https://example.gitlab.com/" }
-
let(:sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
diff --git a/spec/models/integrations/drone_ci_spec.rb b/spec/models/integrations/drone_ci_spec.rb
index 8a51f8a0705..905fee075ad 100644
--- a/spec/models/integrations/drone_ci_spec.rb
+++ b/spec/models/integrations/drone_ci_spec.rb
@@ -175,9 +175,9 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
end
{
- "killed" => :canceled,
+ "killed" => :canceled,
"failure" => :failed,
- "error" => :failed,
+ "error" => :failed,
"success" => "success"
}.each do |drone_status, our_status|
it "sets commit status to #{our_status.inspect} when returned status is #{drone_status.inspect}" do
diff --git a/spec/models/integrations/hangouts_chat_spec.rb b/spec/models/integrations/hangouts_chat_spec.rb
index 17b40c484f5..828bcdf5d8f 100644
--- a/spec/models/integrations/hangouts_chat_spec.rb
+++ b/spec/models/integrations/hangouts_chat_spec.rb
@@ -12,4 +12,175 @@ RSpec.describe Integrations::HangoutsChat do
}
end
end
+
+ let(:chat_integration) { described_class.new }
+ let(:webhook_url) { 'https://example.gitlab.com/' }
+ let(:webhook_url_regex) { /\A#{webhook_url}.*/ }
+
+ describe "#execute" do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :repository, :wiki_repo) }
+
+ before do
+ allow(chat_integration).to receive_messages(
+ project: project,
+ project_id: project.id,
+ webhook: webhook_url
+ )
+
+ WebMock.stub_request(:post, webhook_url_regex)
+ end
+
+ context 'with push events' do
+ let(:push_sample_data) do
+ Gitlab::DataBuilder::Push.build_sample(project, user)
+ end
+
+ it "adds thread key for push events" do
+ expect(chat_integration.execute(push_sample_data)).to be(true)
+
+ expect(WebMock).to have_requested(:post, webhook_url)
+ .with(query: hash_including({ "threadKey" => /push .*?/ }))
+ .once
+ end
+ end
+
+ context 'with issue events' do
+ let(:issues_sample_data) { create(:issue).to_hook_data(user) }
+
+ it "adds thread key for issue events" do
+ expect(chat_integration.execute(issues_sample_data)).to be(true)
+
+ expect(WebMock).to have_requested(:post, webhook_url)
+ .with(query: hash_including({ "threadKey" => /issue .*?/ }))
+ .once
+ end
+ end
+
+ context 'with merge events' do
+ let(:merge_sample_data) { create(:merge_request).to_hook_data(user) }
+
+ it "adds thread key for merge events" do
+ expect(chat_integration.execute(merge_sample_data)).to be(true)
+
+ expect(WebMock).to have_requested(:post, webhook_url)
+ .with(query: hash_including({ "threadKey" => /merge request .*?/ }))
+ .once
+ end
+ end
+
+ context 'with wiki page events' do
+ let(:wiki_page_sample_data) do
+ Gitlab::DataBuilder::WikiPage.build(create(:wiki_page, message: 'foo'), user, 'create')
+ end
+
+ it "adds thread key for wiki page events" do
+ expect(chat_integration.execute(wiki_page_sample_data)).to be(true)
+
+ expect(WebMock).to have_requested(:post, webhook_url)
+ .with(query: hash_including({ "threadKey" => /wiki_page .*?/ }))
+ .once
+ end
+ end
+
+ context 'with pipeline events' do
+ let(:pipeline) do
+ create(:ci_pipeline, :failed, project: project, sha: project.commit.sha, ref: project.default_branch)
+ end
+
+ let(:pipeline_sample_data) { Gitlab::DataBuilder::Pipeline.build(pipeline) }
+
+ it "adds thread key for pipeline events" do
+ expect(chat_integration.execute(pipeline_sample_data)).to be(true)
+
+ expect(WebMock).to have_requested(:post, webhook_url)
+ .with(query: hash_including({ "threadKey" => /pipeline .*?/ }))
+ .once
+ end
+ end
+ end
+
+ describe "Note events" do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :repository, creator: user) }
+
+ before do
+ allow(chat_integration).to receive_messages(
+ project: project,
+ project_id: project.id,
+ webhook: webhook_url
+ )
+
+ WebMock.stub_request(:post, webhook_url_regex)
+ end
+
+ context 'when commit comment event executed' do
+ let(:commit_note) do
+ create(:note_on_commit, author: user,
+ project: project,
+ commit_id: project.repository.commit.id,
+ note: 'a comment on a commit')
+ end
+
+ it "adds thread key" do
+ data = Gitlab::DataBuilder::Note.build(commit_note, user)
+
+ expect(chat_integration.execute(data)).to be(true)
+
+ expect(WebMock).to have_requested(:post, webhook_url)
+ .with(query: hash_including({ "threadKey" => /commit .*?/ }))
+ .once
+ end
+ end
+
+ context 'when merge request comment event executed' do
+ let(:merge_request_note) do
+ create(:note_on_merge_request, project: project,
+ note: "merge request note")
+ end
+
+ it "adds thread key" do
+ data = Gitlab::DataBuilder::Note.build(merge_request_note, user)
+
+ expect(chat_integration.execute(data)).to be(true)
+
+ expect(WebMock).to have_requested(:post, webhook_url)
+ .with(query: hash_including({ "threadKey" => /merge request .*?/ }))
+ .once
+ end
+ end
+
+ context 'when issue comment event executed' do
+ let(:issue_note) do
+ create(:note_on_issue, project: project, note: "issue note")
+ end
+
+ it "adds thread key" do
+ data = Gitlab::DataBuilder::Note.build(issue_note, user)
+
+ expect(chat_integration.execute(data)).to be(true)
+
+ expect(WebMock).to have_requested(:post, webhook_url)
+ .with(query: hash_including({ "threadKey" => /issue .*?/ }))
+ .once
+ end
+ end
+
+ context 'when snippet comment event executed' do
+ let(:snippet_note) do
+ create(:note_on_project_snippet, project: project,
+ note: "snippet note")
+ end
+
+ it "adds thread key" do
+ data = Gitlab::DataBuilder::Note.build(snippet_note, user)
+
+ expect(chat_integration.execute(data)).to be(true)
+
+ expect(WebMock).to have_requested(:post, webhook_url)
+ .with(query: hash_including({ "threadKey" => /snippet .*?/ }))
+ .once
+ end
+ end
+ end
end
diff --git a/spec/models/integrations/harbor_spec.rb b/spec/models/integrations/harbor_spec.rb
index 3952495119a..26b43fa3313 100644
--- a/spec/models/integrations/harbor_spec.rb
+++ b/spec/models/integrations/harbor_spec.rb
@@ -27,6 +27,12 @@ RSpec.describe Integrations::Harbor do
it { is_expected.to allow_value('https://demo.goharbor.io').for(:url) }
end
+ describe 'hostname' do
+ it 'returns the host of the integration url' do
+ expect(harbor_integration.hostname).to eq('demo.goharbor.io')
+ end
+ end
+
describe '#fields' do
it 'returns custom fields' do
expect(harbor_integration.fields.pluck(:name)).to eq(%w[url project_name username password])