diff options
Diffstat (limited to 'spec/support/shared_examples/requests')
6 files changed, 168 insertions, 32 deletions
diff --git a/spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb b/spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb index 0f277c11913..3e058838773 100644 --- a/spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb @@ -54,6 +54,29 @@ RSpec.shared_examples 'returns repositories for allowed users' do |user_type, sc expect(response).to match_response_schema('registry/repositories') end end + + context 'with tags_count param' do + let(:url) { "/#{scope}s/#{object.id}/registry/repositories?tags_count=true" } + + before do + stub_container_registry_tags(repository: root_repository.path, tags: %w(rootA latest), with_manifest: true) + stub_container_registry_tags(repository: test_repository.path, tags: %w(rootA latest), with_manifest: true) + end + + it 'returns a list of repositories and their tags_count' do + subject + + expect(response.body).to include('tags_count') + expect(json_response[0]['tags_count']).to eq(2) + end + + it 'returns a matching schema' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('registry/repositories') + end + end end end diff --git a/spec/support/shared_examples/requests/api/diff_discussions_shared_examples.rb b/spec/support/shared_examples/requests/api/diff_discussions_shared_examples.rb index 3d25b9076ad..518c5b8dc28 100644 --- a/spec/support/shared_examples/requests/api/diff_discussions_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/diff_discussions_shared_examples.rb @@ -30,7 +30,9 @@ RSpec.shared_examples 'diff discussions API' do |parent_type, noteable_type, id_ it "creates a new diff note" do line_range = { "start_line_code" => Gitlab::Git.diff_line_code(diff_note.position.file_path, 1, 1), - "end_line_code" => Gitlab::Git.diff_line_code(diff_note.position.file_path, 2, 2) + "end_line_code" => Gitlab::Git.diff_line_code(diff_note.position.file_path, 2, 2), + "start_line_type" => diff_note.position.type, + "end_line_type" => diff_note.position.type } position = diff_note.position.to_h.merge({ line_range: line_range }) diff --git a/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb index feb3ba46353..f26af6cb766 100644 --- a/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb @@ -45,44 +45,37 @@ RSpec.shared_examples 'group and project boards query' do end describe 'sorting and pagination' do + let(:data_path) { [board_parent_type, :boards] } + + def pagination_query(params, page_info) + graphql_query_for( + board_parent_type, + { 'fullPath' => board_parent.full_path }, + query_graphql_field('boards', params, "#{page_info} edges { node { id } }") + ) + end + + def pagination_results_data(data) + data.map { |board| board.dig('node', 'id') } + end + context 'when using default sorting' do let!(:board_B) { create(:board, resource_parent: board_parent, name: 'B') } let!(:board_C) { create(:board, resource_parent: board_parent, name: 'C') } let!(:board_a) { create(:board, resource_parent: board_parent, name: 'a') } let!(:board_A) { create(:board, resource_parent: board_parent, name: 'A') } - - before do - post_graphql(query, current_user: current_user) - end - - it_behaves_like 'a working graphql query' + let(:boards) { [board_a, board_A, board_B, board_C] } context 'when ascending' do - let(:boards) { [board_a, board_A, board_B, board_C] } - let(:expected_boards) do - if board_parent.multiple_issue_boards_available? - boards - else - [boards.first] - end - end - - it 'sorts boards' do - expect(grab_names).to eq expected_boards.map(&:name) - end - - context 'when paginating' do - let(:params) { 'first: 2' } - - it 'sorts boards' do - expect(grab_names).to eq expected_boards.first(2).map(&:name) - - cursored_query = query("after: \"#{end_cursor}\"") - post_graphql(cursored_query, current_user: current_user) - - response_data = Gitlab::Json.parse(response.body)['data'][board_parent_type]['boards']['edges'] - - expect(grab_names(response_data)).to eq expected_boards.drop(2).first(2).map(&:name) + it_behaves_like 'sorted paginated query' do + let(:sort_param) { } + let(:first_param) { 2 } + let(:expected_results) do + if board_parent.multiple_issue_boards_available? + boards.map { |board| board.to_global_id.to_s } + else + [boards.first.to_global_id.to_s] + end end end end diff --git a/spec/support/shared_examples/requests/api/issuable_update_shared_examples.rb b/spec/support/shared_examples/requests/api/issuable_update_shared_examples.rb new file mode 100644 index 00000000000..ded381fd402 --- /dev/null +++ b/spec/support/shared_examples/requests/api/issuable_update_shared_examples.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'issuable update endpoint' do + let(:area) { entity.class.name.underscore.pluralize } + + describe 'PUT /projects/:id/issues/:issue_id' do + let(:url) { "/projects/#{project.id}/#{area}/#{entity.iid}" } + + it 'clears labels when labels param is nil' do + put api(url, user), params: { labels: 'label1' } + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['labels']).to contain_exactly('label1') + + put api(url, user), params: { labels: nil } + + expect(response).to have_gitlab_http_status(:ok) + json_response = Gitlab::Json.parse(response.body) + expect(json_response['labels']).to be_empty + end + + it 'updates the issuable with labels param as array' do + stub_const("Gitlab::QueryLimiting::Transaction::THRESHOLD", 110) + + params = { labels: ['label1', 'label2', 'foo, bar', '&,?'] } + + put api(url, user), params: params + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['labels']).to include 'label1' + expect(json_response['labels']).to include 'label2' + expect(json_response['labels']).to include 'foo' + expect(json_response['labels']).to include 'bar' + expect(json_response['labels']).to include '&' + expect(json_response['labels']).to include '?' + end + end +end diff --git a/spec/support/shared_examples/requests/api/resource_label_events_api_shared_examples.rb b/spec/support/shared_examples/requests/api/resource_label_events_api_shared_examples.rb index f49f944f38d..675b6c5cef6 100644 --- a/spec/support/shared_examples/requests/api/resource_label_events_api_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/resource_label_events_api_shared_examples.rb @@ -93,6 +93,20 @@ RSpec.shared_examples 'resource_label_events API' do |parent_type, eventable_typ end end + describe 'pagination' do + let!(:event1) { create_event(label) } + let!(:event2) { create_event(label) } + + # https://gitlab.com/gitlab-org/gitlab/-/issues/220192 + it "returns the second page" do + get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events?page=2&per_page=1", user) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.count).to eq(1) + expect(json_response.first['id']).to eq(event2.id) + end + end + def create_event(label) create(:resource_label_event, eventable.class.name.underscore => eventable, label: label) end diff --git a/spec/support/shared_examples/requests/api/resource_milestone_events_api_shared_examples.rb b/spec/support/shared_examples/requests/api/resource_milestone_events_api_shared_examples.rb new file mode 100644 index 00000000000..bca51dab353 --- /dev/null +++ b/spec/support/shared_examples/requests/api/resource_milestone_events_api_shared_examples.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'resource_milestone_events API' do |parent_type, eventable_type, id_name| + describe "GET /#{parent_type}/:id/#{eventable_type}/:noteable_id/resource_milestone_events" do + let!(:event) { create_event(milestone) } + + it "returns an array of resource milestone events" do + url = "/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_milestone_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['milestone']['id']).to eq(event.milestone.id) + expect(json_response.first['action']).to eq(event.action) + 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_milestone_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("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_milestone_events", private_user) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + describe "GET /#{parent_type}/:id/#{eventable_type}/:noteable_id/resource_milestone_events/:event_id" do + let!(:event) { create_event(milestone) } + + it "returns a resource milestone event by id" do + get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_milestone_events/#{event.id}", user) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['id']).to eq(event.id) + expect(json_response['milestone']['id']).to eq(event.milestone.id) + expect(json_response['action']).to eq(event.action) + end + + it "returns 404 when not authorized" do + parent.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) + private_user = create(:user) + + get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_milestone_events/#{event.id}", private_user) + + expect(response).to have_gitlab_http_status(:not_found) + end + + it "returns a 404 error if resource milestone event not found" do + get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_milestone_events/#{non_existing_record_id}", user) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + def create_event(milestone, action: :add) + create(:resource_milestone_event, eventable.class.name.underscore => eventable, milestone: milestone, action: action) + end +end |