diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/graphql/types | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) | |
download | gitlab-ce-a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4.tar.gz |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/graphql/types')
-rw-r--r-- | spec/graphql/types/ci/runner_type_spec.rb | 6 | ||||
-rw-r--r-- | spec/graphql/types/global_id_type_spec.rb | 146 | ||||
-rw-r--r-- | spec/graphql/types/label_type_spec.rb | 1 | ||||
-rw-r--r-- | spec/graphql/types/merge_request_type_spec.rb | 33 | ||||
-rw-r--r-- | spec/graphql/types/mutation_type_spec.rb | 22 | ||||
-rw-r--r-- | spec/graphql/types/packages/package_group_sort_enum_spec.rb | 9 | ||||
-rw-r--r-- | spec/graphql/types/packages/package_sort_enum_spec.rb | 9 | ||||
-rw-r--r-- | spec/graphql/types/packages/pypi/metadatum_type_spec.rb | 13 | ||||
-rw-r--r-- | spec/graphql/types/projects/service_type_spec.rb | 4 | ||||
-rw-r--r-- | spec/graphql/types/projects/services_enum_spec.rb | 8 | ||||
-rw-r--r-- | spec/graphql/types/snippet_type_spec.rb | 28 | ||||
-rw-r--r-- | spec/graphql/types/snippets/blob_viewer_type_spec.rb | 22 | ||||
-rw-r--r-- | spec/graphql/types/timelog_type_spec.rb | 2 |
13 files changed, 231 insertions, 72 deletions
diff --git a/spec/graphql/types/ci/runner_type_spec.rb b/spec/graphql/types/ci/runner_type_spec.rb index dfe4a30c5b7..f27216f4d39 100644 --- a/spec/graphql/types/ci/runner_type_spec.rb +++ b/spec/graphql/types/ci/runner_type_spec.rb @@ -2,15 +2,17 @@ require 'spec_helper' -RSpec.describe Types::Ci::RunnerType do +RSpec.describe GitlabSchema.types['CiRunner'] do specify { expect(described_class.graphql_name).to eq('CiRunner') } + specify { expect(described_class).to require_graphql_authorizations(:read_runner) } + it 'contains attributes related to a runner' do expected_fields = %w[ id description contacted_at maximum_timeout access_level active status version short_sha revision locked run_untagged ip_address runner_type tag_list ] - expect(described_class).to have_graphql_fields(*expected_fields) + expect(described_class).to include_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/global_id_type_spec.rb b/spec/graphql/types/global_id_type_spec.rb index 4df51dc8d1b..37f59770817 100644 --- a/spec/graphql/types/global_id_type_spec.rb +++ b/spec/graphql/types/global_id_type_spec.rb @@ -3,6 +3,10 @@ require 'spec_helper' RSpec.describe Types::GlobalIDType do + include ::Gitlab::Graphql::Laziness + include GraphqlHelpers + include GlobalIDDeprecationHelpers + let_it_be(:project) { create(:project) } let(:gid) { project.to_global_id } @@ -97,6 +101,142 @@ RSpec.describe Types::GlobalIDType do expect { type.coerce_isolated_input(invalid_gid) } .to raise_error(GraphQL::CoercionError, /does not represent an instance of Project/) end + + context 'with a deprecation' do + around(:all) do |example| + # Unset all previously memoized GlobalIDTypes to allow us to define one + # that will use the constants stubbed in the `before` block. + previous_id_types = Types::GlobalIDType.instance_variable_get(:@id_types) + Types::GlobalIDType.instance_variable_set(:@id_types, {}) + + example.run + ensure + Types::GlobalIDType.instance_variable_set(:@id_types, previous_id_types) + end + + before do + deprecation = Gitlab::GlobalId::Deprecations::Deprecation.new(old_model_name: 'OldIssue', new_model_name: 'Issue', milestone: '10.0') + + stub_global_id_deprecations(deprecation) + end + + let_it_be(:issue) { create(:issue) } + + let!(:type) { ::Types::GlobalIDType[::Issue] } + let(:deprecated_gid) { Gitlab::GlobalId.build(model_name: 'OldIssue', id: issue.id) } + let(:deprecating_gid) { Gitlab::GlobalId.build(model_name: 'Issue', id: issue.id) } + + it 'appends the description with a deprecation notice for the old Global ID' do + expect(type.to_graphql.description).to include('The older format `"gid://gitlab/OldIssue/1"` was deprecated in 10.0') + end + + describe 'coercing input against the type (parsing the Global ID string when supplied as an argument)' do + subject(:result) { type.coerce_isolated_input(gid.to_s) } + + context 'when passed the deprecated Global ID' do + let(:gid) { deprecated_gid } + + it 'changes the model_name to the new model name' do + expect(result.model_name).to eq('Issue') + end + + it 'changes the model_class to the new model class' do + expect(result.model_class).to eq(Issue) + end + + it 'can find the correct resource' do + expect(result.find).to eq(issue) + end + + it 'can find the correct resource loaded through GitlabSchema' do + expect(force(GitlabSchema.object_from_id(result, expected_class: Issue))).to eq(issue) + end + end + + context 'when passed the Global ID that is deprecating another' do + let(:gid) { deprecating_gid } + + it 'works as normal' do + expect(result).to have_attributes( + model_class: Issue, + model_name: 'Issue', + find: issue, + to_s: gid.to_s + ) + end + end + end + + describe 'coercing the result against the type (producing the Global ID string when used in a field)' do + context 'when passed the deprecated Global ID' do + let(:gid) { deprecated_gid } + + it 'works, but does not result in matching the new Global ID', :aggregate_failures do + # Note, this would normally never happen in real life as the object being parsed + # by the field would not produce the GlobalID of the deprecated model. This test + # proves that it is technically possible for the deprecated GlobalID to be + # considered parsable for the type, as opposed to raising a `GraphQL::CoercionError`. + expect(type.coerce_isolated_result(gid)).not_to eq(issue.to_global_id.to_s) + expect(type.coerce_isolated_result(gid)).to eq(gid.to_s) + end + end + + context 'when passed the Global ID that is deprecating another' do + let(:gid) { deprecating_gid } + + it 'works as normal' do + expect(type.coerce_isolated_result(gid)).to eq(issue.to_global_id.to_s) + end + end + end + + describe 'executing against the schema' do + let(:query_result) do + context = { current_user: issue.project.owner } + variables = { 'id' => gid } + + run_with_clean_state(query, context: context, variables: variables).to_h + end + + shared_examples 'a query that works with old and new GIDs' do + let(:query) do + <<-GQL + query($id: #{argument_name}!) { + issue(id: $id) { + id + } + } + GQL + end + + subject { query_result.dig('data', 'issue', 'id') } + + context 'when the argument value is the new GID' do + let(:gid) { Gitlab::GlobalId.build(model_name: 'Issue', id: issue.id) } + + it { is_expected.to be_present } + end + + context 'when the argument value is the old GID' do + let(:gid) { Gitlab::GlobalId.build(model_name: 'OldIssue', id: issue.id) } + + it { is_expected.to be_present } + end + end + + context 'when the query signature includes the old type name' do + let(:argument_name) { 'OldIssueID' } + + it_behaves_like 'a query that works with old and new GIDs' + end + + context 'when the query signature includes the new type name' do + let(:argument_name) { 'IssueID' } + + it_behaves_like 'a query that works with old and new GIDs' + end + end + end end describe 'a parameterized type with a namespace' do @@ -231,4 +371,10 @@ RSpec.describe Types::GlobalIDType do end end end + + describe '.model_name_to_graphql_name' do + it 'returns a graphql name for the given model name' do + expect(described_class.model_name_to_graphql_name('DesignManagement::Design')).to eq('DesignManagementDesignID') + end + end end diff --git a/spec/graphql/types/label_type_spec.rb b/spec/graphql/types/label_type_spec.rb index 475b2a2ad34..427b5d2dcef 100644 --- a/spec/graphql/types/label_type_spec.rb +++ b/spec/graphql/types/label_type_spec.rb @@ -11,7 +11,6 @@ RSpec.describe GitlabSchema.types['Label'] do :color, :text_color, :created_at, - :remove_on_close, :updated_at ] diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index fa33b32c6c8..875a16a79e5 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['MergeRequest'] do + include GraphqlHelpers + specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::MergeRequest) } specify { expect(described_class).to require_graphql_authorizations(:read_merge_request) } @@ -19,15 +21,17 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do target_branch work_in_progress draft merge_when_pipeline_succeeds diff_head_sha merge_commit_sha user_notes_count user_discussions_count should_remove_source_branch diff_refs diff_stats diff_stats_summary - force_remove_source_branch merge_status in_progress_merge_commit_sha + force_remove_source_branch + merge_status merge_status_enum + in_progress_merge_commit_sha merge_error allow_collaboration should_be_rebased rebase_commit_sha rebase_in_progress default_merge_commit_message merge_ongoing mergeable_discussions_state web_url source_branch_exists target_branch_exists diverged_from_target_branch upvotes downvotes head_pipeline pipelines task_completion_status milestone assignees reviewers participants subscribed labels discussion_locked time_estimate - total_time_spent reference author merged_at commit_count current_user_todos - conflicts auto_merge_enabled approved_by source_branch_protected + total_time_spent human_time_estimate human_total_time_spent reference author merged_at + commit_count current_user_todos conflicts auto_merge_enabled approved_by source_branch_protected default_merge_commit_message_with_description squash_on_merge available_auto_merge_strategies has_ci mergeable commits_without_merge_commits squash security_auto_fix default_squash_commit_message auto_merge_strategy merge_user @@ -106,4 +110,27 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do execute_query end end + + describe 'merge_status_enum' do + let(:type) { GitlabSchema.types['MergeStatus'] } + + it 'has the type MergeStatus' do + expect(described_class.fields['mergeStatusEnum']).to have_graphql_type(type) + end + + let_it_be(:project) { create(:project, :public) } + + %i[preparing unchecked cannot_be_merged_recheck checking cannot_be_merged_rechecking can_be_merged cannot_be_merged].each do |state| + context "when the the DB value is #{state}" do + let(:merge_request) { create(:merge_request, :unique_branches, source_project: project, merge_status: state.to_s) } + + it 'serializes correctly' do + value = resolve_field(:merge_status_enum, merge_request) + value = type.coerce_isolated_result(value) + + expect(value).to eq(merge_request.public_merge_status.upcase) + end + end + end + end end diff --git a/spec/graphql/types/mutation_type_spec.rb b/spec/graphql/types/mutation_type_spec.rb index e4144e4fa97..c1a5c93c85b 100644 --- a/spec/graphql/types/mutation_type_spec.rb +++ b/spec/graphql/types/mutation_type_spec.rb @@ -15,28 +15,6 @@ RSpec.describe Types::MutationType do expect(described_class).to have_graphql_mutation(Mutations::MergeRequests::SetDraft) end - describe 'deprecated and aliased mutations' do - using RSpec::Parameterized::TableSyntax - - where(:alias_name, :canonical_name) do - 'AddAwardEmoji' | 'AwardEmojiAdd' - 'RemoveAwardEmoji' | 'AwardEmojiRemove' - 'ToggleAwardEmoji' | 'AwardEmojiToggle' - end - - with_them do - let(:alias_field) { get_field(alias_name) } - let(:canonical_field) { get_field(canonical_name) } - - it { expect(alias_field).to be_present } - it { expect(canonical_field).to be_present } - it { expect(alias_field.deprecation_reason).to be_present } - it { expect(canonical_field.deprecation_reason).not_to be_present } - it { expect(alias_field.resolver.fields).to eq(canonical_field.resolver.fields) } - it { expect(alias_field.resolver.arguments).to eq(canonical_field.resolver.arguments) } - end - end - def get_field(name) described_class.fields[GraphqlHelpers.fieldnamerize(name)] end diff --git a/spec/graphql/types/packages/package_group_sort_enum_spec.rb b/spec/graphql/types/packages/package_group_sort_enum_spec.rb new file mode 100644 index 00000000000..f2ed8f66fb3 --- /dev/null +++ b/spec/graphql/types/packages/package_group_sort_enum_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageGroupSort'] do + it 'exposes all package group sort values' do + expect(described_class.values.keys).to contain_exactly(*%w[CREATED_DESC CREATED_ASC NAME_DESC NAME_ASC PROJECT_PATH_DESC PROJECT_PATH_ASC VERSION_DESC VERSION_ASC TYPE_DESC TYPE_ASC]) + end +end diff --git a/spec/graphql/types/packages/package_sort_enum_spec.rb b/spec/graphql/types/packages/package_sort_enum_spec.rb new file mode 100644 index 00000000000..fe9ce120c73 --- /dev/null +++ b/spec/graphql/types/packages/package_sort_enum_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageSort'] do + it 'exposes all package sort values' do + expect(described_class.values.keys).to contain_exactly(*%w[CREATED_DESC CREATED_ASC NAME_DESC NAME_ASC VERSION_DESC VERSION_ASC TYPE_DESC TYPE_ASC]) + end +end diff --git a/spec/graphql/types/packages/pypi/metadatum_type_spec.rb b/spec/graphql/types/packages/pypi/metadatum_type_spec.rb new file mode 100644 index 00000000000..16fb3ef2098 --- /dev/null +++ b/spec/graphql/types/packages/pypi/metadatum_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PypiMetadata'] do + it 'includes pypi metadatum fields' do + expected_fields = %w[ + id required_python + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/projects/service_type_spec.rb b/spec/graphql/types/projects/service_type_spec.rb index cca7c49e132..567bdfaec24 100644 --- a/spec/graphql/types/projects/service_type_spec.rb +++ b/spec/graphql/types/projects/service_type_spec.rb @@ -9,8 +9,8 @@ RSpec.describe Types::Projects::ServiceType do it 'resolves the corresponding type for objects' do expect(described_class.resolve_type(build(:jira_service), {})).to eq(Types::Projects::Services::JiraServiceType) expect(described_class.resolve_type(build(:service), {})).to eq(Types::Projects::Services::BaseServiceType) - expect(described_class.resolve_type(build(:drone_ci_service), {})).to eq(Types::Projects::Services::BaseServiceType) - expect(described_class.resolve_type(build(:custom_issue_tracker_service), {})).to eq(Types::Projects::Services::BaseServiceType) + expect(described_class.resolve_type(build(:drone_ci_integration), {})).to eq(Types::Projects::Services::BaseServiceType) + expect(described_class.resolve_type(build(:custom_issue_tracker_integration), {})).to eq(Types::Projects::Services::BaseServiceType) end end end diff --git a/spec/graphql/types/projects/services_enum_spec.rb b/spec/graphql/types/projects/services_enum_spec.rb index c23c652a378..39c2dcd07f6 100644 --- a/spec/graphql/types/projects/services_enum_spec.rb +++ b/spec/graphql/types/projects/services_enum_spec.rb @@ -3,13 +3,11 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['ServiceType'] do - specify { expect(described_class.graphql_name).to eq('ServiceType') } - it 'exposes all the existing project services' do expect(described_class.values.keys).to match_array(available_services_enum) end -end -def available_services_enum - ::Integration.available_services_types(include_dev: false).map(&:underscore).map(&:upcase) + def available_services_enum + ::Integration.available_services_types(include_dev: false).map(&:underscore).map(&:upcase) + end end diff --git a/spec/graphql/types/snippet_type_spec.rb b/spec/graphql/types/snippet_type_spec.rb index b87770ebe8d..f284d88180c 100644 --- a/spec/graphql/types/snippet_type_spec.rb +++ b/spec/graphql/types/snippet_type_spec.rb @@ -13,7 +13,7 @@ RSpec.describe GitlabSchema.types['Snippet'] do :visibility_level, :created_at, :updated_at, :web_url, :raw_url, :ssh_url_to_repo, :http_url_to_repo, :notes, :discussions, :user_permissions, - :description_html, :blob, :blobs] + :description_html, :blobs] expect(described_class).to have_graphql_fields(*expected_fields) end @@ -133,32 +133,6 @@ RSpec.describe GitlabSchema.types['Snippet'] do end end - describe '#blob' do - let(:query_blob) { subject.dig('data', 'snippets', 'nodes')[0]['blob'] } - - subject { GitlabSchema.execute(snippet_query_for(field: 'blob'), context: { current_user: user }).as_json } - - context 'when snippet has repository' do - let!(:snippet) { create(:personal_snippet, :repository, :public, author: user) } - let(:blob) { snippet.blobs.first } - - it 'returns the first blob from the repository' do - expect(query_blob['name']).to eq blob.name - expect(query_blob['path']).to eq blob.path - end - end - - context 'when snippet does not have a repository' do - let!(:snippet) { create(:personal_snippet, :public, author: user) } - let(:blob) { snippet.blob } - - it 'returns SnippetBlob type' do - expect(query_blob['name']).to eq blob.name - expect(query_blob['path']).to eq blob.path - end - end - end - describe '#blobs' do let_it_be(:snippet) { create(:personal_snippet, :public, author: user) } diff --git a/spec/graphql/types/snippets/blob_viewer_type_spec.rb b/spec/graphql/types/snippets/blob_viewer_type_spec.rb index 295df992c67..c3b98236f2b 100644 --- a/spec/graphql/types/snippets/blob_viewer_type_spec.rb +++ b/spec/graphql/types/snippets/blob_viewer_type_spec.rb @@ -31,7 +31,7 @@ RSpec.describe GitlabSchema.types['SnippetBlobViewer'] do end it 'returns false' do - snippet_blob = subject.dig('data', 'snippets', 'edges')[0].dig('node', 'blob') + snippet_blob = subject.dig('data', 'snippets', 'edges').first.dig('node', 'blobs', 'nodes').find { |b| b['path'] == blob.path } expect(snippet_blob['path']).to eq blob.path expect(blob_attribute).to be_nil @@ -47,10 +47,12 @@ RSpec.describe GitlabSchema.types['SnippetBlobViewer'] do snippets(ids: "#{snippet.to_global_id}") { edges { node { - blob { - path - simpleViewer { - collapsed + blobs { + nodes { + path + simpleViewer { + collapsed + } } } } @@ -73,10 +75,12 @@ RSpec.describe GitlabSchema.types['SnippetBlobViewer'] do snippets(ids: "#{snippet.to_global_id}") { edges { node { - blob { - path - simpleViewer { - tooLarge + blobs { + nodes { + path + simpleViewer { + tooLarge + } } } } diff --git a/spec/graphql/types/timelog_type_spec.rb b/spec/graphql/types/timelog_type_spec.rb index 791c2fdb046..1344af89fb6 100644 --- a/spec/graphql/types/timelog_type_spec.rb +++ b/spec/graphql/types/timelog_type_spec.rb @@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['Timelog'] do it { expect(described_class.graphql_name).to eq('Timelog') } it { expect(described_class).to have_graphql_fields(fields) } - it { expect(described_class).to require_graphql_authorizations(:read_group_timelogs) } + it { expect(described_class).to require_graphql_authorizations(:read_issue) } describe 'user field' do subject { described_class.fields['user'] } |