2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'spec_helper'
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe "Jira", :js do
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:actual_project) { create(:project, :public, :repository) }
|
|
|
|
let(:merge_request) { create(:merge_request, target_project: actual_project, source_project: actual_project) }
|
|
|
|
let(:issue_actual_project) { create(:issue, project: actual_project) }
|
|
|
|
let!(:other_project) { create(:project, :public) }
|
|
|
|
let!(:issue_other_project) { create(:issue, project: other_project) }
|
|
|
|
let(:issues) { [issue_actual_project, issue_other_project] }
|
|
|
|
|
|
|
|
shared_examples "correct references" do
|
|
|
|
before do
|
|
|
|
remotelink = double(:remotelink, all: [], build: double(save!: true))
|
|
|
|
|
|
|
|
stub_request(:get, "https://jira.example.com/rest/api/2/issue/JIRA-5")
|
|
|
|
stub_request(:post, "https://jira.example.com/rest/api/2/issue/JIRA-5/comment")
|
2019-12-26 22:10:19 +05:30
|
|
|
allow_next_instance_of(JIRA::Resource::Issue) do |instance|
|
|
|
|
allow(instance).to receive(:remotelink).and_return(remotelink)
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
visit(merge_request_path(merge_request))
|
|
|
|
|
|
|
|
build_note
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a link to the referenced issue on the preview" do
|
|
|
|
find(".js-md-preview-button").click
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
page.within(".md-preview-holder") do
|
|
|
|
links_expectations
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a link to the referenced issue after submit" do
|
|
|
|
click_button("Comment")
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
page.within("#diff-notes-app") do
|
|
|
|
links_expectations
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it "creates a note on the referenced issues", :sidekiq_might_not_need_inline do
|
2018-11-08 19:23:39 +05:30
|
|
|
click_button("Comment")
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
if referenced_issues.include?(issue_actual_project)
|
|
|
|
visit(issue_path(issue_actual_project))
|
|
|
|
|
|
|
|
page.within("#notes") do
|
|
|
|
expect(page).to have_content("#{user.to_reference} mentioned in merge request #{merge_request.to_reference}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if referenced_issues.include?(issue_other_project)
|
|
|
|
visit(issue_path(issue_other_project))
|
|
|
|
|
|
|
|
page.within("#notes") do
|
|
|
|
expect(page).to have_content("#{user.to_reference} mentioned in merge request #{merge_request.to_reference(other_project)}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when internal issues tracker is enabled for the other project" do
|
|
|
|
context "when only internal issues tracker is enabled for the actual project" do
|
|
|
|
include_examples "correct references" do
|
|
|
|
let(:referenced_issues) { [issue_actual_project, issue_other_project] }
|
|
|
|
let(:jira_referenced) { false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when both external and internal issues trackers are enabled for the actual project" do
|
|
|
|
before do
|
2021-09-30 23:02:18 +05:30
|
|
|
create(:jira_integration, project: actual_project)
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "correct references" do
|
|
|
|
let(:referenced_issues) { [issue_actual_project, issue_other_project] }
|
|
|
|
let(:jira_referenced) { true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when only external issues tracker is enabled for the actual project" do
|
|
|
|
let(:actual_project) { create(:project, :public, :repository, :issues_disabled) }
|
|
|
|
|
|
|
|
before do
|
2021-09-30 23:02:18 +05:30
|
|
|
create(:jira_integration, project: actual_project)
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "correct references" do
|
|
|
|
let(:referenced_issues) { [issue_other_project] }
|
|
|
|
let(:jira_referenced) { true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no tracker is enabled for the actual project" do
|
|
|
|
let(:actual_project) { create(:project, :public, :repository, :issues_disabled) }
|
|
|
|
|
|
|
|
include_examples 'correct references' do
|
|
|
|
let(:referenced_issues) { [issue_other_project] }
|
|
|
|
let(:jira_referenced) { false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when internal issues tracker is disabled for the other project" do
|
|
|
|
let(:other_project) { create(:project, :public, :repository, :issues_disabled) }
|
|
|
|
|
|
|
|
context "when only internal issues tracker is enabled for the actual project" do
|
|
|
|
include_examples "correct references" do
|
|
|
|
let(:referenced_issues) { [issue_actual_project] }
|
|
|
|
let(:jira_referenced) { false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when both external and internal issues trackers are enabled for the actual project" do
|
|
|
|
before do
|
2021-09-30 23:02:18 +05:30
|
|
|
create(:jira_integration, project: actual_project)
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "correct references" do
|
|
|
|
let(:referenced_issues) { [issue_actual_project] }
|
|
|
|
let(:jira_referenced) { true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when only external issues tracker is enabled for the actual project" do
|
|
|
|
let(:actual_project) { create(:project, :public, :repository, :issues_disabled) }
|
|
|
|
|
|
|
|
before do
|
2021-09-30 23:02:18 +05:30
|
|
|
create(:jira_integration, project: actual_project)
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "correct references" do
|
|
|
|
let(:referenced_issues) { [] }
|
|
|
|
let(:jira_referenced) { true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no issues tracker is enabled for the actual project" do
|
|
|
|
let(:actual_project) { create(:project, :public, :repository, :issues_disabled) }
|
|
|
|
|
|
|
|
include_examples "correct references" do
|
|
|
|
let(:referenced_issues) { [] }
|
|
|
|
let(:jira_referenced) { false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def build_note
|
|
|
|
markdown = <<~HEREDOC
|
|
|
|
Referencing internal issue #{issue_actual_project.to_reference},
|
|
|
|
cross-project #{issue_other_project.to_reference(actual_project)} external JIRA-5
|
2020-04-22 19:07:51 +05:30
|
|
|
and non existing ##{non_existing_record_iid}
|
2018-11-08 19:23:39 +05:30
|
|
|
HEREDOC
|
|
|
|
|
|
|
|
page.within("#diff-notes-app") do
|
|
|
|
fill_in("note-body", with: markdown)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def links_expectations
|
|
|
|
issues.each do |issue|
|
|
|
|
if referenced_issues.include?(issue)
|
|
|
|
expect(page).to have_link(issue.to_reference, href: issue_path(issue))
|
|
|
|
else
|
|
|
|
expect(page).not_to have_link(issue.to_reference, href: issue_path(issue))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if jira_referenced
|
|
|
|
expect(page).to have_link("JIRA-5", href: "https://jira.example.com/browse/JIRA-5")
|
|
|
|
else
|
|
|
|
expect(page).not_to have_link("JIRA-5", href: "https://jira.example.com/browse/JIRA-5")
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(page).not_to have_link("##{non_existing_record_iid}")
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|