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/services/system_note_service_spec.rb')
-rw-r--r--spec/services/system_note_service_spec.rb199
1 files changed, 12 insertions, 187 deletions
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb
index 1a421999ffb..ce0122ae301 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/spec/services/system_note_service_spec.rb
@@ -348,193 +348,6 @@ RSpec.describe SystemNoteService do
end
end
- describe 'Jira integration' do
- include JiraServiceHelper
-
- let(:project) { create(:jira_project, :repository) }
- let(:author) { create(:user) }
- let(:issue) { create(:issue, project: project) }
- let(:merge_request) { create(:merge_request, :simple, target_project: project, source_project: project) }
- let(:jira_issue) { ExternalIssue.new("JIRA-1", project)}
- let(:jira_tracker) { project.jira_integration }
- let(:commit) { project.commit }
- let(:comment_url) { jira_api_comment_url(jira_issue.id) }
- let(:success_message) { "SUCCESS: Successfully posted to http://jira.example.net." }
-
- before do
- stub_jira_integration_test
- stub_jira_urls(jira_issue.id)
- jira_integration_settings
- end
-
- def cross_reference(type, link_exists = false)
- noteable = type == 'commit' ? commit : merge_request
-
- links = []
- if link_exists
- url = if type == 'commit'
- "#{Settings.gitlab.base_url}/#{project.namespace.path}/#{project.path}/-/commit/#{commit.id}"
- else
- "#{Settings.gitlab.base_url}/#{project.namespace.path}/#{project.path}/-/merge_requests/#{merge_request.iid}"
- end
-
- link = double(object: { 'url' => url })
- links << link
- expect(link).to receive(:save!)
- end
-
- allow(JIRA::Resource::Remotelink).to receive(:all).and_return(links)
-
- described_class.cross_reference(jira_issue, noteable, author)
- end
-
- noteable_types = %w(merge_requests commit)
-
- noteable_types.each do |type|
- context "when noteable is a #{type}" do
- it "blocks cross reference when #{type.underscore}_events is false" do
- jira_tracker.update!("#{type}_events" => false)
-
- expect(cross_reference(type)).to eq(s_('JiraService|Events for %{noteable_model_name} are disabled.') % { noteable_model_name: type.pluralize.humanize.downcase })
- end
-
- it "creates cross reference when #{type.underscore}_events is true" do
- jira_tracker.update!("#{type}_events" => true)
-
- expect(cross_reference(type)).to eq(success_message)
- end
- end
-
- context 'when a new cross reference is created' do
- it 'creates a new comment and remote link' do
- cross_reference(type)
-
- expect(WebMock).to have_requested(:post, jira_api_comment_url(jira_issue))
- expect(WebMock).to have_requested(:post, jira_api_remote_link_url(jira_issue))
- end
- end
-
- context 'when a link exists' do
- it 'updates a link but does not create a new comment' do
- expect(WebMock).not_to have_requested(:post, jira_api_comment_url(jira_issue))
-
- cross_reference(type, true)
- end
- end
- end
-
- describe "new reference" do
- let(:favicon_path) { "http://localhost/assets/#{find_asset('favicon.png').digest_path}" }
-
- before do
- allow(JIRA::Resource::Remotelink).to receive(:all).and_return([])
- end
-
- context 'for commits' do
- it "creates comment" do
- result = described_class.cross_reference(jira_issue, commit, author)
-
- expect(result).to eq(success_message)
- end
-
- it "creates remote link" do
- described_class.cross_reference(jira_issue, commit, author)
-
- expect(WebMock).to have_requested(:post, jira_api_remote_link_url(jira_issue)).with(
- body: hash_including(
- GlobalID: "GitLab",
- relationship: 'mentioned on',
- object: {
- url: project_commit_url(project, commit),
- title: "Commit - #{commit.title}",
- icon: { title: "GitLab", url16x16: favicon_path },
- status: { resolved: false }
- }
- )
- ).once
- end
- end
-
- context 'for issues' do
- let(:issue) { create(:issue, project: project) }
-
- it "creates comment" do
- result = described_class.cross_reference(jira_issue, issue, author)
-
- expect(result).to eq(success_message)
- end
-
- it "creates remote link" do
- described_class.cross_reference(jira_issue, issue, author)
-
- expect(WebMock).to have_requested(:post, jira_api_remote_link_url(jira_issue)).with(
- body: hash_including(
- GlobalID: "GitLab",
- relationship: 'mentioned on',
- object: {
- url: project_issue_url(project, issue),
- title: "Issue - #{issue.title}",
- icon: { title: "GitLab", url16x16: favicon_path },
- status: { resolved: false }
- }
- )
- ).once
- end
- end
-
- context 'for snippets' do
- let(:snippet) { create(:snippet, project: project) }
-
- it "creates comment" do
- result = described_class.cross_reference(jira_issue, snippet, author)
-
- expect(result).to eq(success_message)
- end
-
- it "creates remote link" do
- described_class.cross_reference(jira_issue, snippet, author)
-
- expect(WebMock).to have_requested(:post, jira_api_remote_link_url(jira_issue)).with(
- body: hash_including(
- GlobalID: "GitLab",
- relationship: 'mentioned on',
- object: {
- url: project_snippet_url(project, snippet),
- title: "Snippet - #{snippet.title}",
- icon: { title: "GitLab", url16x16: favicon_path },
- status: { resolved: false }
- }
- )
- ).once
- end
- end
- end
-
- describe "existing reference" do
- before do
- allow(JIRA::Resource::Remotelink).to receive(:all).and_return([])
- message = double('message')
- allow(message).to receive(:include?) { true }
- allow_next_instance_of(JIRA::Resource::Issue) do |instance|
- allow(instance).to receive(:comments).and_return([OpenStruct.new(body: message)])
- end
- end
-
- it "does not return success message" do
- result = described_class.cross_reference(jira_issue, commit, author)
-
- expect(result).not_to eq(success_message)
- end
-
- it 'does not try to create comment and remote link' do
- subject
-
- expect(WebMock).not_to have_requested(:post, jira_api_comment_url(jira_issue))
- expect(WebMock).not_to have_requested(:post, jira_api_remote_link_url(jira_issue))
- end
- end
- end
-
describe '.change_time_estimate' do
it 'calls TimeTrackingService' do
expect_next_instance_of(::SystemNotes::TimeTrackingService) do |service|
@@ -781,6 +594,18 @@ RSpec.describe SystemNoteService do
end
end
+ describe '.resolve_incident_status' do
+ let(:incident) { build(:incident, :closed) }
+
+ it 'calls IncidentService' do
+ expect_next_instance_of(SystemNotes::IncidentService) do |service|
+ expect(service).to receive(:resolve_incident_status)
+ end
+
+ described_class.resolve_incident_status(incident, author)
+ end
+ end
+
describe '.log_resolving_alert' do
let(:alert) { build(:alert_management_alert) }
let(:monitoring_tool) { 'Prometheus' }