2019-11-04 04:06:21 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Mutations::MergeRequests::SetMilestone do
|
2019-11-04 04:06:21 -05:00
|
|
|
let(:user) { create(:user) }
|
2020-10-01 14:10:20 -04:00
|
|
|
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) }
|
2019-12-17 13:07:48 -05:00
|
|
|
|
2020-10-01 14:10:20 -04:00
|
|
|
subject { mutation.resolve(project_path: project.full_path, iid: merge_request.iid, milestone: milestone) }
|
2019-11-04 04:06:21 -05:00
|
|
|
|
2020-05-06 23:09:46 -04:00
|
|
|
specify { expect(described_class).to require_graphql_authorizations(:update_merge_request) }
|
|
|
|
|
2019-11-04 04:06:21 -05:00
|
|
|
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
|
|
|
|
|
2020-10-26 14:08:27 -04:00
|
|
|
it_behaves_like 'permission level for merge request mutation is correctly verified'
|
|
|
|
|
2019-11-04 04:06:21 -05:00
|
|
|
context 'when the user can update the merge request' do
|
|
|
|
before do
|
2020-10-01 14:10:20 -04:00
|
|
|
project.add_developer(user)
|
2019-11-04 04:06:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the merge request with the milestone' do
|
2020-10-01 14:10:20 -04:00
|
|
|
expect(subject[:merge_request]).to eq(merge_request)
|
|
|
|
expect(subject[:merge_request].milestone).to eq(milestone)
|
2019-11-04 04:06:21 -05:00
|
|
|
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-01 14:10:20 -04:00
|
|
|
merge_request.update!(milestone: create(:milestone, project: project))
|
2019-11-04 04:06:21 -05:00
|
|
|
|
2020-10-01 14:10:20 -04:00
|
|
|
expect(subject[:merge_request].milestone).to be_nil
|
2019-11-04 04:06:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not do anything if the MR already does not have a milestone' do
|
2020-10-01 14:10:20 -04:00
|
|
|
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-11-04 04:06:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|