diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/graphql/types | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/graphql/types')
34 files changed, 312 insertions, 133 deletions
diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb index b85716e4d21..9f8a8717efb 100644 --- a/spec/graphql/types/base_field_spec.rb +++ b/spec/graphql/types/base_field_spec.rb @@ -205,39 +205,6 @@ RSpec.describe Types::BaseField do end end end - - describe '#visible?' do - context 'and has a feature_flag' do - let(:flag) { :test_feature } - let(:field) { described_class.new(name: 'test', type: GraphQL::Types::String, _deprecated_feature_flag: flag, null: false) } - let(:context) { {} } - - before do - skip_feature_flags_yaml_validation - end - - it 'checks YAML definition for default_enabled' do - # Exception is indicative of a check for YAML definition - expect { field.visible?(context) }.to raise_error(Feature::InvalidFeatureFlagError, /The feature flag YAML definition for '#{flag}' does not exist/) - end - - context 'skipping YAML check' do - before do - skip_default_enabled_yaml_check - end - - it 'returns false if the feature is not enabled' do - stub_feature_flags(flag => false) - - expect(field.visible?(context)).to eq(false) - end - - it 'returns true if the feature is enabled' do - expect(field.visible?(context)).to eq(true) - end - end - end - end end describe '#resolve' do @@ -251,77 +218,11 @@ RSpec.describe Types::BaseField do end end - describe '#description' do - context 'feature flag given' do - let(:field) { described_class.new(name: 'test', type: GraphQL::Types::String, _deprecated_feature_flag: flag, null: false, description: 'Test description.') } - let(:flag) { :test_flag } - - it 'prepends the description' do - expect(field.description).to start_with 'Test description. Available only when feature flag `test_flag` is enabled.' - end - - context 'falsey feature_flag values' do - using RSpec::Parameterized::TableSyntax - - where(:flag, :feature_value, :default_enabled) do - '' | false | false - '' | true | false - nil | false | true - nil | true | false - end - - with_them do - it 'returns the correct description' do - expect(field.description).to eq('Test description.') - end - end - end - - context 'with different default_enabled values' do - using RSpec::Parameterized::TableSyntax - - where(:feature_value, :default_enabled, :expected_description) do - disabled_ff_description = "Test description. Available only when feature flag `test_flag` is enabled. This flag is disabled by default, because the feature is experimental and is subject to change without notice." - enabled_ff_description = "Test description. Available only when feature flag `test_flag` is enabled. This flag is enabled by default." - - false | false | disabled_ff_description - true | false | disabled_ff_description - false | true | enabled_ff_description - true | true | enabled_ff_description - end - - with_them do - before do - stub_feature_flags("#{flag}": feature_value) - - allow(Feature::Definition).to receive(:has_definition?).with(flag).and_return(true) - allow(Feature::Definition).to receive(:default_enabled?).and_return(default_enabled) - end - - it 'returns the correct availability in the description' do - expect(field.description).to eq expected_description - end - end - end - end - end - include_examples 'Gitlab-style deprecations' do def subject(args = {}) base_args = { name: 'test', type: GraphQL::Types::String, null: true } described_class.new(**base_args.merge(args)) end - - it 'interacts well with the `_deprecated_feature_flag` property' do - field = subject( - deprecated: { milestone: '1.10', reason: 'Deprecation reason' }, - description: 'Field description.', - _deprecated_feature_flag: 'foo_flag' - ) - - expect(field.description).to start_with('Field description. Available only when feature flag `foo_flag` is enabled.') - expect(field.description).to end_with('Deprecated in 1.10: Deprecation reason.') - end end end diff --git a/spec/graphql/types/branch_protections/merge_access_level_type_spec.rb b/spec/graphql/types/branch_protections/merge_access_level_type_spec.rb new file mode 100644 index 00000000000..8cc1005d97e --- /dev/null +++ b/spec/graphql/types/branch_protections/merge_access_level_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['MergeAccessLevel'] do + subject { described_class } + + let(:fields) { %i[access_level access_level_description] } + + specify { is_expected.to require_graphql_authorizations(:read_protected_branch) } + + specify { is_expected.to have_graphql_fields(fields).at_least } +end diff --git a/spec/graphql/types/branch_protections/push_access_level_type_spec.rb b/spec/graphql/types/branch_protections/push_access_level_type_spec.rb new file mode 100644 index 00000000000..c78c0bda74c --- /dev/null +++ b/spec/graphql/types/branch_protections/push_access_level_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PushAccessLevel'] do + subject { described_class } + + let(:fields) { %i[access_level access_level_description] } + + specify { is_expected.to require_graphql_authorizations(:read_protected_branch) } + + specify { is_expected.to have_graphql_fields(fields).at_least } +end diff --git a/spec/graphql/types/branch_rule_type_spec.rb b/spec/graphql/types/branch_rule_type_spec.rb new file mode 100644 index 00000000000..277901f00bf --- /dev/null +++ b/spec/graphql/types/branch_rule_type_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['BranchRule'] do + include GraphqlHelpers + + subject { described_class } + + let(:fields) do + %i[ + name + branch_protection + created_at + updated_at + ] + end + + specify { is_expected.to require_graphql_authorizations(:read_protected_branch) } + + specify { is_expected.to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/branch_rules/branch_protection_type_spec.rb b/spec/graphql/types/branch_rules/branch_protection_type_spec.rb new file mode 100644 index 00000000000..bbc92fd8fef --- /dev/null +++ b/spec/graphql/types/branch_rules/branch_protection_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['BranchProtection'] do + subject { described_class } + + let(:fields) { %i[merge_access_levels push_access_levels allow_force_push] } + + specify { is_expected.to require_graphql_authorizations(:read_protected_branch) } + + specify { is_expected.to have_graphql_fields(fields).at_least } +end diff --git a/spec/graphql/types/ci/config_variable_type_spec.rb b/spec/graphql/types/ci/config_variable_type_spec.rb new file mode 100644 index 00000000000..2b0937a7858 --- /dev/null +++ b/spec/graphql/types/ci/config_variable_type_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CiConfigVariable'] do + specify { expect(described_class).to have_graphql_fields(:key, :description, :value).at_least } +end diff --git a/spec/graphql/types/ci/group_variable_connection_type_spec.rb b/spec/graphql/types/ci/group_variable_connection_type_spec.rb new file mode 100644 index 00000000000..4a1fd490506 --- /dev/null +++ b/spec/graphql/types/ci/group_variable_connection_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CiGroupVariableConnection'] do + it 'has the expected fields' do + expected_fields = %i[limit page_info edges nodes] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/instance_variable_type_spec.rb b/spec/graphql/types/ci/instance_variable_type_spec.rb index cf4aaed31f1..c77a4ac1dc4 100644 --- a/spec/graphql/types/ci/instance_variable_type_spec.rb +++ b/spec/graphql/types/ci/instance_variable_type_spec.rb @@ -5,5 +5,5 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['CiInstanceVariable'] do specify { expect(described_class.interfaces).to contain_exactly(Types::Ci::VariableInterface) } - specify { expect(described_class).to have_graphql_fields(:masked, :protected).at_least } + specify { expect(described_class).to have_graphql_fields(:environment_scope, :masked, :protected).at_least } end diff --git a/spec/graphql/types/ci/job_artifact_type_spec.rb b/spec/graphql/types/ci/job_artifact_type_spec.rb index 58b5f9cfcb7..3e054faf0c9 100644 --- a/spec/graphql/types/ci/job_artifact_type_spec.rb +++ b/spec/graphql/types/ci/job_artifact_type_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['CiJobArtifact'] do it 'has the correct fields' do - expected_fields = [:download_path, :file_type, :name] + expected_fields = [:id, :download_path, :file_type, :name, :size, :expire_at] expect(described_class).to have_graphql_fields(*expected_fields) 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 457d46b6896..18f4d762d1e 100644 --- a/spec/graphql/types/ci/job_token_scope_type_spec.rb +++ b/spec/graphql/types/ci/job_token_scope_type_spec.rb @@ -69,8 +69,8 @@ RSpec.describe GitlabSchema.types['CiJobTokenScopeType'] do expect(subject['errors']).to be_nil end - it 'returns nil' do - expect(subject['data']['project']['ciJobTokenScope']).to be_nil + it 'returns readable projects in scope' do + expect(returned_project_paths).to contain_exactly(project.path) end end end diff --git a/spec/graphql/types/ci/job_type_spec.rb b/spec/graphql/types/ci/job_type_spec.rb index bc9e64282bc..b3dee082d1f 100644 --- a/spec/graphql/types/ci/job_type_spec.rb +++ b/spec/graphql/types/ci/job_type_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Types::Ci::JobType do + include GraphqlHelpers + specify { expect(described_class.graphql_name).to eq('CiJob') } specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Ci::Job) } @@ -45,8 +47,21 @@ RSpec.describe Types::Ci::JobType do tags triggered userPermissions + webPath ] expect(described_class).to have_graphql_fields(*expected_fields) end + + describe '#web_path' do + subject { resolve_field(:web_path, build, current_user: user, object_type: described_class) } + + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:build) { create(:ci_build, project: project, user: user) } + + it 'returns the web path of the job' do + is_expected.to eq("/#{project.full_path}/-/jobs/#{build.id}") + end + end end diff --git a/spec/graphql/types/ci/manual_variable_type_spec.rb b/spec/graphql/types/ci/manual_variable_type_spec.rb index 2884c818a52..21d36b7dfc0 100644 --- a/spec/graphql/types/ci/manual_variable_type_spec.rb +++ b/spec/graphql/types/ci/manual_variable_type_spec.rb @@ -4,4 +4,6 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['CiManualVariable'] do specify { expect(described_class.interfaces).to contain_exactly(Types::Ci::VariableInterface) } + + specify { expect(described_class).to have_graphql_fields(:environment_scope).at_least } end diff --git a/spec/graphql/types/ci/project_variable_connection_type_spec.rb b/spec/graphql/types/ci/project_variable_connection_type_spec.rb new file mode 100644 index 00000000000..97c3a207f7f --- /dev/null +++ b/spec/graphql/types/ci/project_variable_connection_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CiProjectVariableConnection'] do + it 'has the expected fields' do + expected_fields = %i[limit page_info edges nodes] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/runner_architecture_type_spec.rb b/spec/graphql/types/ci/runner_architecture_type_spec.rb index 527adef8cf9..60709acfd53 100644 --- a/spec/graphql/types/ci/runner_architecture_type_spec.rb +++ b/spec/graphql/types/ci/runner_architecture_type_spec.rb @@ -7,8 +7,8 @@ RSpec.describe Types::Ci::RunnerArchitectureType do it 'exposes the expected fields' do expected_fields = %i[ - name - download_location + name + download_location ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/ci/runner_platform_type_spec.rb b/spec/graphql/types/ci/runner_platform_type_spec.rb index 66b83f607d0..29b8e885183 100644 --- a/spec/graphql/types/ci/runner_platform_type_spec.rb +++ b/spec/graphql/types/ci/runner_platform_type_spec.rb @@ -7,9 +7,9 @@ RSpec.describe Types::Ci::RunnerPlatformType do it 'exposes the expected fields' do expected_fields = %i[ - name - human_readable_name - architectures + name + human_readable_name + architectures ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/ci/variable_interface_spec.rb b/spec/graphql/types/ci/variable_interface_spec.rb index 8cef0ac2a14..328c5305a44 100644 --- a/spec/graphql/types/ci/variable_interface_spec.rb +++ b/spec/graphql/types/ci/variable_interface_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['CiVariable'] do specify do expect(described_class).to have_graphql_fields( - :id, :key, :value, :variable_type, :raw + :id, :key, :raw, :value, :variable_type ).at_least end end diff --git a/spec/graphql/types/clusters/agent_type_spec.rb b/spec/graphql/types/clusters/agent_type_spec.rb index 3f4faccf15d..bb1006c55c0 100644 --- a/spec/graphql/types/clusters/agent_type_spec.rb +++ b/spec/graphql/types/clusters/agent_type_spec.rb @@ -9,5 +9,5 @@ RSpec.describe GitlabSchema.types['ClusterAgent'] do it { expect(described_class).to require_graphql_authorizations(:read_cluster) } - it { expect(described_class).to have_graphql_fields(fields) } + it { expect(described_class).to include_graphql_fields(*fields) } end diff --git a/spec/graphql/types/customer_relations/organization_sort_enum_spec.rb b/spec/graphql/types/customer_relations/organization_sort_enum_spec.rb new file mode 100644 index 00000000000..7ff498f0097 --- /dev/null +++ b/spec/graphql/types/customer_relations/organization_sort_enum_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['OrganizationSort'] do + specify { expect(described_class.graphql_name).to eq('OrganizationSort') } + + it_behaves_like 'common sort values' + + it 'exposes all the contact sort values' do + expect(described_class.values.keys).to include( + *%w[ + NAME_ASC + NAME_DESC + DESCRIPTION_ASC + DESCRIPTION_DESC + DEFAULT_RATE_ASC + DEFAULT_RATE_DESC + ] + ) + end +end diff --git a/spec/graphql/types/customer_relations/organization_state_counts_type_spec.rb b/spec/graphql/types/customer_relations/organization_state_counts_type_spec.rb new file mode 100644 index 00000000000..a2c8dacb1a5 --- /dev/null +++ b/spec/graphql/types/customer_relations/organization_state_counts_type_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['OrganizationStateCounts'] do + include GraphqlHelpers + + let(:fields) do + %w[ + all + active + inactive + ] + end + + let(:object) do + { + 'inactive' => 3, + 'active' => 4 + } + end + + it { expect(described_class.graphql_name).to eq('OrganizationStateCounts') } + it { expect(described_class).to have_graphql_fields(fields) } + + describe '#all' do + it 'returns the sum of all counts' do + expect(resolve_field(:all, object)).to eq(7) + end + end +end diff --git a/spec/graphql/types/deployment_details_type_spec.rb b/spec/graphql/types/deployment_details_type_spec.rb new file mode 100644 index 00000000000..70fdc38019e --- /dev/null +++ b/spec/graphql/types/deployment_details_type_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['DeploymentDetails'] do + specify { expect(described_class.graphql_name).to eq('DeploymentDetails') } + + it 'has the expected fields' do + expected_fields = %w[ + id iid ref tag tags sha created_at updated_at finished_at status commit job triggerer + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end + + specify { expect(described_class).to require_graphql_authorizations(:read_deployment) } +end diff --git a/spec/graphql/types/deployment_type_spec.rb b/spec/graphql/types/deployment_type_spec.rb new file mode 100644 index 00000000000..bf4be0523c6 --- /dev/null +++ b/spec/graphql/types/deployment_type_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['Deployment'] do + specify { expect(described_class.graphql_name).to eq('Deployment') } + + it 'has the expected fields' do + expected_fields = %w[ + id iid ref tag sha created_at updated_at finished_at status commit job triggerer + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end + + specify { expect(described_class).to require_graphql_authorizations(:read_deployment) } +end diff --git a/spec/graphql/types/detployment_tag_type_spec.rb b/spec/graphql/types/detployment_tag_type_spec.rb new file mode 100644 index 00000000000..9a7a8db0970 --- /dev/null +++ b/spec/graphql/types/detployment_tag_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['DeploymentTag'] do + specify { expect(described_class.graphql_name).to eq('DeploymentTag') } + + it 'has the expected fields' do + expected_fields = %w[ + name path + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/environment_type_spec.rb b/spec/graphql/types/environment_type_spec.rb index 3671d35e8a5..ae58fe00af7 100644 --- a/spec/graphql/types/environment_type_spec.rb +++ b/spec/graphql/types/environment_type_spec.rb @@ -7,7 +7,8 @@ RSpec.describe GitlabSchema.types['Environment'] do it 'has the expected fields' do expected_fields = %w[ - name id state metrics_dashboard latest_opened_most_severe_alert path + name id state metrics_dashboard latest_opened_most_severe_alert path external_url deployments + slug createdAt updatedAt autoStopAt autoDeleteAt tier environmentType lastDeployment ] expect(described_class).to have_graphql_fields(*expected_fields) @@ -17,7 +18,7 @@ RSpec.describe GitlabSchema.types['Environment'] do context 'when there is an environment' do let_it_be(:project) { create(:project) } - let_it_be(:environment) { create(:environment, project: project) } + let_it_be(:environment) { create(:environment, project: project, external_url: 'https://gitlab.com') } let_it_be(:user) { create(:user) } subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } @@ -29,6 +30,7 @@ RSpec.describe GitlabSchema.types['Environment'] do environment(name: "#{environment.name}") { name path + externalUrl state } } @@ -50,6 +52,10 @@ RSpec.describe GitlabSchema.types['Environment'] do ) end + it 'returns the external url of the environment' do + expect(subject['data']['project']['environment']['externalUrl']).to eq(environment.external_url) + end + context 'when query alert data for the environment' do let_it_be(:query) do %( diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index 72b3bb90194..0b65778ce90 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -24,8 +24,9 @@ RSpec.describe GitlabSchema.types['Group'] do dependency_proxy_blobs dependency_proxy_image_count dependency_proxy_blob_count dependency_proxy_total_size dependency_proxy_image_prefix dependency_proxy_image_ttl_policy - shared_runners_setting timelogs organizations contacts contact_state_counts - work_item_types recent_issue_boards ci_variables + shared_runners_setting timelogs organization_state_counts organizations + contact_state_counts contacts work_item_types + recent_issue_boards ci_variables ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -62,6 +63,13 @@ RSpec.describe GitlabSchema.types['Group'] do it { is_expected.to have_graphql_resolver(Resolvers::Crm::ContactStateCountsResolver) } end + describe 'organization_state_counts field' do + subject { described_class.fields['organizationStateCounts'] } + + it { is_expected.to have_graphql_type(Types::CustomerRelations::OrganizationStateCountsType) } + it { is_expected.to have_graphql_resolver(Resolvers::Crm::OrganizationStateCountsResolver) } + end + it_behaves_like 'a GraphQL type with labels' do let(:labels_resolver_arguments) { [:search_term, :includeAncestorGroups, :includeDescendantGroups, :onlyGroupLabels] } end diff --git a/spec/graphql/types/merge_request_review_state_enum_spec.rb b/spec/graphql/types/merge_request_review_state_enum_spec.rb index 407a1ae3c1f..486e1c4f502 100644 --- a/spec/graphql/types/merge_request_review_state_enum_spec.rb +++ b/spec/graphql/types/merge_request_review_state_enum_spec.rb @@ -12,10 +12,6 @@ RSpec.describe GitlabSchema.types['MergeRequestReviewState'] do 'UNREVIEWED' => have_attributes( description: 'The merge request is unreviewed.', value: 'unreviewed' - ), - 'ATTENTION_REQUESTED' => have_attributes( - description: 'The merge request is attention_requested.', - value: 'attention_requested' ) ) end diff --git a/spec/graphql/types/metrics/dashboard_type_spec.rb b/spec/graphql/types/metrics/dashboard_type_spec.rb index 30dccc7c0be..114db87d5f1 100644 --- a/spec/graphql/types/metrics/dashboard_type_spec.rb +++ b/spec/graphql/types/metrics/dashboard_type_spec.rb @@ -7,8 +7,8 @@ RSpec.describe GitlabSchema.types['MetricsDashboard'] do it 'has the expected fields' do expected_fields = %w[ - path annotations schema_validation_warnings - ] + path annotations schema_validation_warnings + ] expect(described_class).to have_graphql_fields(*expected_fields) end diff --git a/spec/graphql/types/packages/composer/metadatum_type_spec.rb b/spec/graphql/types/packages/composer/metadatum_type_spec.rb index a950c10a41d..272d518cdd5 100644 --- a/spec/graphql/types/packages/composer/metadatum_type_spec.rb +++ b/spec/graphql/types/packages/composer/metadatum_type_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['ComposerMetadata'] do it 'includes composer metadatum fields' do expected_fields = %w[ - target_sha composer_json + target_sha composer_json ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/packages/package_type_enum_spec.rb b/spec/graphql/types/packages/package_type_enum_spec.rb index 9d5a7716a61..fb93b1c8c8a 100644 --- a/spec/graphql/types/packages/package_type_enum_spec.rb +++ b/spec/graphql/types/packages/package_type_enum_spec.rb @@ -4,6 +4,6 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['PackageTypeEnum'] do it 'exposes all package types' do - expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER GENERIC GOLANG DEBIAN RUBYGEMS HELM TERRAFORM_MODULE]) + expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER GENERIC GOLANG DEBIAN RUBYGEMS HELM TERRAFORM_MODULE RPM]) end end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 5ff7653ce39..617cbdb07fe 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -4,7 +4,6 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['Project'] do include GraphqlHelpers - include Ci::TemplateHelpers specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Project) } @@ -37,7 +36,7 @@ RSpec.describe GitlabSchema.types['Project'] do cluster_agent cluster_agents agent_configurations ci_template timelogs merge_commit_template squash_commit_template work_item_types recent_issue_boards ci_config_path_or_default packages_cleanup_policy ci_variables - timelog_categories fork_targets + timelog_categories fork_targets branch_rules ci_config_variables ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -509,6 +508,20 @@ RSpec.describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_resolver(Resolvers::Ci::JobTokenScopeResolver) } end + describe 'branch_rules field' do + subject { described_class.fields['branchRules'] } + + let(:br_resolver) { Resolvers::Projects::BranchRulesResolver } + + specify do + is_expected.to have_graphql_type( + Types::Projects::BranchRuleType.connection_type + ) + end + + specify { is_expected.to have_graphql_resolver(br_resolver) } + end + describe 'agent_configurations' do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } @@ -682,4 +695,54 @@ RSpec.describe GitlabSchema.types['Project'] do end end end + + describe 'branch_rules' do + let_it_be(:user) { create(:user) } + let_it_be(:project, reload: true) { create(:project, :public) } + let_it_be(:name) { 'feat/*' } + let_it_be(:protected_branch) do + create(:protected_branch, project: project, name: name) + end + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + branchRules { + nodes { + name + } + } + } + } + ) + end + + let(:branch_rules_data) do + subject.dig('data', 'project', 'branchRules', 'nodes') + end + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + context 'when a user can read protected branches' do + before do + project.add_maintainer(user) + end + + it 'is present and correct' do + expect(branch_rules_data.count).to eq(1) + expect(branch_rules_data.first['name']).to eq(name) + end + end + + context 'when a user cannot read protected branches' do + before do + project.add_guest(user) + end + + it 'is empty' do + expect(branch_rules_data.count).to eq(0) + end + end + end end diff --git a/spec/graphql/types/subscription_type_spec.rb b/spec/graphql/types/subscription_type_spec.rb index 9b043fa52cf..860cbbf0c15 100644 --- a/spec/graphql/types/subscription_type_spec.rb +++ b/spec/graphql/types/subscription_type_spec.rb @@ -10,8 +10,9 @@ RSpec.describe GitlabSchema.types['Subscription'] do issuable_title_updated issuable_labels_updated issuable_dates_updated + merge_request_reviewers_updated ] - expect(described_class).to have_graphql_fields(*expected_fields).only + expect(described_class).to include_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/timelog_type_spec.rb b/spec/graphql/types/timelog_type_spec.rb index c897a25d10d..3a26ba89e04 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_issue) } + it { expect(described_class).to require_graphql_authorizations(:read_issuable) } it { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Timelog) } describe 'user field' do diff --git a/spec/graphql/types/user_merge_request_interaction_type_spec.rb b/spec/graphql/types/user_merge_request_interaction_type_spec.rb index 4782a1faf8d..3cd9750debb 100644 --- a/spec/graphql/types/user_merge_request_interaction_type_spec.rb +++ b/spec/graphql/types/user_merge_request_interaction_type_spec.rb @@ -76,11 +76,8 @@ RSpec.describe GitlabSchema.types['UserMergeRequestInteraction'] do context 'when the user has been asked to review the MR' do before do merge_request.reviewers << user - merge_request.find_reviewer(user).update!(state: :attention_requested) end - it { is_expected.to eq(Types::MergeRequestReviewStateEnum.values['ATTENTION_REQUESTED'].value) } - it 'implies not reviewed' do expect(resolve(:reviewed)).to be false end diff --git a/spec/graphql/types/work_item_type_spec.rb b/spec/graphql/types/work_item_type_spec.rb index c556424b0b4..11b02a88dbd 100644 --- a/spec/graphql/types/work_item_type_spec.rb +++ b/spec/graphql/types/work_item_type_spec.rb @@ -28,8 +28,6 @@ RSpec.describe GitlabSchema.types['WorkItem'] do closed_at ] - fields.each do |field_name| - expect(described_class).to have_graphql_fields(*fields) - end + expect(described_class).to have_graphql_fields(*fields) end end diff --git a/spec/graphql/types/work_items/widgets/description_type_spec.rb b/spec/graphql/types/work_items/widgets/description_type_spec.rb index 5ade1fe4aa2..aee388ce82a 100644 --- a/spec/graphql/types/work_items/widgets/description_type_spec.rb +++ b/spec/graphql/types/work_items/widgets/description_type_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe Types::WorkItems::Widgets::DescriptionType do it 'exposes the expected fields' do - expected_fields = %i[description description_html type] + expected_fields = %i[description description_html edited last_edited_at last_edited_by type] expect(described_class).to have_graphql_fields(*expected_fields) end |