diff options
Diffstat (limited to 'spec/graphql/types')
18 files changed, 170 insertions, 38 deletions
diff --git a/spec/graphql/types/access_level_enum_spec.rb b/spec/graphql/types/access_level_enum_spec.rb index eeb10a50b7e..1b379c56ff9 100644 --- a/spec/graphql/types/access_level_enum_spec.rb +++ b/spec/graphql/types/access_level_enum_spec.rb @@ -6,6 +6,6 @@ RSpec.describe GitlabSchema.types['AccessLevelEnum'] do specify { expect(described_class.graphql_name).to eq('AccessLevelEnum') } it 'exposes all the existing access levels' do - expect(described_class.values.keys).to match_array(%w[NO_ACCESS GUEST REPORTER DEVELOPER MAINTAINER OWNER]) + expect(described_class.values.keys).to match_array(%w[NO_ACCESS MINIMAL_ACCESS GUEST REPORTER DEVELOPER MAINTAINER OWNER]) end end diff --git a/spec/graphql/types/admin/analytics/instance_statistics/measurement_identifier_enum_spec.rb b/spec/graphql/types/admin/analytics/usage_trends/measurement_identifier_enum_spec.rb index 8a7408224a2..91851c11dc8 100644 --- a/spec/graphql/types/admin/analytics/instance_statistics/measurement_identifier_enum_spec.rb +++ b/spec/graphql/types/admin/analytics/usage_trends/measurement_identifier_enum_spec.rb @@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['MeasurementIdentifier'] do it 'exposes all the existing identifier values' do ee_only_identifiers = %w[billable_users] - identifiers = Analytics::InstanceStatistics::Measurement.identifiers.keys.reject do |x| + identifiers = Analytics::UsageTrends::Measurement.identifiers.keys.reject do |x| ee_only_identifiers.include?(x) end.map(&:upcase) diff --git a/spec/graphql/types/admin/analytics/instance_statistics/measurement_type_spec.rb b/spec/graphql/types/admin/analytics/usage_trends/measurement_type_spec.rb index ffb1a0f30c9..c50092d7f0e 100644 --- a/spec/graphql/types/admin/analytics/instance_statistics/measurement_type_spec.rb +++ b/spec/graphql/types/admin/analytics/usage_trends/measurement_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe GitlabSchema.types['InstanceStatisticsMeasurement'] do +RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do subject { described_class } it { is_expected.to have_graphql_field(:recorded_at) } @@ -10,13 +10,13 @@ RSpec.describe GitlabSchema.types['InstanceStatisticsMeasurement'] do it { is_expected.to have_graphql_field(:count) } describe 'authorization' do - let_it_be(:measurement) { create(:instance_statistics_measurement, :project_count) } + let_it_be(:measurement) { create(:usage_trends_measurement, :project_count) } let(:user) { create(:user) } let(:query) do <<~GRAPHQL - query instanceStatisticsMeasurements($identifier: MeasurementIdentifier!) { - instanceStatisticsMeasurements(identifier: $identifier) { + query usageTrendsMeasurements($identifier: MeasurementIdentifier!) { + usageTrendsMeasurements(identifier: $identifier) { nodes { count identifier @@ -36,7 +36,7 @@ RSpec.describe GitlabSchema.types['InstanceStatisticsMeasurement'] do context 'when the user is not admin' do it 'returns no data' do - expect(subject.dig('data', 'instanceStatisticsMeasurements')).to be_nil + expect(subject.dig('data', 'usageTrendsMeasurements')).to be_nil end end @@ -48,7 +48,7 @@ RSpec.describe GitlabSchema.types['InstanceStatisticsMeasurement'] do end it 'returns data' do - expect(subject.dig('data', 'instanceStatisticsMeasurements', 'nodes')).not_to be_empty + expect(subject.dig('data', 'usageTrendsMeasurements', 'nodes')).not_to be_empty end end end diff --git a/spec/graphql/types/alert_management/alert_type_spec.rb b/spec/graphql/types/alert_management/alert_type_spec.rb index 82b48a20708..9ff01418c9a 100644 --- a/spec/graphql/types/alert_management/alert_type_spec.rb +++ b/spec/graphql/types/alert_management/alert_type_spec.rb @@ -10,7 +10,8 @@ RSpec.describe GitlabSchema.types['AlertManagementAlert'] do it 'exposes the expected fields' do expected_fields = %i[ iid - issue_iid + issueIid + issue title description severity diff --git a/spec/graphql/types/base_argument_spec.rb b/spec/graphql/types/base_argument_spec.rb new file mode 100644 index 00000000000..61e0179ff21 --- /dev/null +++ b/spec/graphql/types/base_argument_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::BaseArgument do + include_examples 'Gitlab-style deprecations' do + let_it_be(:field) do + Types::BaseField.new(name: 'field', type: String, null: true) + end + + let(:base_args) { { name: 'test', type: String, required: false, owner: field } } + + def subject(args = {}) + described_class.new(**base_args.merge(args)) + end + end +end diff --git a/spec/graphql/types/board_type_spec.rb b/spec/graphql/types/board_type_spec.rb index 5ea87d5f473..dca3cfd8aaf 100644 --- a/spec/graphql/types/board_type_spec.rb +++ b/spec/graphql/types/board_type_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['Board'] do specify { expect(described_class.graphql_name).to eq('Board') } - specify { expect(described_class).to require_graphql_authorizations(:read_board) } + specify { expect(described_class).to require_graphql_authorizations(:read_issue_board) } it 'has specific fields' do expected_fields = %w[id name web_url web_path] diff --git a/spec/graphql/types/ci/job_type_spec.rb b/spec/graphql/types/ci/job_type_spec.rb index e277916f5cb..25f626cea0f 100644 --- a/spec/graphql/types/ci/job_type_spec.rb +++ b/spec/graphql/types/ci/job_type_spec.rb @@ -14,6 +14,8 @@ RSpec.describe Types::Ci::JobType do detailedStatus scheduledAt artifacts + finished_at + duration ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb index 2a1e030480d..e0e84a1b635 100644 --- a/spec/graphql/types/ci/pipeline_type_spec.rb +++ b/spec/graphql/types/ci/pipeline_type_spec.rb @@ -12,11 +12,11 @@ RSpec.describe Types::Ci::PipelineType do id iid sha before_sha status detailed_status config_source duration coverage created_at updated_at started_at finished_at committed_at stages user retryable cancelable jobs source_job downstream - upstream path project active user_permissions warnings + upstream path project active user_permissions warnings commit_path ] if Gitlab.ee? - expected_fields << 'security_report_summary' + expected_fields += %w[security_report_summary security_report_findings] end expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/global_id_type_spec.rb b/spec/graphql/types/global_id_type_spec.rb index cb129868f7e..8eb023ad2a3 100644 --- a/spec/graphql/types/global_id_type_spec.rb +++ b/spec/graphql/types/global_id_type_spec.rb @@ -5,7 +5,6 @@ require 'spec_helper' RSpec.describe Types::GlobalIDType do let_it_be(:project) { create(:project) } let(:gid) { project.to_global_id } - let(:foreign_gid) { GlobalID.new(::URI::GID.build(app: 'otherapp', model_name: 'Project', model_id: project.id, params: nil)) } it 'is has the correct name' do expect(described_class.to_graphql.name).to eq('GlobalID') @@ -41,16 +40,18 @@ RSpec.describe Types::GlobalIDType do it 'rejects invalid input' do expect { described_class.coerce_isolated_input('not valid') } - .to raise_error(GraphQL::CoercionError) + .to raise_error(GraphQL::CoercionError, /not a valid Global ID/) end it 'rejects nil' do expect(described_class.coerce_isolated_input(nil)).to be_nil end - it 'rejects gids from different apps' do - expect { described_class.coerce_isolated_input(foreign_gid) } - .to raise_error(GraphQL::CoercionError) + it 'rejects GIDs from different apps' do + invalid_gid = GlobalID.new(::URI::GID.build(app: 'otherapp', model_name: 'Project', model_id: project.id, params: nil)) + + expect { described_class.coerce_isolated_input(invalid_gid) } + .to raise_error(GraphQL::CoercionError, /is not a Gitlab Global ID/) end end @@ -79,14 +80,22 @@ RSpec.describe Types::GlobalIDType do let(:gid) { build_stubbed(:user).to_global_id } it 'raises errors when coercing results' do - expect { type.coerce_isolated_result(gid) }.to raise_error(GraphQL::CoercionError) + expect { type.coerce_isolated_result(gid) } + .to raise_error(GraphQL::CoercionError, /Expected a Project ID/) end it 'will not coerce invalid input, even if its a valid GID' do expect { type.coerce_isolated_input(gid.to_s) } - .to raise_error(GraphQL::CoercionError) + .to raise_error(GraphQL::CoercionError, /does not represent an instance of Project/) end end + + it 'handles GIDs for invalid resource names gracefully' do + invalid_gid = GlobalID.new(::URI::GID.build(app: GlobalID.app, model_name: 'invalid', model_id: 1, params: nil)) + + expect { type.coerce_isolated_input(invalid_gid) } + .to raise_error(GraphQL::CoercionError, /does not represent an instance of Project/) + end end describe 'a parameterized type with a namespace' do diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index bba702ba3e9..ef11e3d309c 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -18,6 +18,7 @@ RSpec.describe GitlabSchema.types['Group'] do two_factor_grace_period auto_devops_enabled emails_disabled mentions_disabled parent boards milestones group_members merge_requests container_repositories container_repositories_count + packages ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/label_type_spec.rb b/spec/graphql/types/label_type_spec.rb index 6a999a2e925..427b5d2dcef 100644 --- a/spec/graphql/types/label_type_spec.rb +++ b/spec/graphql/types/label_type_spec.rb @@ -3,7 +3,16 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['Label'] do it 'has the correct fields' do - expected_fields = [:id, :description, :description_html, :title, :color, :text_color] + expected_fields = [ + :id, + :description, + :description_html, + :title, + :color, + :text_color, + :created_at, + :updated_at + ] expect(described_class).to have_graphql_fields(*expected_fields) end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 63d288934e5..3314ea62324 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -23,7 +23,7 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do 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 + 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 @@ -77,4 +77,33 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do end end end + + describe '#diverged_from_target_branch' do + subject(:execute_query) { GitlabSchema.execute(query, context: { current_user: current_user }).as_json } + + let!(:merge_request) { create(:merge_request, target_project: project, source_project: project) } + let(:project) { create(:project, :public) } + let(:current_user) { create :admin } + let(:query) do + %( + { + project(fullPath: "#{project.full_path}") { + mergeRequests { + nodes { + divergedFromTargetBranch + } + } + } + } + ) + end + + it 'delegates the diverged_from_target_branch? call to the merge request entity' do + expect_next_found_instance_of(MergeRequest) do |instance| + expect(instance).to receive(:diverged_from_target_branch?) + end + + execute_query + end + end end diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index fea0a3bd37e..cb8e875dbf4 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -21,7 +21,7 @@ RSpec.describe GitlabSchema.types['Query'] do user users issue - instance_statistics_measurements + usage_trends_measurements runner_platforms ] @@ -65,11 +65,11 @@ RSpec.describe GitlabSchema.types['Query'] do end end - describe 'instance_statistics_measurements field' do - subject { described_class.fields['instanceStatisticsMeasurements'] } + describe 'usage_trends_measurements field' do + subject { described_class.fields['usageTrendsMeasurements'] } - it 'returns instance statistics measurements' do - is_expected.to have_graphql_type(Types::Admin::Analytics::InstanceStatistics::MeasurementType.connection_type) + it 'returns usage trends measurements' do + is_expected.to have_graphql_type(Types::Admin::Analytics::UsageTrends::MeasurementType.connection_type) end end diff --git a/spec/graphql/types/snippet_type_spec.rb b/spec/graphql/types/snippet_type_spec.rb index e73665a1b1d..4d827186a9b 100644 --- a/spec/graphql/types/snippet_type_spec.rb +++ b/spec/graphql/types/snippet_type_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['Snippet'] do + include GraphqlHelpers + let_it_be(:user) { create(:user) } it 'has the correct fields' do @@ -25,6 +27,14 @@ RSpec.describe GitlabSchema.types['Snippet'] do end end + describe '#user_permissions' do + let_it_be(:snippet) { create(:personal_snippet, :repository, :public, author: user) } + + it 'can resolve the snippet permissions' do + expect(resolve_field(:user_permissions, snippet)).to eq(snippet) + end + end + context 'when restricted visibility level is set to public' do let_it_be(:snippet) { create(:personal_snippet, :repository, :public, author: user) } diff --git a/spec/graphql/types/snippets/blob_type_spec.rb b/spec/graphql/types/snippets/blob_type_spec.rb index bfac08f40d3..60c0db8e551 100644 --- a/spec/graphql/types/snippets/blob_type_spec.rb +++ b/spec/graphql/types/snippets/blob_type_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['SnippetBlob'] do + include GraphqlHelpers + it 'has the correct fields' do expected_fields = [:rich_data, :plain_data, :raw_path, :size, :binary, :name, :path, @@ -12,16 +14,37 @@ RSpec.describe GitlabSchema.types['SnippetBlob'] do expect(described_class).to have_graphql_fields(*expected_fields) end - specify { expect(described_class.fields['richData'].type).not_to be_non_null } - specify { expect(described_class.fields['plainData'].type).not_to be_non_null } - specify { expect(described_class.fields['rawPath'].type).to be_non_null } - specify { expect(described_class.fields['size'].type).to be_non_null } - specify { expect(described_class.fields['binary'].type).to be_non_null } - specify { expect(described_class.fields['name'].type).not_to be_non_null } - specify { expect(described_class.fields['path'].type).not_to be_non_null } - specify { expect(described_class.fields['simpleViewer'].type).to be_non_null } - specify { expect(described_class.fields['richViewer'].type).not_to be_non_null } - specify { expect(described_class.fields['mode'].type).not_to be_non_null } - specify { expect(described_class.fields['externalStorage'].type).not_to be_non_null } - specify { expect(described_class.fields['renderedAsText'].type).to be_non_null } + let_it_be(:nullity) do + { + 'richData' => be_nullable, + 'plainData' => be_nullable, + 'rawPath' => be_non_null, + 'size' => be_non_null, + 'binary' => be_non_null, + 'name' => be_nullable, + 'path' => be_nullable, + 'simpleViewer' => be_non_null, + 'richViewer' => be_nullable, + 'mode' => be_nullable, + 'externalStorage' => be_nullable, + 'renderedAsText' => be_non_null + } + end + + let_it_be(:blob) { create(:snippet, :public, :repository).blobs.first } + + shared_examples 'a field from the snippet blob presenter' do |field| + it "resolves using the presenter", :request_store do + presented = SnippetBlobPresenter.new(blob) + + expect(resolve_field(field, blob)).to eq(presented.try(field.method_sym)) + end + end + + described_class.fields.each_value do |field| + describe field.graphql_name do + it_behaves_like 'a field from the snippet blob presenter', field + specify { expect(field.type).to match(nullity.fetch(field.graphql_name)) } + end + end end diff --git a/spec/graphql/types/user_callout_feature_name_enum_spec.rb b/spec/graphql/types/user_callout_feature_name_enum_spec.rb new file mode 100644 index 00000000000..28755e1301b --- /dev/null +++ b/spec/graphql/types/user_callout_feature_name_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['UserCalloutFeatureNameEnum'] do + specify { expect(described_class.graphql_name).to eq('UserCalloutFeatureNameEnum') } + + it 'exposes all the existing user callout feature names' do + expect(described_class.values.keys).to match_array(::UserCallout.feature_names.keys.map(&:upcase)) + end +end diff --git a/spec/graphql/types/user_callout_type_spec.rb b/spec/graphql/types/user_callout_type_spec.rb new file mode 100644 index 00000000000..b26b85a4e8b --- /dev/null +++ b/spec/graphql/types/user_callout_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['UserCallout'] do + specify { expect(described_class.graphql_name).to eq('UserCallout') } + + it 'has expected fields' do + expect(described_class).to have_graphql_fields(:feature_name, :dismissed_at) + end +end diff --git a/spec/graphql/types/user_type_spec.rb b/spec/graphql/types/user_type_spec.rb index 5b3662383d8..d9e67ff348b 100644 --- a/spec/graphql/types/user_type_spec.rb +++ b/spec/graphql/types/user_type_spec.rb @@ -31,6 +31,7 @@ RSpec.describe GitlabSchema.types['User'] do groupCount projectMemberships starredProjects + callouts ] expect(described_class).to have_graphql_fields(*expected_fields) @@ -44,4 +45,12 @@ RSpec.describe GitlabSchema.types['User'] do is_expected.to have_graphql_resolver(Resolvers::Users::SnippetsResolver) end end + + describe 'callouts field' do + subject { described_class.fields['callouts'] } + + it 'returns user callouts' do + is_expected.to have_graphql_type(Types::UserCalloutType.connection_type) + end + end end |