diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/graphql/types | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/graphql/types')
26 files changed, 257 insertions, 15 deletions
diff --git a/spec/graphql/types/alert_management/domain_filter_enum_spec.rb b/spec/graphql/types/alert_management/domain_filter_enum_spec.rb new file mode 100644 index 00000000000..2111a33b8b4 --- /dev/null +++ b/spec/graphql/types/alert_management/domain_filter_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['AlertManagementDomainFilter'] do + specify { expect(described_class.graphql_name).to eq('AlertManagementDomainFilter') } + + it 'exposes all the severity values' do + expect(described_class.values.keys).to include(*%w[threat_monitoring operations]) + end +end diff --git a/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb b/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb index 0e9994035d8..b10c2a2ab2a 100644 --- a/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb +++ b/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb @@ -11,11 +11,14 @@ RSpec.describe GitlabSchema.types['AlertManagementPrometheusIntegration'] do describe 'resolvers' do shared_examples_for 'has field with value' do |field_name| it 'correctly renders the field' do - expect(resolve_field(field_name, integration)).to eq(value) + result = resolve_field(field_name, integration, current_user: user) + + expect(result).to eq(value) end end let_it_be_with_reload(:integration) { create(:prometheus_service) } + let_it_be(:user) { create(:user, maintainer_projects: [integration.project]) } it_behaves_like 'has field with value', 'name' do let(:value) { integration.title } diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb index d61ea6aa6e9..54b59317b55 100644 --- a/spec/graphql/types/base_field_spec.rb +++ b/spec/graphql/types/base_field_spec.rb @@ -145,11 +145,11 @@ RSpec.describe Types::BaseField do describe '#description' do context 'feature flag given' do - let(:field) { described_class.new(name: 'test', type: GraphQL::STRING_TYPE, feature_flag: flag, null: false, description: 'Test description') } + let(:field) { described_class.new(name: 'test', type: GraphQL::STRING_TYPE, feature_flag: flag, null: false, description: 'Test description.') } let(:flag) { :test_flag } it 'prepends the description' do - expect(field.description). to eq 'Test description. Available only when feature flag `test_flag` is enabled' + expect(field.description). to eq 'Test description. Available only when feature flag `test_flag` is enabled.' end context 'falsey feature_flag values' do @@ -164,7 +164,7 @@ RSpec.describe Types::BaseField do with_them do it 'returns the correct description' do - expect(field.description).to eq('Test description') + expect(field.description).to eq('Test description.') end end end @@ -181,11 +181,11 @@ RSpec.describe Types::BaseField do it 'interacts well with the `feature_flag` property' do field = subject( deprecated: { milestone: '1.10', reason: 'Deprecation reason' }, - description: 'Field description', + description: 'Field description.', feature_flag: 'foo_flag' ) - expectation = 'Field description. Available only when feature flag `foo_flag` is enabled. Deprecated in 1.10: Deprecation reason' + expectation = 'Field description. Available only when feature flag `foo_flag` is enabled. Deprecated in 1.10: Deprecation reason.' expect(field.description).to eq(expectation) end diff --git a/spec/graphql/types/ci/analytics_type_spec.rb b/spec/graphql/types/ci/analytics_type_spec.rb new file mode 100644 index 00000000000..c8462d40769 --- /dev/null +++ b/spec/graphql/types/ci/analytics_type_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::AnalyticsType do + it 'exposes the expected fields' do + expected_fields = %i[ + weekPipelinesTotals + weekPipelinesLabels + weekPipelinesSuccessful + monthPipelinesLabels + monthPipelinesTotals + monthPipelinesSuccessful + yearPipelinesLabels + yearPipelinesTotals + yearPipelinesSuccessful + pipelineTimesLabels + pipelineTimesValues + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/config/config_type_spec.rb b/spec/graphql/types/ci/config/config_type_spec.rb new file mode 100644 index 00000000000..edd190a4365 --- /dev/null +++ b/spec/graphql/types/ci/config/config_type_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::ConfigType do + specify { expect(described_class.graphql_name).to eq('CiConfig') } + + it 'exposes the expected fields' do + expected_fields = %i[ + errors + mergedYaml + stages + status + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/config/group_type_spec.rb b/spec/graphql/types/ci/config/group_type_spec.rb new file mode 100644 index 00000000000..7d808e85371 --- /dev/null +++ b/spec/graphql/types/ci/config/group_type_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::GroupType do + specify { expect(described_class.graphql_name).to eq('CiConfigGroup') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + jobs + size + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/config/job_type_spec.rb b/spec/graphql/types/ci/config/job_type_spec.rb new file mode 100644 index 00000000000..600d665a84b --- /dev/null +++ b/spec/graphql/types/ci/config/job_type_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::JobType do + specify { expect(described_class.graphql_name).to eq('CiConfigJob') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + group_name + stage + needs + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/config/need_type_spec.rb b/spec/graphql/types/ci/config/need_type_spec.rb new file mode 100644 index 00000000000..3387049a81d --- /dev/null +++ b/spec/graphql/types/ci/config/need_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::NeedType do + specify { expect(described_class.graphql_name).to eq('CiConfigNeed') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/config/stage_type_spec.rb b/spec/graphql/types/ci/config/stage_type_spec.rb new file mode 100644 index 00000000000..aba97f8c7ed --- /dev/null +++ b/spec/graphql/types/ci/config/stage_type_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::StageType do + specify { expect(described_class.graphql_name).to eq('CiConfigStage') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + groups + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/job_artifact_file_type_enum_spec.rb b/spec/graphql/types/ci/job_artifact_file_type_enum_spec.rb new file mode 100644 index 00000000000..78a32595730 --- /dev/null +++ b/spec/graphql/types/ci/job_artifact_file_type_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['JobArtifactFileType'] do + it 'exposes all job artifact file types' do + expect(described_class.values.keys).to contain_exactly( + *::Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS.keys.map(&:to_s).map(&:upcase) + ) + end +end diff --git a/spec/graphql/types/ci/job_artifact_type_spec.rb b/spec/graphql/types/ci/job_artifact_type_spec.rb new file mode 100644 index 00000000000..d4dc5ef214d --- /dev/null +++ b/spec/graphql/types/ci/job_artifact_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CiJobArtifact'] do + it 'has the correct fields' do + expected_fields = [:download_path, :file_type] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/job_type_spec.rb b/spec/graphql/types/ci/job_type_spec.rb index 3dcb81eefbf..441a719df8c 100644 --- a/spec/graphql/types/ci/job_type_spec.rb +++ b/spec/graphql/types/ci/job_type_spec.rb @@ -12,6 +12,7 @@ RSpec.describe Types::Ci::JobType do needs detailedStatus scheduledAt + artifacts ] 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 f13f1c9afb2..d435e337ad7 100644 --- a/spec/graphql/types/ci/pipeline_type_spec.rb +++ b/spec/graphql/types/ci/pipeline_type_spec.rb @@ -6,4 +6,19 @@ RSpec.describe Types::Ci::PipelineType do specify { expect(described_class.graphql_name).to eq('Pipeline') } specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Ci::Pipeline) } + + it 'contains attributes related to a pipeline' do + expected_fields = %w[ + 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 + ] + + if Gitlab.ee? + expected_fields << 'security_report_summary' + end + + expect(described_class).to have_graphql_fields(*expected_fields) + end end diff --git a/spec/graphql/types/commit_type_spec.rb b/spec/graphql/types/commit_type_spec.rb index e9bc7f6bb94..b43693e5804 100644 --- a/spec/graphql/types/commit_type_spec.rb +++ b/spec/graphql/types/commit_type_spec.rb @@ -9,7 +9,7 @@ RSpec.describe GitlabSchema.types['Commit'] do it 'contains attributes related to commit' do expect(described_class).to have_graphql_fields( - :id, :sha, :title, :description, :description_html, :message, :title_html, :authored_date, + :id, :sha, :short_id, :title, :description, :description_html, :message, :title_html, :authored_date, :author_name, :author_gravatar, :author, :web_url, :web_path, :pipelines, :signature_html ) diff --git a/spec/graphql/types/container_repository_details_type_spec.rb b/spec/graphql/types/container_repository_details_type_spec.rb index b5ff460fcf7..45f6449d8c8 100644 --- a/spec/graphql/types/container_repository_details_type_spec.rb +++ b/spec/graphql/types/container_repository_details_type_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['ContainerRepositoryDetails'] do - fields = %i[id name path location created_at updated_at expiration_policy_started_at status tags_count can_delete expiration_policy_cleanup_status tags] + fields = %i[id name path location created_at updated_at expiration_policy_started_at status tags_count can_delete expiration_policy_cleanup_status tags project] it { expect(described_class.graphql_name).to eq('ContainerRepositoryDetails') } diff --git a/spec/graphql/types/container_repository_type_spec.rb b/spec/graphql/types/container_repository_type_spec.rb index 3d3445ba5c3..87e1c11ce19 100644 --- a/spec/graphql/types/container_repository_type_spec.rb +++ b/spec/graphql/types/container_repository_type_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['ContainerRepository'] do - fields = %i[id name path location created_at updated_at expiration_policy_started_at status tags_count can_delete expiration_policy_cleanup_status] + fields = %i[id name path location created_at updated_at expiration_policy_started_at status tags_count can_delete expiration_policy_cleanup_status project] it { expect(described_class.graphql_name).to eq('ContainerRepository') } diff --git a/spec/graphql/types/countable_connection_type_spec.rb b/spec/graphql/types/countable_connection_type_spec.rb index 3b3c02baa5d..648dbacff42 100644 --- a/spec/graphql/types/countable_connection_type_spec.rb +++ b/spec/graphql/types/countable_connection_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe GitlabSchema.types['MergeRequestConnection'] do +RSpec.describe GitlabSchema.types['PipelineConnection'] do it 'has the expected fields' do expected_fields = %i[count page_info edges nodes] diff --git a/spec/graphql/types/group_member_relation_enum_spec.rb b/spec/graphql/types/group_member_relation_enum_spec.rb new file mode 100644 index 00000000000..315809ef75e --- /dev/null +++ b/spec/graphql/types/group_member_relation_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::GroupMemberRelationEnum do + specify { expect(described_class.graphql_name).to eq('GroupMemberRelation') } + + it 'exposes all the existing group member relation type values' do + expect(described_class.values.keys).to contain_exactly('DIRECT', 'INHERITED', 'DESCENDANTS') + end +end diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index 7d14ef87551..de19e8b602a 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -17,7 +17,7 @@ RSpec.describe GitlabSchema.types['Group'] do subgroup_creation_level require_two_factor_authentication two_factor_grace_period auto_devops_enabled emails_disabled mentions_disabled parent boards milestones group_members - merge_requests + merge_requests container_repositories container_repositories_count ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/merge_request_connection_type_spec.rb b/spec/graphql/types/merge_request_connection_type_spec.rb new file mode 100644 index 00000000000..f4ab6c79721 --- /dev/null +++ b/spec/graphql/types/merge_request_connection_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['MergeRequestConnection'] do + it 'has the expected fields' do + expected_fields = %i[count totalTimeToMerge page_info edges nodes] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 8800250b103..51e7b4029d5 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -27,18 +27,27 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do upvotes downvotes head_pipeline pipelines task_completion_status milestone assignees 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 + 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 security_auto_fix ] if Gitlab.ee? expected_fields << 'approved' expected_fields << 'approvals_left' expected_fields << 'approvals_required' + expected_fields << 'merge_trains_count' end expect(described_class).to have_graphql_fields(*expected_fields) end + describe '#pipelines' do + subject { described_class.fields['pipelines'] } + + it { is_expected.to have_attributes(max_page_size: 500) } + end + describe '#diff_stats_summary' do subject { GitlabSchema.execute(query, context: { current_user: current_user }).as_json } diff --git a/spec/graphql/types/permission_types/base_permission_type_spec.rb b/spec/graphql/types/permission_types/base_permission_type_spec.rb index 2ce02f1520c..68632a509ee 100644 --- a/spec/graphql/types/permission_types/base_permission_type_spec.rb +++ b/spec/graphql/types/permission_types/base_permission_type_spec.rb @@ -11,9 +11,13 @@ RSpec.describe Types::PermissionTypes::BasePermissionType do Class.new(described_class) do graphql_name 'TestClass' - permission_field :do_stuff, resolve: -> (_, _, _) { true } + permission_field :do_stuff ability_field(:read_issue) abilities :admin_issue + + define_method :do_stuff do + true + end end end diff --git a/spec/graphql/types/project_member_relation_enum_spec.rb b/spec/graphql/types/project_member_relation_enum_spec.rb new file mode 100644 index 00000000000..3c947bf8406 --- /dev/null +++ b/spec/graphql/types/project_member_relation_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::ProjectMemberRelationEnum do + specify { expect(described_class.graphql_name).to eq('ProjectMemberRelation') } + + it 'exposes all the existing project member relation type values' do + expect(described_class.values.keys).to contain_exactly('DIRECT', 'INHERITED', 'DESCENDANTS', 'INVITED_GROUPS') + end +end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index be579e92fb3..b3028e034cc 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['Project'] do + include GraphqlHelpers + specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Project) } specify { expect(described_class.graphql_name).to eq('Project') } @@ -28,7 +30,8 @@ RSpec.describe GitlabSchema.types['Project'] do alert_management_alerts alert_management_alert alert_management_alert_status_counts container_expiration_policy service_desk_enabled service_desk_address issue_status_counts terraform_states alert_management_integrations - + container_repositories container_repositories_count + pipeline_analytics total_pipeline_duration squash_read_only ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -76,6 +79,7 @@ RSpec.describe GitlabSchema.types['Project'] do :merged_before, :author_username, :assignee_username, + :reviewer_username, :milestone_title, :sort ) @@ -163,4 +167,32 @@ RSpec.describe GitlabSchema.types['Project'] do end it_behaves_like 'a GraphQL type with labels' + + describe 'jira_imports' do + subject { resolve_field(:jira_imports, project) } + + let_it_be(:project) { create(:project, :public) } + + context 'when project has Jira imports' do + let_it_be(:jira_import1) { create(:jira_import_state, :finished, project: project, jira_project_key: 'AA', created_at: 2.days.ago) } + let_it_be(:jira_import2) { create(:jira_import_state, :finished, project: project, jira_project_key: 'BB', created_at: 5.days.ago) } + + it 'retrieves the imports' do + expect(subject).to contain_exactly(jira_import1, jira_import2) + end + end + + context 'when project does not have Jira imports' do + it 'returns an empty result' do + expect(subject).to be_empty + end + end + end + + describe 'pipeline_analytics field' do + subject { described_class.fields['pipelineAnalytics'] } + + it { is_expected.to have_graphql_type(Types::Ci::AnalyticsType) } + it { is_expected.to have_graphql_resolver(Resolvers::ProjectPipelineStatisticsResolver) } + end end diff --git a/spec/graphql/types/terraform/state_version_type_spec.rb b/spec/graphql/types/terraform/state_version_type_spec.rb index 1c1e95039dc..18f869e4f1f 100644 --- a/spec/graphql/types/terraform/state_version_type_spec.rb +++ b/spec/graphql/types/terraform/state_version_type_spec.rb @@ -7,13 +7,15 @@ RSpec.describe GitlabSchema.types['TerraformStateVersion'] do it { expect(described_class).to require_graphql_authorizations(:read_terraform_state) } describe 'fields' do - let(:fields) { %i[id created_by_user job created_at updated_at] } + let(:fields) { %i[id created_by_user job download_path serial created_at updated_at] } it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class.fields['id'].type).to be_non_null } it { expect(described_class.fields['createdByUser'].type).not_to be_non_null } it { expect(described_class.fields['job'].type).not_to be_non_null } + it { expect(described_class.fields['downloadPath'].type).not_to be_non_null } + it { expect(described_class.fields['serial'].type).not_to be_non_null } it { expect(described_class.fields['createdAt'].type).to be_non_null } it { expect(described_class.fields['updatedAt'].type).to be_non_null } end diff --git a/spec/graphql/types/user_type_spec.rb b/spec/graphql/types/user_type_spec.rb index c8953d9ccb7..0eff33bb25b 100644 --- a/spec/graphql/types/user_type_spec.rb +++ b/spec/graphql/types/user_type_spec.rb @@ -15,14 +15,17 @@ RSpec.describe GitlabSchema.types['User'] do name username email + publicEmail avatarUrl webUrl webPath todos state status + location authoredMergeRequests assignedMergeRequests + reviewRequestedMergeRequests groupMemberships groupCount projectMemberships |