diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/requests/api/graphql/mutations/snippets/update_spec.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/requests/api/graphql/mutations/snippets/update_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/mutations/snippets/update_spec.rb | 105 |
1 files changed, 50 insertions, 55 deletions
diff --git a/spec/requests/api/graphql/mutations/snippets/update_spec.rb b/spec/requests/api/graphql/mutations/snippets/update_spec.rb index 3f39c0ab851..58ce74b9263 100644 --- a/spec/requests/api/graphql/mutations/snippets/update_spec.rb +++ b/spec/requests/api/graphql/mutations/snippets/update_spec.rb @@ -12,18 +12,20 @@ RSpec.describe 'Updating a Snippet' do let(:updated_content) { 'Updated content' } let(:updated_description) { 'Updated description' } let(:updated_title) { 'Updated_title' } - let(:updated_file_name) { 'Updated file_name' } let(:current_user) { snippet.author } - + let(:updated_file) { 'CHANGELOG' } + let(:deleted_file) { 'README' } let(:snippet_gid) { GitlabSchema.id_from_object(snippet).to_s } let(:mutation_vars) do { id: snippet_gid, - content: updated_content, description: updated_description, visibility_level: 'public', - file_name: updated_file_name, - title: updated_title + title: updated_title, + blob_actions: [ + { action: :update, filePath: updated_file, content: updated_content }, + { action: :delete, filePath: deleted_file } + ] } end @@ -50,21 +52,32 @@ RSpec.describe 'Updating a Snippet' do end context 'when the user has permission' do - it 'updates the Snippet' do + it 'updates the snippet record' do post_graphql_mutation(mutation, current_user: current_user) expect(snippet.reload.title).to eq(updated_title) end - it 'returns the updated Snippet' do + it 'updates the Snippet' do + blob_to_update = blob_at(updated_file) + blob_to_delete = blob_at(deleted_file) + + expect(blob_to_update.data).not_to eq updated_content + expect(blob_to_delete).to be_present + post_graphql_mutation(mutation, current_user: current_user) - expect(mutation_response['snippet']['blob']['richData']).to be_nil - expect(mutation_response['snippet']['blob']['plainData']).to match(updated_content) - expect(mutation_response['snippet']['title']).to eq(updated_title) - expect(mutation_response['snippet']['description']).to eq(updated_description) - expect(mutation_response['snippet']['fileName']).to eq(updated_file_name) - expect(mutation_response['snippet']['visibilityLevel']).to eq('public') + blob_to_update = blob_at(updated_file) + blob_to_delete = blob_at(deleted_file) + + aggregate_failures do + expect(blob_to_update.data).to eq updated_content + expect(blob_to_delete).to be_nil + expect(blob_in_mutation_response(updated_file)['plainData']).to match(updated_content) + expect(mutation_response['snippet']['title']).to eq(updated_title) + expect(mutation_response['snippet']['description']).to eq(updated_description) + expect(mutation_response['snippet']['visibilityLevel']).to eq('public') + end end context 'when there are ActiveRecord validation errors' do @@ -79,16 +92,29 @@ RSpec.describe 'Updating a Snippet' do end it 'returns the Snippet with its original values' do + blob_to_update = blob_at(updated_file) + blob_to_delete = blob_at(deleted_file) + post_graphql_mutation(mutation, current_user: current_user) - expect(mutation_response['snippet']['blob']['richData']).to be_nil - expect(mutation_response['snippet']['blob']['plainData']).to match(original_content) - expect(mutation_response['snippet']['title']).to eq(original_title) - expect(mutation_response['snippet']['description']).to eq(original_description) - expect(mutation_response['snippet']['fileName']).to eq(original_file_name) - expect(mutation_response['snippet']['visibilityLevel']).to eq('private') + aggregate_failures do + expect(blob_at(updated_file).data).to eq blob_to_update.data + expect(blob_at(deleted_file).data).to eq blob_to_delete.data + expect(blob_in_mutation_response(deleted_file)['plainData']).not_to be_nil + expect(mutation_response['snippet']['title']).to eq(original_title) + expect(mutation_response['snippet']['description']).to eq(original_description) + expect(mutation_response['snippet']['visibilityLevel']).to eq('private') + end end end + + def blob_in_mutation_response(filename) + mutation_response['snippet']['blobs'].select { |blob| blob['name'] == filename }[0] + end + + def blob_at(filename) + snippet.repository.blob_at('HEAD', filename) + end end end @@ -96,6 +122,7 @@ RSpec.describe 'Updating a Snippet' do let(:snippet) do create(:personal_snippet, :private, + :repository, file_name: original_file_name, title: original_title, content: original_content, @@ -104,6 +131,7 @@ RSpec.describe 'Updating a Snippet' do it_behaves_like 'graphql update actions' it_behaves_like 'when the snippet is not found' + it_behaves_like 'snippet edit usage data counters' end describe 'ProjectSnippet' do @@ -111,6 +139,7 @@ RSpec.describe 'Updating a Snippet' do let(:snippet) do create(:project_snippet, :private, + :repository, project: project, author: create(:user), file_name: original_file_name, @@ -145,44 +174,10 @@ RSpec.describe 'Updating a Snippet' do expect(errors.first['message']).to eq(Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) end end - end - - it_behaves_like 'when the snippet is not found' - end - - context 'when using the files params' do - let!(:snippet) { create(:personal_snippet, :private, :repository) } - let(:updated_content) { 'updated_content' } - let(:updated_file) { 'CHANGELOG' } - let(:deleted_file) { 'README' } - let(:mutation_vars) do - { - id: snippet_gid, - blob_actions: [ - { action: :update, filePath: updated_file, content: updated_content }, - { action: :delete, filePath: deleted_file } - ] - } - end - it 'updates the Snippet' do - blob_to_update = blob_at(updated_file) - expect(blob_to_update.data).not_to eq updated_content - - blob_to_delete = blob_at(deleted_file) - expect(blob_to_delete).to be_present - - post_graphql_mutation(mutation, current_user: current_user) - - blob_to_update = blob_at(updated_file) - expect(blob_to_update.data).to eq updated_content - - blob_to_delete = blob_at(deleted_file) - expect(blob_to_delete).to be_nil + it_behaves_like 'snippet edit usage data counters' end - def blob_at(filename) - snippet.repository.blob_at('HEAD', filename) - end + it_behaves_like 'when the snippet is not found' end end |