diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/requests/api/graphql/mutations/snippets/create_spec.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/requests/api/graphql/mutations/snippets/create_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/mutations/snippets/create_spec.rb | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/spec/requests/api/graphql/mutations/snippets/create_spec.rb b/spec/requests/api/graphql/mutations/snippets/create_spec.rb index cef7fc5cbe3..e1e5fe22887 100644 --- a/spec/requests/api/graphql/mutations/snippets/create_spec.rb +++ b/spec/requests/api/graphql/mutations/snippets/create_spec.rb @@ -13,6 +13,7 @@ describe 'Creating a Snippet' do let(:file_name) { 'Initial file_name' } let(:visibility_level) { 'public' } let(:project_path) { nil } + let(:uploaded_files) { nil } let(:mutation) do variables = { @@ -21,7 +22,8 @@ describe 'Creating a Snippet' do visibility_level: visibility_level, file_name: file_name, title: title, - project_path: project_path + project_path: project_path, + uploaded_files: uploaded_files } graphql_mutation(:create_snippet, variables) @@ -31,6 +33,8 @@ describe 'Creating a Snippet' do graphql_mutation_response(:create_snippet) end + subject { post_graphql_mutation(mutation, current_user: current_user) } + context 'when the user does not have permission' do let(:current_user) { nil } @@ -39,7 +43,7 @@ describe 'Creating a Snippet' do it 'does not create the Snippet' do expect do - post_graphql_mutation(mutation, current_user: current_user) + subject end.not_to change { Snippet.count } end @@ -48,7 +52,7 @@ describe 'Creating a Snippet' do it 'does not create the snippet when the user is not authorized' do expect do - post_graphql_mutation(mutation, current_user: current_user) + subject end.not_to change { Snippet.count } end end @@ -60,12 +64,12 @@ describe 'Creating a Snippet' do context 'with PersonalSnippet' do it 'creates the Snippet' do expect do - post_graphql_mutation(mutation, current_user: current_user) + subject end.to change { Snippet.count }.by(1) end it 'returns the created Snippet' do - post_graphql_mutation(mutation, current_user: current_user) + subject expect(mutation_response['snippet']['blob']['richData']).to be_nil expect(mutation_response['snippet']['blob']['plainData']).to match(content) @@ -86,12 +90,12 @@ describe 'Creating a Snippet' do it 'creates the Snippet' do expect do - post_graphql_mutation(mutation, current_user: current_user) + subject end.to change { Snippet.count }.by(1) end it 'returns the created Snippet' do - post_graphql_mutation(mutation, current_user: current_user) + subject expect(mutation_response['snippet']['blob']['richData']).to be_nil expect(mutation_response['snippet']['blob']['plainData']).to match(content) @@ -106,7 +110,7 @@ describe 'Creating a Snippet' do let(:project_path) { 'foobar' } it 'returns an an error' do - post_graphql_mutation(mutation, current_user: current_user) + subject errors = json_response['errors'] expect(errors.first['message']).to eq(Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) @@ -117,7 +121,7 @@ describe 'Creating a Snippet' do it 'returns an an error' do project.project_feature.update_attribute(:snippets_access_level, ProjectFeature::DISABLED) - post_graphql_mutation(mutation, current_user: current_user) + subject errors = json_response['errors'] expect(errors.first['message']).to eq(Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) @@ -132,15 +136,41 @@ describe 'Creating a Snippet' do it 'does not create the Snippet' do expect do - post_graphql_mutation(mutation, current_user: current_user) + subject end.not_to change { Snippet.count } end it 'does not return Snippet' do - post_graphql_mutation(mutation, current_user: current_user) + subject expect(mutation_response['snippet']).to be_nil end end + + context 'when there uploaded files' do + shared_examples 'expected files argument' do |file_value, expected_value| + let(:uploaded_files) { file_value } + + it do + expect(::Snippets::CreateService).to receive(:new).with(nil, user, hash_including(files: expected_value)) + + subject + end + end + + it_behaves_like 'expected files argument', nil, nil + it_behaves_like 'expected files argument', %w(foo bar), %w(foo bar) + it_behaves_like 'expected files argument', 'foo', %w(foo) + + context 'when files has an invalid value' do + let(:uploaded_files) { [1] } + + it 'returns an error' do + subject + + expect(json_response['errors']).to be + end + end + end end end |