debian-mirror-gitlab/spec/graphql/mutations/merge_requests/create_spec.rb

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

145 lines
3.9 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Mutations::MergeRequests::Create do
2022-07-16 23:28:13 +05:30
include GraphqlHelpers
2020-06-23 00:09:42 +05:30
subject(:mutation) { described_class.new(object: nil, context: context, field: nil) }
2022-10-11 01:57:18 +05:30
let(:user) { create(:user) }
2022-01-26 12:08:38 +05:30
let(:context) do
2020-06-23 00:09:42 +05:30
GraphQL::Query::Context.new(
2022-07-16 23:28:13 +05:30
query: query_double(schema: nil),
2020-06-23 00:09:42 +05:30
values: { current_user: user },
object: nil
)
end
describe '#resolve' do
subject do
mutation.resolve(
project_path: project.full_path,
title: title,
source_branch: source_branch,
target_branch: target_branch,
2020-10-24 23:57:45 +05:30
description: description,
labels: labels
2020-06-23 00:09:42 +05:30
)
end
let(:title) { 'MergeRequest' }
let(:source_branch) { 'feature' }
let(:target_branch) { 'master' }
let(:description) { nil }
2020-10-24 23:57:45 +05:30
let(:labels) { nil }
2020-06-23 00:09:42 +05:30
let(:mutated_merge_request) { subject[:merge_request] }
2022-10-11 01:57:18 +05:30
shared_examples 'resource not available' do
it 'raises an error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
2020-06-23 00:09:42 +05:30
end
2022-10-11 01:57:18 +05:30
context 'when user is not a project member' do
let_it_be(:project) { create(:project, :public, :repository) }
2020-06-23 00:09:42 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'resource not available'
2020-06-23 00:09:42 +05:30
end
2022-10-11 01:57:18 +05:30
context 'when user is a direct project member' do
let_it_be(:project) { create(:project, :public, :repository) }
2020-06-23 00:09:42 +05:30
2022-10-11 01:57:18 +05:30
context 'and user is a guest' do
before do
project.add_guest(user)
end
2020-06-23 00:09:42 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'resource not available'
2020-06-23 00:09:42 +05:30
end
2022-10-11 01:57:18 +05:30
context 'and user is a developer' do
before do
project.add_developer(user)
end
it 'creates a new merge request' do
expect { mutated_merge_request }.to change(MergeRequest, :count).by(1)
end
2020-06-23 00:09:42 +05:30
2022-10-11 01:57:18 +05:30
it 'returns a new merge request' do
expect(mutated_merge_request.title).to eq(title)
2020-06-23 00:09:42 +05:30
expect(subject[:errors]).to be_empty
end
2022-10-11 01:57:18 +05:30
context 'when optional description field is set' do
let(:description) { 'content' }
2020-10-24 23:57:45 +05:30
2022-10-11 01:57:18 +05:30
it 'returns a new merge request with a description' do
expect(mutated_merge_request.description).to eq(description)
expect(subject[:errors]).to be_empty
end
end
context 'when optional labels field is set' do
let(:labels) { %w[label-1 label-2] }
it 'returns a new merge request with labels' do
expect(mutated_merge_request.labels.map(&:title)).to eq(labels)
expect(subject[:errors]).to be_empty
end
end
context 'when service cannot create a merge request' do
let(:title) { nil }
it 'does not create a new merge request' do
expect { mutated_merge_request }.not_to change(MergeRequest, :count)
end
it 'returns errors' do
expect(mutated_merge_request).to be_nil
expect(subject[:errors]).to match_array(['Title can\'t be blank'])
end
2020-10-24 23:57:45 +05:30
end
end
2022-10-11 01:57:18 +05:30
end
2020-10-24 23:57:45 +05:30
2022-10-11 01:57:18 +05:30
context 'when user is an inherited member from the group' do
let_it_be(:group) { create(:group, :public) }
2020-06-23 00:09:42 +05:30
2022-10-11 01:57:18 +05:30
context 'when project is public with private merge requests' do
let_it_be(:project) do
create(:project,
:public,
:repository,
group: group,
merge_requests_access_level: ProjectFeature::DISABLED)
2020-06-23 00:09:42 +05:30
end
2022-10-11 01:57:18 +05:30
context 'and user is a guest' do
before do
group.add_guest(user)
end
it_behaves_like 'resource not available'
end
end
context 'when project is private' do
let_it_be(:project) { create(:project, :private, :repository, group: group) }
context 'and user is a guest' do
before do
group.add_guest(user)
end
it_behaves_like 'resource not available'
2020-06-23 00:09:42 +05:30
end
end
end
end
end