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

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

75 lines
2 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Creation of a new commit', feature_category: :source_code_management do
2020-06-23 00:09:42 +05:30
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository) }
2021-09-30 23:02:18 +05:30
2020-06-23 00:09:42 +05:30
let(:input) { { project_path: project.full_path, branch: branch, message: message, actions: actions } }
let(:branch) { 'master' }
let(:message) { 'Commit message' }
let(:actions) do
[
{
action: 'CREATE',
filePath: 'NEW_FILE.md',
content: 'Hello'
}
]
end
let(:mutation) { graphql_mutation(:commit_create, input) }
let(:mutation_response) { graphql_mutation_response(:commit_create) }
2021-01-29 00:20:46 +05:30
shared_examples 'a commit is successful' do
it 'creates a new commit' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['commit']).to include(
'title' => message
)
end
end
2020-06-23 00:09:42 +05:30
context 'the user is not allowed to create a commit' do
2020-11-24 15:15:51 +05:30
it_behaves_like 'a mutation that returns a top-level access error'
2020-06-23 00:09:42 +05:30
end
context 'when user has permissions to create a commit' do
before do
project.add_developer(current_user)
end
2021-01-29 00:20:46 +05:30
it_behaves_like 'a commit is successful'
2020-06-23 00:09:42 +05:30
context 'when branch is not correct' do
let(:branch) { 'unknown' }
it_behaves_like 'a mutation that returns errors in the response',
errors: ['You can only create or edit files when you are on a branch']
end
2021-01-29 00:20:46 +05:30
context 'when branch is new, and a start_branch is defined' do
let(:input) { { project_path: project.full_path, branch: branch, start_branch: start_branch, message: message, actions: actions } }
let(:branch) { 'new-branch' }
let(:start_branch) { 'master' }
let(:actions) do
[
{
action: 'CREATE',
filePath: 'ANOTHER_FILE.md',
content: 'Bye'
}
]
end
it_behaves_like 'a commit is successful'
end
2020-06-23 00:09:42 +05:30
end
end