2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe GitlabSchema.types['MergeRequest'] do
|
2020-05-24 23:13:21 +05:30
|
|
|
specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::MergeRequest) }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
specify { expect(described_class).to require_graphql_authorizations(:read_merge_request) }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
specify { expect(described_class.interfaces).to include(Types::Notes::NoteableType) }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
specify { expect(described_class.interfaces).to include(Types::CurrentUserTodos) }
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'has the expected fields' do
|
|
|
|
expected_fields = %w[
|
|
|
|
notes discussions user_permissions id iid title title_html description
|
|
|
|
description_html state created_at updated_at source_project target_project
|
|
|
|
project project_id source_project_id target_project_id source_branch
|
|
|
|
target_branch work_in_progress merge_when_pipeline_succeeds diff_head_sha
|
2021-01-29 00:20:46 +05:30
|
|
|
merge_commit_sha user_notes_count user_discussions_count should_remove_source_branch
|
2020-07-28 23:09:34 +05:30
|
|
|
diff_refs diff_stats diff_stats_summary
|
2019-09-30 21:07:59 +05:30
|
|
|
force_remove_source_branch merge_status in_progress_merge_commit_sha
|
|
|
|
merge_error allow_collaboration should_be_rebased rebase_commit_sha
|
2021-01-29 00:20:46 +05:30
|
|
|
rebase_in_progress default_merge_commit_message
|
2020-06-23 00:09:42 +05:30
|
|
|
merge_ongoing mergeable_discussions_state web_url
|
2021-04-17 20:07:23 +05:30
|
|
|
source_branch_exists target_branch_exists diverged_from_target_branch
|
2019-12-21 20:55:43 +05:30
|
|
|
upvotes downvotes head_pipeline pipelines task_completion_status
|
2021-03-08 18:12:59 +05:30
|
|
|
milestone assignees reviewers participants subscribed labels discussion_locked time_estimate
|
2020-11-24 15:15:51 +05:30
|
|
|
total_time_spent reference author merged_at commit_count current_user_todos
|
2021-02-22 17:27:13 +05:30
|
|
|
conflicts auto_merge_enabled approved_by source_branch_protected
|
|
|
|
default_merge_commit_message_with_description squash_on_merge available_auto_merge_strategies
|
2021-03-08 18:12:59 +05:30
|
|
|
has_ci mergeable commits_without_merge_commits squash security_auto_fix default_squash_commit_message
|
|
|
|
auto_merge_strategy merge_user
|
2019-09-30 21:07:59 +05:30
|
|
|
]
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(described_class).to have_graphql_fields(*expected_fields).at_least
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
describe '#pipelines' do
|
|
|
|
subject { described_class.fields['pipelines'] }
|
|
|
|
|
|
|
|
it { is_expected.to have_attributes(max_page_size: 500) }
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe '#diff_stats_summary' do
|
|
|
|
subject { GitlabSchema.execute(query, context: { current_user: current_user }).as_json }
|
|
|
|
|
|
|
|
let(:current_user) { create :admin }
|
|
|
|
let(:query) do
|
|
|
|
%(
|
|
|
|
{
|
|
|
|
project(fullPath: "#{project.full_path}") {
|
|
|
|
mergeRequests {
|
|
|
|
nodes {
|
|
|
|
diffStatsSummary {
|
|
|
|
additions, deletions
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:merge_request) { create(:merge_request, target_project: project, source_project: project) }
|
|
|
|
|
|
|
|
let(:response) { subject.dig('data', 'project', 'mergeRequests', 'nodes').first['diffStatsSummary'] }
|
|
|
|
|
|
|
|
context 'when MR metrics has additions and deletions' do
|
|
|
|
before do
|
|
|
|
merge_request.metrics.update!(added_lines: 5, removed_lines: 8)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'pulls out data from metrics object' do
|
|
|
|
expect(response).to match('additions' => 5, 'deletions' => 8)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
describe '#diverged_from_target_branch' do
|
|
|
|
subject(:execute_query) { GitlabSchema.execute(query, context: { current_user: current_user }).as_json }
|
|
|
|
|
|
|
|
let!(:merge_request) { create(:merge_request, target_project: project, source_project: project) }
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:current_user) { create :admin }
|
|
|
|
let(:query) do
|
|
|
|
%(
|
|
|
|
{
|
|
|
|
project(fullPath: "#{project.full_path}") {
|
|
|
|
mergeRequests {
|
|
|
|
nodes {
|
|
|
|
divergedFromTargetBranch
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'delegates the diverged_from_target_branch? call to the merge request entity' do
|
|
|
|
expect_next_found_instance_of(MergeRequest) do |instance|
|
|
|
|
expect(instance).to receive(:diverged_from_target_branch?)
|
|
|
|
end
|
|
|
|
|
|
|
|
execute_query
|
|
|
|
end
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|