debian-mirror-gitlab/spec/requests/api/graphql/mutations/branches/create_spec.rb

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

100 lines
2.9 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Creation of a new branch', feature_category: :source_code_management do
2020-05-24 23:13:21 +05:30
include GraphqlHelpers
2022-10-11 01:57:18 +05:30
let_it_be(:group) { create(:group, :public) }
2020-05-24 23:13:21 +05:30
let_it_be(:current_user) { create(:user) }
2021-09-30 23:02:18 +05:30
2020-05-24 23:13:21 +05:30
let(:input) { { project_path: project.full_path, name: new_branch, ref: ref } }
2022-10-11 01:57:18 +05:30
let(:new_branch) { "new_branch_#{SecureRandom.hex(4)}" }
2020-05-24 23:13:21 +05:30
let(:ref) { 'master' }
let(:mutation) { graphql_mutation(:create_branch, input) }
let(:mutation_response) { graphql_mutation_response(:create_branch) }
2022-10-11 01:57:18 +05:30
shared_examples 'creates a new branch' do
specify do
2020-05-24 23:13:21 +05:30
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['branch']).to include(
'name' => new_branch,
'commit' => a_hash_including('id')
)
end
2022-10-11 01:57:18 +05:30
end
context 'when project is public' do
let_it_be(:project) { create(:project, :public, :empty_repo) }
context 'when user is not allowed to create a branch' do
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when user is a direct project member' do
context 'and user is a developer' do
before do
project.add_developer(current_user)
end
it_behaves_like 'creates a new branch'
context 'when ref is not correct' do
err_msg = 'Failed to create branch \'another_branch\': invalid reference name \'unknown\''
let(:new_branch) { 'another_branch' }
let(:ref) { 'unknown' }
it_behaves_like 'a mutation that returns errors in the response', errors: [err_msg]
end
end
end
context 'when user is an inherited member from the group' do
context 'when project has a private repository' do
let_it_be(:project) { create(:project, :public, :empty_repo, :repository_private, group: group) }
context 'and user is a guest' do
before do
group.add_guest(current_user)
end
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'and user is a developer' do
before do
group.add_developer(current_user)
end
it_behaves_like 'creates a new branch'
end
end
end
end
context 'when project is private' do
let_it_be(:project) { create(:project, :private, :empty_repo, group: group) }
context 'when user is an inherited member from the group' do
context 'and user is a guest' do
before do
group.add_guest(current_user)
end
it_behaves_like 'a mutation that returns a top-level access error'
end
2020-05-24 23:13:21 +05:30
2022-10-11 01:57:18 +05:30
context 'and user is a developer' do
before do
group.add_developer(current_user)
end
2020-05-24 23:13:21 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'creates a new branch'
end
2020-05-24 23:13:21 +05:30
end
end
end