diff options
Diffstat (limited to 'spec/support/shared_examples/requests/api')
14 files changed, 131 insertions, 17 deletions
diff --git a/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb index dc2c4f890b1..6a77de4266f 100644 --- a/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb @@ -108,6 +108,7 @@ RSpec.shared_examples 'process Composer api request' do |user_type, status, add_ end it_behaves_like 'returning response status', status + it_behaves_like 'bumping the package last downloaded at field' if status == :success end end diff --git a/spec/support/shared_examples/requests/api/conan_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/conan_packages_shared_examples.rb index bb2f8965294..629d93676eb 100644 --- a/spec/support/shared_examples/requests/api/conan_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/conan_packages_shared_examples.rb @@ -355,7 +355,7 @@ RSpec.shared_examples 'recipe download_urls' do it 'returns the download_urls for the recipe files' do expected_response = { - 'conanfile.py' => "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanfile.py", + 'conanfile.py' => "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanfile.py", 'conanmanifest.txt' => "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanmanifest.txt" } @@ -372,7 +372,7 @@ RSpec.shared_examples 'package download_urls' do it 'returns the download_urls for the package files' do expected_response = { - 'conaninfo.txt' => "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/123456789/0/conaninfo.txt", + 'conaninfo.txt' => "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/123456789/0/conaninfo.txt", 'conanmanifest.txt' => "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/123456789/0/conanmanifest.txt", 'conan_package.tgz' => "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/123456789/0/conan_package.tgz" } @@ -412,7 +412,7 @@ RSpec.shared_examples 'recipe snapshot endpoint' do conan_manifest_file = package.package_files.find_by(file_name: 'conanmanifest.txt') expected_response = { - 'conanfile.py' => conan_file_file.file_md5, + 'conanfile.py' => conan_file_file.file_md5, 'conanmanifest.txt' => conan_manifest_file.file_md5 } @@ -435,7 +435,7 @@ RSpec.shared_examples 'package snapshot endpoint' do context 'with existing package' do it 'returns a hash of md5 values for the files' do expected_response = { - 'conaninfo.txt' => "12345abcde", + 'conaninfo.txt' => "12345abcde", 'conanmanifest.txt' => "12345abcde", 'conan_package.tgz' => "12345abcde" } @@ -486,7 +486,7 @@ RSpec.shared_examples 'recipe upload_urls endpoint' do subject expected_response = { - 'conanfile.py': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanfile.py", + 'conanfile.py': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanfile.py", 'conanmanifest.txt': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanmanifest.txt" } @@ -505,7 +505,7 @@ RSpec.shared_examples 'recipe upload_urls endpoint' do expected_response = { 'conan_sources.tgz': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conan_sources.tgz", - 'conan_export.tgz': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conan_export.tgz", + 'conan_export.tgz': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conan_export.tgz", 'conanmanifest.txt': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanmanifest.txt" } @@ -547,7 +547,7 @@ RSpec.shared_examples 'package upload_urls endpoint' do it 'returns a set of upload urls for the files requested' do expected_response = { - 'conaninfo.txt': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/123456789/0/conaninfo.txt", + 'conaninfo.txt': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/123456789/0/conaninfo.txt", 'conanmanifest.txt': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/123456789/0/conanmanifest.txt", 'conan_package.tgz': "#{url_prefix}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/123456789/0/conan_package.tgz" } @@ -631,6 +631,7 @@ RSpec.shared_examples 'a public project with packages' do end it_behaves_like 'allows download with no token' + it_behaves_like 'bumping the package last downloaded at field' it 'returns the file' do subject @@ -647,6 +648,7 @@ RSpec.shared_examples 'an internal project with packages' do end it_behaves_like 'denies download with no token' + it_behaves_like 'bumping the package last downloaded at field' it 'returns the file' do subject @@ -662,6 +664,7 @@ RSpec.shared_examples 'a private project with packages' do end it_behaves_like 'denies download with no token' + it_behaves_like 'bumping the package last downloaded at field' it 'returns the file' do subject diff --git a/spec/support/shared_examples/requests/api/graphql/issuable_search_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/issuable_search_shared_examples.rb new file mode 100644 index 00000000000..22805cf7aed --- /dev/null +++ b/spec/support/shared_examples/requests/api/graphql/issuable_search_shared_examples.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Requires `query(params)` , `user`, `issuable_data` and `issuable` bindings +RSpec.shared_examples 'query with a search term' do + it 'returns only matching issuables' do + filter_params = { search: 'bar', in: [:DESCRIPTION] } + graphql_query = query(filter_params) + + post_graphql(graphql_query, current_user: user) + ids = graphql_dig_at(issuable_data, :node, :id) + + expect(ids).to contain_exactly(issuable.to_global_id.to_s) + end +end diff --git a/spec/support/shared_examples/requests/api/graphql/packages/group_and_project_packages_list_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/packages/group_and_project_packages_list_shared_examples.rb index 9f7ec6e90e9..1b609915f32 100644 --- a/spec/support/shared_examples/requests/api/graphql/packages/group_and_project_packages_list_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/graphql/packages/group_and_project_packages_list_shared_examples.rb @@ -9,9 +9,10 @@ RSpec.shared_examples 'group and project packages query' do let_it_be(:composer_package) { create(:composer_package, project: project2, name: 'dab', version: '4.0.0', created_at: 3.days.ago) } let_it_be(:debian_package) { create(:debian_package, project: project2, name: 'aab', version: '5.0.0', created_at: 2.days.ago) } let_it_be(:composer_metadatum) do - create(:composer_metadatum, package: composer_package, - target_sha: 'afdeh', - composer_json: { name: 'x', type: 'y', license: 'z', version: 1 }) + create(:composer_metadatum, + package: composer_package, + target_sha: 'afdeh', + composer_json: { name: 'x', type: 'y', license: 'z', version: 1 }) end let(:package_names) { graphql_data_at(resource_type, :packages, :nodes, :name) } diff --git a/spec/support/shared_examples/requests/api/helm_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/helm_packages_shared_examples.rb index acbcf4f7f3d..06ed0448b50 100644 --- a/spec/support/shared_examples/requests/api/helm_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/helm_packages_shared_examples.rb @@ -191,14 +191,15 @@ RSpec.shared_examples 'process helm download content request' do |user_type, sta end end - it_behaves_like 'a package tracking event', 'API::HelmPackages', 'pull_package' - it 'returns expected status and a valid package archive' do subject expect(response).to have_gitlab_http_status(status) expect(response.media_type).to eq('application/octet-stream') end + + it_behaves_like 'a package tracking event', 'API::HelmPackages', 'pull_package' + it_behaves_like 'bumping the package last downloaded at field' end end @@ -278,7 +279,6 @@ RSpec.shared_examples 'handling helm chart index requests' do end it_behaves_like 'deploy token for package GET requests' - it_behaves_like 'rejects helm access with unknown project id' do subject { get api(url) } end diff --git a/spec/support/shared_examples/requests/api/issues/merge_requests_count_shared_examples.rb b/spec/support/shared_examples/requests/api/issues/merge_requests_count_shared_examples.rb index 971b21b5b32..8c4ff120471 100644 --- a/spec/support/shared_examples/requests/api/issues/merge_requests_count_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/issues/merge_requests_count_shared_examples.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true def get_issue - json_response.is_a?(Array) ? json_response.detect {|issue| issue['id'] == target_issue.id} : json_response + json_response.is_a?(Array) ? json_response.detect { |issue| issue['id'] == target_issue.id } : json_response end RSpec.shared_examples 'accessible merge requests count' do diff --git a/spec/support/shared_examples/requests/api/labels_api_shared_examples.rb b/spec/support/shared_examples/requests/api/labels_api_shared_examples.rb index 02e50b789cc..41d21490343 100644 --- a/spec/support/shared_examples/requests/api/labels_api_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/labels_api_shared_examples.rb @@ -9,6 +9,6 @@ RSpec.shared_examples 'fetches labels' do expect(json_response).to be_an Array expect(json_response).to all(match_schema('public_api/v4/labels/label')) expect(json_response.size).to eq(expected_labels.size) - expect(json_response.map {|r| r['name'] }).to match_array(expected_labels) + expect(json_response.map { |r| r['name'] }).to match_array(expected_labels) end end diff --git a/spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb index 6568d51b90e..fdd55893deb 100644 --- a/spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb @@ -293,6 +293,8 @@ RSpec.shared_examples 'process nuget download content request' do |user_type, st it_behaves_like 'a package tracking event', 'API::NugetPackages', 'pull_package' + it_behaves_like 'bumping the package last downloaded at field' + it 'returns a valid package archive' do subject @@ -315,6 +317,8 @@ RSpec.shared_examples 'process nuget download content request' do |user_type, st end it_behaves_like 'a package tracking event', 'API::NugetPackages', 'pull_symbol_package' + + it_behaves_like 'bumping the package last downloaded at field' end context 'with lower case package name' do diff --git a/spec/support/shared_examples/requests/api/packages_shared_examples.rb b/spec/support/shared_examples/requests/api/packages_shared_examples.rb index eb650b7a09f..860cb1b1d86 100644 --- a/spec/support/shared_examples/requests/api/packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/packages_shared_examples.rb @@ -165,3 +165,10 @@ RSpec.shared_examples 'not a package tracking event' do expect_no_snowplow_event end end + +RSpec.shared_examples 'bumping the package last downloaded at field' do + it 'bumps last_downloaded_at' do + expect { subject } + .to change { package.reload.last_downloaded_at }.from(nil).to(instance_of(ActiveSupport::TimeWithZone)) + end +end diff --git a/spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb index ba8311bf0be..f411b5699a9 100644 --- a/spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb @@ -167,6 +167,7 @@ RSpec.shared_examples 'PyPI package download' do |user_type, status, add_member it_behaves_like 'returning response status', status it_behaves_like 'a package tracking event', described_class.name, 'pull_package' + it_behaves_like 'bumping the package last downloaded at field' end end diff --git a/spec/support/shared_examples/requests/api/repository_storage_moves_shared_examples.rb b/spec/support/shared_examples/requests/api/repository_storage_moves_shared_examples.rb index 3ca2b9fa6de..2d036cb2aa3 100644 --- a/spec/support/shared_examples/requests/api/repository_storage_moves_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/repository_storage_moves_shared_examples.rb @@ -70,7 +70,7 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type| get_container_repository_storage_moves - json_ids = json_response.map {|storage_move| storage_move['id'] } + json_ids = json_response.map { |storage_move| storage_move['id'] } expect(json_ids).to eq([ storage_move.id, storage_move_middle.id, diff --git a/spec/support/shared_examples/requests/api/resource_state_events_api_shared_examples.rb b/spec/support/shared_examples/requests/api/resource_state_events_api_shared_examples.rb new file mode 100644 index 00000000000..c1850a0d0c9 --- /dev/null +++ b/spec/support/shared_examples/requests/api/resource_state_events_api_shared_examples.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'resource_state_events API' do |parent_type, eventable_type, id_name| + let(:base_path) { "/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}" } + + describe "GET /#{parent_type}/:id/#{eventable_type}/:noteable_id/resource_state_events" do + let!(:event) { create_event } + + it "returns an array of resource state events" do + url = "#{base_path}/resource_state_events" + get api(url, user) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.first['id']).to eq(event.id) + expect(json_response.first['state']).to eq(event.state.to_s) + end + + it "returns a 404 error when eventable id not found" do + get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{non_existing_record_id}/resource_state_events", user) + + expect(response).to have_gitlab_http_status(:not_found) + end + + it "returns 404 when not authorized" do + parent.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) + private_user = create(:user) + + get api("#{base_path}/resource_state_events", private_user) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + describe "GET /#{parent_type}/:id/#{eventable_type}/:noteable_id/resource_state_events/:event_id" do + let!(:event) { create_event } + + it "returns a resource state event by id" do + get api("#{base_path}/resource_state_events/#{event.id}", user) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['id']).to eq(event.id) + expect(json_response['state']).to eq(event.state.to_s) + end + + it "returns 404 when not authorized" do + parent.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) + private_user = create(:user) + + get api("#{base_path}/resource_state_events/#{event.id}", private_user) + + expect(response).to have_gitlab_http_status(:not_found) + end + + it "returns a 404 error if resource state event not found" do + get api("#{base_path}/resource_state_events/#{non_existing_record_id}", user) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + describe 'pagination' do + # https://gitlab.com/gitlab-org/gitlab/-/issues/220192 + it 'returns the second page' do + create_event + event2 = create_event + + get api("#{base_path}/resource_state_events?page=2&per_page=1", user) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(response.headers['X-Total']).to eq '2' + expect(json_response.count).to eq(1) + expect(json_response.first['id']).to eq(event2.id) + end + end + + def create_event(state: :opened) + create(:resource_state_event, eventable.class.name.underscore => eventable, state: state) + end +end diff --git a/spec/support/shared_examples/requests/api/rubygems_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/rubygems_packages_shared_examples.rb index abdb468353a..f075927e7bf 100644 --- a/spec/support/shared_examples/requests/api/rubygems_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/rubygems_packages_shared_examples.rb @@ -203,5 +203,6 @@ RSpec.shared_examples 'Rubygems gem download' do |user_type, status, add_member end it_behaves_like 'a package tracking event', described_class.name, 'pull_package' + it_behaves_like 'bumping the package last downloaded at field' end end diff --git a/spec/support/shared_examples/requests/api/snippets_shared_examples.rb b/spec/support/shared_examples/requests/api/snippets_shared_examples.rb index 2b72c69cb37..1b92eb56f54 100644 --- a/spec/support/shared_examples/requests/api/snippets_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/snippets_shared_examples.rb @@ -133,7 +133,7 @@ RSpec.shared_examples 'snippet file updates' do context 'when save fails due to a repository commit error' do before do allow_next_instance_of(Repository) do |instance| - allow(instance).to receive(:multi_action).and_raise(Gitlab::Git::CommitError) + allow(instance).to receive(:commit_files).and_raise(Gitlab::Git::CommitError) end update_snippet(params: { files: [create_action] }) |