diff options
Diffstat (limited to 'spec/graphql/types')
17 files changed, 187 insertions, 15 deletions
diff --git a/spec/graphql/types/admin/analytics/usage_trends/measurement_type_spec.rb b/spec/graphql/types/admin/analytics/usage_trends/measurement_type_spec.rb index d1c2b4044c1..37c9d6b269c 100644 --- a/spec/graphql/types/admin/analytics/usage_trends/measurement_type_spec.rb +++ b/spec/graphql/types/admin/analytics/usage_trends/measurement_type_spec.rb @@ -36,8 +36,14 @@ RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do end context 'when the user is not admin' do - it 'returns no data' do - expect(subject.dig('data', 'usageTrendsMeasurements')).to be_nil + it 'returns an error' do + expected_err = "The resource that you are attempting to access does not exist or you don't have permission to perform this action" + + expect(subject["errors"].first["message"]).to eq(expected_err) + end + + it 'does not return usageTrendsMeasurements data' do + expect(subject["data"]["usageTrendsMeasurements"]).to be_nil end end @@ -48,7 +54,7 @@ RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do stub_application_setting(admin_mode: false) end - it 'returns data' do + it 'returns usageTrendsMeasurements data' do expect(subject.dig('data', 'usageTrendsMeasurements', 'nodes')).not_to be_empty end end diff --git a/spec/graphql/types/base_edge_spec.rb b/spec/graphql/types/base_edge_spec.rb new file mode 100644 index 00000000000..3afb4202173 --- /dev/null +++ b/spec/graphql/types/base_edge_spec.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::BaseEdge do + include GraphqlHelpers + + let_it_be(:test_schema) do + project_edge_type = Class.new(described_class) do + field :proof_of_admin_rights, String, + null: true, authorize: :admin_project + + def proof_of_admin_rights + 'ok' + end + end + + project_type = Class.new(::Types::BaseObject) do + graphql_name 'Project' + authorize :read_project + edge_type_class project_edge_type + + field :name, String, null: false + end + + Class.new(GraphQL::Schema) do + lazy_resolve ::Gitlab::Graphql::Lazy, :force + use ::GraphQL::Pagination::Connections + use ::Gitlab::Graphql::Pagination::Connections + + query(Class.new(::Types::BaseObject) do + graphql_name 'Query' + field :projects, project_type.connection_type, null: false + + def projects + context[:projects] + end + end) + end + end + + def document + GraphQL.parse(<<~GQL) + query { + projects { + edges { + proofOfAdminRights + node { name } + } + } + } + GQL + end + + it 'supports field authorization on edge fields' do + user = create(:user) + private_project = create(:project, :private) + member_project = create(:project, :private) + maintainer_project = create(:project, :private) + public_project = create(:project, :public) + + member_project.add_developer(user) + maintainer_project.add_maintainer(user) + projects = [private_project, member_project, maintainer_project, public_project] + + data = { current_user: user, projects: projects } + query = GraphQL::Query.new(test_schema, document: document, context: data) + result = query.result.to_h + + expect(graphql_dig_at(result, 'data', 'projects', 'edges', 'node', 'name')) + .to contain_exactly(member_project.name, maintainer_project.name, public_project.name) + + expect(graphql_dig_at(result, 'data', 'projects', 'edges', 'proofOfAdminRights')) + .to contain_exactly(nil, 'ok', nil) + end +end diff --git a/spec/graphql/types/boards/board_issue_input_type_spec.rb b/spec/graphql/types/boards/board_issue_input_type_spec.rb index 5d3efb9b40d..ed2872c3598 100644 --- a/spec/graphql/types/boards/board_issue_input_type_spec.rb +++ b/spec/graphql/types/boards/board_issue_input_type_spec.rb @@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['BoardIssueInput'] do it 'has specific fields' do allowed_args = %w(labelName milestoneTitle assigneeUsername authorUsername - releaseTag myReactionEmoji not search assigneeWildcardId) + releaseTag myReactionEmoji not search assigneeWildcardId confidential) expect(described_class.arguments.keys).to include(*allowed_args) expect(described_class.arguments['not'].type).to eq(Types::Boards::NegatedBoardIssueInputType) diff --git a/spec/graphql/types/ci/job_need_union_spec.rb b/spec/graphql/types/ci/job_need_union_spec.rb new file mode 100644 index 00000000000..49df9ddc7eb --- /dev/null +++ b/spec/graphql/types/ci/job_need_union_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::JobNeedUnion do + describe '.resolve_type' do + context 'when resolving a build need' do + it 'resolves to a BuildNeedType' do + resolved_type = described_class.resolve_type(build(:ci_build_need), {}) + + expect(resolved_type).to be(Types::Ci::BuildNeedType) + end + end + + context 'when resolving a build' do + it 'resolves to a JobType' do + resolved_type = described_class.resolve_type(build(:ci_build), {}) + + expect(resolved_type).to be(Types::Ci::JobType) + end + end + + context 'when resolving an unrelated object' do + it 'raises a TypeNotSupportedError for string object' do + expect do + described_class.resolve_type(+'unrelated object', {}) + end.to raise_error(Types::Ci::JobNeedUnion::TypeNotSupportedError) + end + + it 'raises a TypeNotSupportedError for nil object' do + expect do + described_class.resolve_type(nil, {}) + end.to raise_error(Types::Ci::JobNeedUnion::TypeNotSupportedError) + end + + it 'raises a TypeNotSupportedError for other CI object' do + expect do + described_class.resolve_type(build(:ci_pipeline), {}) + end.to raise_error(Types::Ci::JobNeedUnion::TypeNotSupportedError) + end + end + end +end diff --git a/spec/graphql/types/ci/job_token_scope_type_spec.rb b/spec/graphql/types/ci/job_token_scope_type_spec.rb index 19a8cc324f9..43225b2089b 100644 --- a/spec/graphql/types/ci/job_token_scope_type_spec.rb +++ b/spec/graphql/types/ci/job_token_scope_type_spec.rb @@ -12,7 +12,7 @@ RSpec.describe GitlabSchema.types['CiJobTokenScopeType'] do end describe 'query' do - let_it_be(:project) { create(:project, ci_job_token_scope_enabled: true).tap(&:save!) } + let(:project) { create(:project, ci_job_token_scope_enabled: true).tap(&:save!) } let_it_be(:current_user) { create(:user) } let(:query) do @@ -65,8 +65,12 @@ RSpec.describe GitlabSchema.types['CiJobTokenScopeType'] do project.ci_cd_settings.update!(job_token_scope_enabled: false) end + it 'does not return an error' do + expect(subject['errors']).to be_nil + end + it 'returns nil' do - expect(subject.dig('data', 'project', 'ciJobTokenScope')).to be_nil + expect(subject['data']['project']['ciJobTokenScope']).to be_nil end end end diff --git a/spec/graphql/types/ci/job_type_spec.rb b/spec/graphql/types/ci/job_type_spec.rb index e95a7da4fe5..e3cb56c2ad5 100644 --- a/spec/graphql/types/ci/job_type_spec.rb +++ b/spec/graphql/types/ci/job_type_spec.rb @@ -25,6 +25,7 @@ RSpec.describe Types::Ci::JobType do needs pipeline playable + previousStageJobsOrNeeds queued_at queued_duration refName diff --git a/spec/graphql/types/clusters/agent_activity_event_type_spec.rb b/spec/graphql/types/clusters/agent_activity_event_type_spec.rb new file mode 100644 index 00000000000..7773bad749d --- /dev/null +++ b/spec/graphql/types/clusters/agent_activity_event_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['ClusterAgentActivityEvent'] do + let(:fields) { %i[recorded_at kind level user agent_token] } + + it { expect(described_class.graphql_name).to eq('ClusterAgentActivityEvent') } + it { expect(described_class).to require_graphql_authorizations(:admin_cluster) } + it { expect(described_class).to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/clusters/agent_type_spec.rb b/spec/graphql/types/clusters/agent_type_spec.rb index 4b4b601b230..a1e5952bf73 100644 --- a/spec/graphql/types/clusters/agent_type_spec.rb +++ b/spec/graphql/types/clusters/agent_type_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['ClusterAgent'] do - let(:fields) { %i[created_at created_by_user id name project updated_at tokens web_path connections] } + let(:fields) { %i[created_at created_by_user id name project updated_at tokens web_path connections activity_events] } it { expect(described_class.graphql_name).to eq('ClusterAgent') } diff --git a/spec/graphql/types/container_respository_tags_sort_enum_spec.rb b/spec/graphql/types/container_respository_tags_sort_enum_spec.rb new file mode 100644 index 00000000000..b464037d8d9 --- /dev/null +++ b/spec/graphql/types/container_respository_tags_sort_enum_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['ContainerRepositoryTagSort'] do + specify { expect(described_class.graphql_name).to eq('ContainerRepositoryTagSort') } + + it 'exposes all the existing issue sort values' do + expect(described_class.values.keys).to include( + *%w[NAME_ASC NAME_DESC] + ) + end +end diff --git a/spec/graphql/types/issue_type_enum_spec.rb b/spec/graphql/types/issue_type_enum_spec.rb index 7ae5eb76f28..131e92aa5ed 100644 --- a/spec/graphql/types/issue_type_enum_spec.rb +++ b/spec/graphql/types/issue_type_enum_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' RSpec.describe Types::IssueTypeEnum do specify { expect(described_class.graphql_name).to eq('IssueType') } - it 'exposes all the existing issue type values' do - expect(described_class.values.keys).to include( - *%w[ISSUE INCIDENT] + it 'exposes all the existing issue type values except for task' do + expect(described_class.values.keys).to match_array( + %w[ISSUE INCIDENT TEST_CASE REQUIREMENT] ) end end diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb index c0a0fdf3b0b..1b8bf007a73 100644 --- a/spec/graphql/types/issue_type_spec.rb +++ b/spec/graphql/types/issue_type_spec.rb @@ -66,10 +66,16 @@ RSpec.describe GitlabSchema.types['Issue'] do end context 'when user does not have the permission' do - it 'returns no data' do + before do allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(false) + end - expect(subject.dig(:data, :project)).to eq(nil) + it 'does not return an error' do + expect(subject['errors']).to be_nil + end + + it 'returns no data' do + expect(subject['data']['project']).to be_nil end end diff --git a/spec/graphql/types/packages/package_details_type_spec.rb b/spec/graphql/types/packages/package_details_type_spec.rb index 7e1103d8aa0..f0b684d6b07 100644 --- a/spec/graphql/types/packages/package_details_type_spec.rb +++ b/spec/graphql/types/packages/package_details_type_spec.rb @@ -10,4 +10,13 @@ RSpec.describe GitlabSchema.types['PackageDetailsType'] do expect(described_class).to include_graphql_fields(*expected_fields) end + + it 'overrides the pipelines field' do + field = described_class.fields['pipelines'] + + expect(field).to have_graphql_type(Types::Ci::PipelineType.connection_type) + expect(field).to have_graphql_extension(Gitlab::Graphql::Extensions::ExternallyPaginatedArrayExtension) + expect(field).to have_graphql_resolver(Resolvers::PackagePipelinesResolver) + expect(field).not_to be_connection + end end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 4f205e861dd..adf5507571b 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -34,7 +34,7 @@ RSpec.describe GitlabSchema.types['Project'] do container_repositories container_repositories_count pipeline_analytics squash_read_only sast_ci_configuration cluster_agent cluster_agents agent_configurations - ci_template timelogs merge_commit_template + ci_template timelogs merge_commit_template squash_commit_template ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/range_input_type_spec.rb b/spec/graphql/types/range_input_type_spec.rb index ca27527c2b5..fc9126247fa 100644 --- a/spec/graphql/types/range_input_type_spec.rb +++ b/spec/graphql/types/range_input_type_spec.rb @@ -24,7 +24,7 @@ RSpec.describe ::Types::RangeInputType do it 'follows expected subtyping relationships for instances' do context = GraphQL::Query::Context.new( - query: OpenStruct.new(schema: nil), + query: double('query', schema: nil), values: {}, object: nil ) diff --git a/spec/graphql/types/repository/blob_type_spec.rb b/spec/graphql/types/repository/blob_type_spec.rb index 7f37237f355..21bc88e34c0 100644 --- a/spec/graphql/types/repository/blob_type_spec.rb +++ b/spec/graphql/types/repository/blob_type_spec.rb @@ -24,10 +24,12 @@ RSpec.describe Types::Repository::BlobType do :raw_path, :replace_path, :pipeline_editor_path, + :code_owners, :simple_viewer, :rich_viewer, :plain_data, :can_modify_blob, + :can_current_user_push_to_branch, :ide_edit_path, :external_storage_url, :fork_and_edit_path, diff --git a/spec/graphql/types/subscription_type_spec.rb b/spec/graphql/types/subscription_type_spec.rb index b99df374bb3..bf933945a31 100644 --- a/spec/graphql/types/subscription_type_spec.rb +++ b/spec/graphql/types/subscription_type_spec.rb @@ -6,6 +6,7 @@ RSpec.describe GitlabSchema.types['Subscription'] do it 'has the expected fields' do expected_fields = %i[ issuable_assignees_updated + issue_crm_contacts_updated ] expect(described_class).to have_graphql_fields(*expected_fields).only diff --git a/spec/graphql/types/user_callout_feature_name_enum_spec.rb b/spec/graphql/types/user_callout_feature_name_enum_spec.rb index 28755e1301b..5dfcfc21708 100644 --- a/spec/graphql/types/user_callout_feature_name_enum_spec.rb +++ b/spec/graphql/types/user_callout_feature_name_enum_spec.rb @@ -6,6 +6,6 @@ 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)) + expect(described_class.values.keys).to match_array(::Users::Callout.feature_names.keys.map(&:upcase)) end end |