2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Mutations::MergeRequests::SetMilestone do
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:user) { create(:user) }
|
2020-10-04 03:57:07 +05:30
|
|
|
let(:project) { create(:project, :private) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, target_project: project, assignees: [user]) }
|
|
|
|
let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
|
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-10-04 03:57:07 +05:30
|
|
|
subject { mutation.resolve(project_path: project.full_path, iid: merge_request.iid, milestone: milestone) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
specify { expect(described_class).to require_graphql_authorizations(:update_merge_request) }
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
describe '#resolve' do
|
|
|
|
it 'raises an error if the resource is not accessible to the user' do
|
|
|
|
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it_behaves_like 'permission level for merge request mutation is correctly verified'
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'when the user can update the merge request' do
|
|
|
|
before do
|
2020-10-04 03:57:07 +05:30
|
|
|
project.add_developer(user)
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the merge request with the milestone' do
|
2020-10-04 03:57:07 +05:30
|
|
|
expect(subject[:merge_request]).to eq(merge_request)
|
|
|
|
expect(subject[:merge_request].milestone).to eq(milestone)
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(subject[:errors]).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns errors merge request could not be updated' do
|
|
|
|
# Make the merge request invalid
|
|
|
|
merge_request.allow_broken = true
|
|
|
|
merge_request.update!(source_project: nil)
|
|
|
|
|
|
|
|
expect(subject[:errors]).not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passing milestone_id as nil' do
|
|
|
|
let(:milestone) { nil }
|
|
|
|
|
|
|
|
it 'removes the milestone' do
|
2020-10-04 03:57:07 +05:30
|
|
|
merge_request.update!(milestone: create(:milestone, project: project))
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-10-04 03:57:07 +05:30
|
|
|
expect(subject[:merge_request].milestone).to be_nil
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not do anything if the MR already does not have a milestone' do
|
2020-10-04 03:57:07 +05:30
|
|
|
expect(subject[:merge_request].milestone).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issue assignee is a guest' do
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update the milestone' do
|
|
|
|
expect(subject[:merge_request]).to eq(merge_request)
|
|
|
|
expect(subject[:merge_request].milestone).to be_nil
|
|
|
|
expect(subject[:errors]).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passing milestone_id as nil' do
|
|
|
|
let(:milestone) { nil }
|
|
|
|
|
|
|
|
it 'does not remove the milestone' do
|
|
|
|
merge_request.update!(milestone: create(:milestone, project: project))
|
|
|
|
|
|
|
|
expect(subject[:merge_request].milestone).not_to be_nil
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|