debian-mirror-gitlab/spec/serializers/merge_request_poll_widget_entity_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

222 lines
6.7 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe MergeRequestPollWidgetEntity do
2020-01-01 13:55:28 +05:30
include ProjectForksHelper
2020-07-28 23:09:34 +05:30
using RSpec::Parameterized::TableSyntax
2020-01-01 13:55:28 +05:30
2021-04-29 21:17:54 +05:30
let_it_be(:project) { create :project, :repository }
let_it_be(:resource) { create(:merge_request, source_project: project, target_project: project) }
let_it_be(:user) { create(:user) }
2020-01-01 13:55:28 +05:30
let(:request) { double('request', current_user: user, project: project) }
2021-04-29 21:17:54 +05:30
let(:options) { {} }
2020-01-01 13:55:28 +05:30
subject do
2021-04-29 21:17:54 +05:30
described_class.new(resource, { request: request }.merge(options)).as_json
2020-01-01 13:55:28 +05:30
end
it 'has default_merge_commit_message_with_description' do
expect(subject[:default_merge_commit_message_with_description])
.to eq(resource.default_merge_commit_message(include_description: true))
end
describe 'new_blob_path' do
context 'when user can push to project' do
it 'returns path' do
project.add_developer(user)
expect(subject[:new_blob_path])
2020-03-13 15:44:24 +05:30
.to eq("/#{resource.project.full_path}/-/new/#{resource.source_branch}")
2020-01-01 13:55:28 +05:30
end
end
context 'when user cannot push to project' do
it 'returns nil' do
expect(subject[:new_blob_path]).to be_nil
end
end
end
describe 'auto merge' do
2020-04-22 19:07:51 +05:30
before do
project.add_maintainer(user)
end
2020-01-01 13:55:28 +05:30
context 'when auto merge is enabled' do
let(:resource) { create(:merge_request, :merge_when_pipeline_succeeds) }
it 'returns auto merge related information' do
expect(subject[:auto_merge_strategy]).to eq('merge_when_pipeline_succeeds')
end
end
context 'when auto merge is not enabled' do
let(:resource) { create(:merge_request) }
it 'returns auto merge related information' do
expect(subject[:auto_merge_strategy]).to be_nil
end
end
context 'when head pipeline is running' do
before do
create(:ci_pipeline, :running, project: project,
ref: resource.source_branch,
sha: resource.diff_head_sha)
resource.update_head_pipeline
end
it 'returns available auto merge strategies' do
expect(subject[:available_auto_merge_strategies]).to eq(%w[merge_when_pipeline_succeeds])
end
end
2020-07-28 23:09:34 +05:30
describe 'squash defaults for projects' do
where(:squash_option, :value, :default, :readonly) do
'always' | true | true | true
'never' | false | false | true
'default_on' | false | true | false
'default_off' | false | false | false
end
with_them do
before do
project.project_setting.update!(squash_option: squash_option)
end
it 'the key reflects the correct value' do
expect(subject[:squash_on_merge]).to eq(value)
expect(subject[:squash_enabled_by_default]).to eq(default)
expect(subject[:squash_readonly]).to eq(readonly)
end
end
end
2020-01-01 13:55:28 +05:30
context 'when head pipeline is finished' do
before do
create(:ci_pipeline, :success, project: project,
ref: resource.source_branch,
sha: resource.diff_head_sha)
resource.update_head_pipeline
end
it 'returns available auto merge strategies' do
expect(subject[:available_auto_merge_strategies]).to be_empty
end
end
end
describe 'pipeline' do
2020-03-28 13:19:24 +05:30
let!(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.source_branch, sha: resource.source_branch_sha, head_pipeline_of: resource) }
2020-01-01 13:55:28 +05:30
before do
allow_any_instance_of(MergeRequestPresenter).to receive(:can?).and_call_original
allow_any_instance_of(MergeRequestPresenter).to receive(:can?).with(user, :read_pipeline, anything).and_return(result)
end
context 'when user has access to pipelines' do
let(:result) { true }
context 'when is up to date' do
let(:req) { double('request', current_user: user, project: project) }
2021-01-03 14:25:43 +05:30
it 'does not return pipeline' do
expect(subject[:pipeline]).to be_nil
2020-01-01 13:55:28 +05:30
end
2020-03-28 13:19:24 +05:30
it 'returns ci_status' do
expect(subject[:ci_status]).to eq('pending')
end
2020-01-01 13:55:28 +05:30
end
context 'when is not up to date' do
it 'returns nil' do
2020-11-24 15:15:51 +05:30
pipeline.update!(sha: "not up to date")
2020-01-01 13:55:28 +05:30
expect(subject[:pipeline]).to eq(nil)
end
end
end
context 'when user does not have access to pipelines' do
let(:result) { false }
2020-03-28 13:19:24 +05:30
let(:req) { double('request', current_user: user, project: project) }
2020-01-01 13:55:28 +05:30
2020-03-28 13:19:24 +05:30
it 'does not return ci_status' do
expect(subject[:ci_status]).to eq(nil)
end
2020-01-01 13:55:28 +05:30
end
end
2020-11-24 15:15:51 +05:30
describe '#builds_with_coverage' do
it 'serializes the builds with coverage' do
allow(resource).to receive(:head_pipeline_builds_with_coverage).and_return([
double(name: 'rspec', coverage: 91.5),
double(name: 'jest', coverage: 94.1)
])
result = subject[:builds_with_coverage]
expect(result).to eq([
{ name: 'rspec', coverage: 91.5 },
{ name: 'jest', coverage: 94.1 }
])
end
end
2021-04-29 21:17:54 +05:30
describe '#mergeable' do
it 'shows whether a merge request is mergeable' do
expect(subject[:mergeable]).to eq(true)
end
context 'when merge request is in checking state' do
before do
resource.mark_as_unchecked!
resource.mark_as_checking!
end
it 'calculates mergeability and returns true' do
expect(subject[:mergeable]).to eq(true)
end
end
end
2022-07-23 23:45:48 +05:30
describe '#mergeable_discussions_state?' do
context 'when change_response_code_merge_status is true' do
before do
stub_feature_flags(change_response_code_merge_status: true)
end
it 'returns mergeable discussions state' do
expect(subject[:mergeable_discussions_state]).to eq(true)
end
end
context 'when change_response_code_merge_status is false' do
context 'when merge request is in a mergeable state' do
before do
stub_feature_flags(change_response_code_merge_status: false)
allow(resource).to receive(:mergeable_discussions_state?).and_return(true)
end
it 'returns mergeable discussions state' do
expect(subject[:mergeable_discussions_state]).to eq(true)
end
end
context 'when merge request is not in a mergeable state' do
before do
stub_feature_flags(change_response_code_merge_status: false)
allow(resource).to receive(:mergeable_state?).and_return(false)
end
it 'returns mergeable discussions state' do
expect(subject[:mergeable_discussions_state]).to eq(false)
end
end
end
end
2020-01-01 13:55:28 +05:30
end