diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/requests/api/graphql/mutations/commits/create_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/requests/api/graphql/mutations/commits/create_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/mutations/commits/create_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/mutations/commits/create_spec.rb b/spec/requests/api/graphql/mutations/commits/create_spec.rb new file mode 100644 index 00000000000..10a69932948 --- /dev/null +++ b/spec/requests/api/graphql/mutations/commits/create_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Creation of a new commit' do + include GraphqlHelpers + + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { create(:project, :public, :repository) } + 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) } + + context 'the user is not allowed to create a commit' do + it_behaves_like 'a mutation that returns top-level errors', + errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action'] + end + + context 'when user has permissions to create a commit' do + before do + project.add_developer(current_user) + end + + 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 + + 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 + end +end |