diff options
Diffstat (limited to 'spec/support/shared_examples/requests/api/graphql')
5 files changed, 111 insertions, 26 deletions
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 da9d254039b..e534a02e562 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 @@ -67,11 +67,15 @@ RSpec.shared_examples 'group and project boards query' do let(:sort_param) { } let(:first_param) { 2 } + def pagination_results_data(nodes) + nodes + end + let(:all_records) do if board_parent.multiple_issue_boards_available? - boards.map { |board| global_id_of(board) } + boards.map { |board| a_graphql_entity_for(board) } else - [global_id_of(boards.first)] + [a_graphql_entity_for(boards.first)] end end end diff --git a/spec/support/shared_examples/requests/api/graphql/noteable_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/noteable_shared_examples.rb index 7e1f4500779..9033a8b4d3a 100644 --- a/spec/support/shared_examples/requests/api/graphql/noteable_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/graphql/noteable_shared_examples.rb @@ -12,9 +12,9 @@ RSpec.shared_examples 'a noteable graphql type we can query' do def expected noteable.discussions.map do |discussion| - include( - 'id' => global_id_of(discussion), - 'replyId' => global_id_of(discussion, id: discussion.reply_id), + a_graphql_entity_for( + discussion, + 'replyId' => global_id_of(discussion, id: discussion.reply_id).to_s, 'createdAt' => discussion.created_at.iso8601, 'notes' => include( 'nodes' => have_attributes(size: discussion.notes.size) @@ -50,8 +50,8 @@ RSpec.shared_examples 'a noteable graphql type we can query' do post_graphql(query(fields), current_user: current_user) - data = graphql_data_at(*path_to_noteable, :discussions, :nodes, :noteable, :id) - expect(data[0]).to eq(global_id_of(noteable)) + entities = graphql_data_at(*path_to_noteable, :discussions, :nodes, :noteable) + expect(entities).to all(match(a_graphql_entity_for(noteable))) end end @@ -62,10 +62,10 @@ RSpec.shared_examples 'a noteable graphql type we can query' do def expected noteable.notes.map do |note| - include( - 'id' => global_id_of(note), - 'project' => include('id' => global_id_of(project)), - 'author' => include('id' => global_id_of(note.author)), + a_graphql_entity_for( + note, + 'project' => a_graphql_entity_for(project), + 'author' => a_graphql_entity_for(note.author), 'createdAt' => note.created_at.iso8601, 'body' => eq(note.note) ) 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 127b1a6d4c4..9f7ec6e90e9 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 @@ -104,7 +104,7 @@ RSpec.shared_examples 'group and project packages query' do } end - let(:expected_packages) { sorted_packages.map { |package| global_id_of(package) } } + let(:expected_packages) { sorted_packages.map { |package| global_id_of(package).to_s } } let(:data_path) { [resource_type, :packages] } @@ -191,4 +191,91 @@ RSpec.shared_examples 'group and project packages query' do it { is_expected.to include({ "name" => versionless_package.name }) } end end + + context 'when reading pipelines' do + let(:npm_pipelines) { create_list(:ci_pipeline, 6, project: project1) } + let(:npm_pipeline_gids) { npm_pipelines.sort_by(&:id).map(&:to_gid).map(&:to_s).reverse } + let(:composer_pipelines) { create_list(:ci_pipeline, 6, project: project2) } + let(:composer_pipeline_gids) { composer_pipelines.sort_by(&:id).map(&:to_gid).map(&:to_s).reverse } + let(:npm_end_cursor) { graphql_data_npm_package.dig('pipelines', 'pageInfo', 'endCursor') } + let(:npm_start_cursor) { graphql_data_npm_package.dig('pipelines', 'pageInfo', 'startCursor') } + let(:pipelines_nodes) do + <<~QUERY + nodes { + id + } + pageInfo { + startCursor + endCursor + } + QUERY + end + + before do + resource.add_maintainer(current_user) + + npm_pipelines.each do |pipeline| + create(:package_build_info, package: npm_package, pipeline: pipeline) + end + + composer_pipelines.each do |pipeline| + create(:package_build_info, package: composer_package, pipeline: pipeline) + end + end + + it 'loads the second page with pagination first correctly' do + run_query(first: 2) + expect(npm_pipeline_ids).to eq(npm_pipeline_gids[0..1]) + expect(composer_pipeline_ids).to eq(composer_pipeline_gids[0..1]) + + run_query(first: 2, after: npm_end_cursor) + expect(npm_pipeline_ids).to eq(npm_pipeline_gids[2..3]) + expect(composer_pipeline_ids).to be_empty + end + + it 'loads the second page with pagination last correctly' do + run_query(last: 2) + expect(npm_pipeline_ids).to eq(npm_pipeline_gids[4..5]) + expect(composer_pipeline_ids).to eq(composer_pipeline_gids[4..5]) + + run_query(last: 2, before: npm_start_cursor) + expect(npm_pipeline_ids).to eq(npm_pipeline_gids[2..3]) + expect(composer_pipeline_ids).to eq(composer_pipeline_gids[4..5]) + end + + def run_query(args) + pipelines_field = query_graphql_field('pipelines', args, pipelines_nodes) + + packages_nodes = <<~QUERY + nodes { + id + #{pipelines_field} + } + QUERY + + query = graphql_query_for( + resource_type, + { 'fullPath' => resource.full_path }, + query_graphql_field('packages', {}, packages_nodes) + ) + + post_graphql(query, current_user: current_user) + end + + def npm_pipeline_ids + graphql_data_npm_package.dig('pipelines', 'nodes').map { |pipeline| pipeline['id'] } + end + + def composer_pipeline_ids + graphql_data_composer_package.dig('pipelines', 'nodes').map { |pipeline| pipeline['id'] } + end + + def graphql_data_npm_package + graphql_data_at(resource_type, :packages, :nodes).find { |pkg| pkg['id'] == npm_package.to_gid.to_s } + end + + def graphql_data_composer_package + graphql_data_at(resource_type, :packages, :nodes).find { |pkg| pkg['id'] == composer_package.to_gid.to_s } + end + end end diff --git a/spec/support/shared_examples/requests/api/graphql/packages/package_details_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/packages/package_details_shared_examples.rb index ab93f54111b..b4019d7c232 100644 --- a/spec/support/shared_examples/requests/api/graphql/packages/package_details_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/graphql/packages/package_details_shared_examples.rb @@ -28,14 +28,10 @@ RSpec.shared_examples 'a package with files' do end it 'has the basic package files data' do - expect(first_file_response).to include( - 'id' => global_id_of(first_file), - 'fileName' => first_file.file_name, - 'size' => first_file.size.to_s, - 'downloadPath' => first_file.download_path, - 'fileSha1' => first_file.file_sha1, - 'fileMd5' => first_file.file_md5, - 'fileSha256' => first_file.file_sha256 + expect(first_file_response).to match a_graphql_entity_for( + first_file, + :file_name, :download_path, :file_sha1, :file_md5, :file_sha256, + 'size' => first_file.size.to_s ) end diff --git a/spec/support/shared_examples/requests/api/graphql/projects/alert_management/integrations_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/projects/alert_management/integrations_shared_examples.rb index c134f7d1839..3c5f25baaa1 100644 --- a/spec/support/shared_examples/requests/api/graphql/projects/alert_management/integrations_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/graphql/projects/alert_management/integrations_shared_examples.rb @@ -30,14 +30,12 @@ RSpec.shared_examples 'GraphQL query with several integrations requested' do |gr it 'returns the correct properties of the integrations', :aggregate_failures do post_graphql(multi_selection_query, current_user: current_user) - expect(graphql_data.dig('project', 'ai', 'nodes')).to include( - 'id' => global_id_of(active_http_integration), - 'name' => active_http_integration.name + expect(graphql_data.dig('project', 'ai', 'nodes')).to match a_graphql_entity_for( + active_http_integration, :name ) - expect(graphql_data.dig('project', 'ii', 'nodes')).to include( - 'id' => global_id_of(inactive_http_integration), - 'name' => inactive_http_integration.name + expect(graphql_data.dig('project', 'ii', 'nodes')).to match a_graphql_entity_for( + inactive_http_integration, :name ) end |