diff options
Diffstat (limited to 'spec/graphql')
32 files changed, 439 insertions, 53 deletions
diff --git a/spec/graphql/mutations/namespace/package_settings/update_spec.rb b/spec/graphql/mutations/namespace/package_settings/update_spec.rb new file mode 100644 index 00000000000..bd0d38cb49f --- /dev/null +++ b/spec/graphql/mutations/namespace/package_settings/update_spec.rb @@ -0,0 +1,98 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Namespace::PackageSettings::Update do + using RSpec::Parameterized::TableSyntax + + let_it_be_with_reload(:namespace) { create(:group) } + let_it_be(:user) { create(:user) } + + let(:params) { { namespace_path: namespace.full_path } } + + specify { expect(described_class).to require_graphql_authorizations(:create_package_settings) } + + describe '#resolve' do + subject { described_class.new(object: namespace, context: { current_user: user }, field: nil).resolve(**params) } + + RSpec.shared_examples 'returning a success' do + it 'returns the namespace package setting with no errors' do + expect(subject).to eq( + package_settings: package_settings, + errors: [] + ) + end + end + + RSpec.shared_examples 'updating the namespace package setting' do + it_behaves_like 'updating the namespace package setting attributes', from: { maven_duplicates_allowed: true, maven_duplicate_exception_regex: 'SNAPSHOT' }, to: { maven_duplicates_allowed: false, maven_duplicate_exception_regex: 'RELEASE' } + + it_behaves_like 'returning a success' + + context 'with invalid params' do + let_it_be(:params) { { namespace_path: namespace.full_path, maven_duplicate_exception_regex: '[' } } + + it_behaves_like 'not creating the namespace package setting' + + it 'doesn\'t update the maven_duplicates_allowed' do + expect { subject } + .not_to change { package_settings.reload.maven_duplicates_allowed } + end + + it 'returns an error' do + expect(subject).to eq( + package_settings: nil, + errors: ['Maven duplicate exception regex not valid RE2 syntax: missing ]: ['] + ) + end + end + end + + RSpec.shared_examples 'denying access to namespace package setting' do + it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + + context 'with existing namespace package setting' do + let_it_be(:package_settings) { create(:namespace_package_setting, namespace: namespace) } + let_it_be(:params) { { namespace_path: namespace.full_path, maven_duplicates_allowed: false, maven_duplicate_exception_regex: 'RELEASE' } } + + where(:user_role, :shared_examples_name) do + :maintainer | 'updating the namespace package setting' + :developer | 'updating the namespace package setting' + :reporter | 'denying access to namespace package setting' + :guest | 'denying access to namespace package setting' + :anonymous | 'denying access to namespace package setting' + end + + with_them do + before do + namespace.send("add_#{user_role}", user) unless user_role == :anonymous + end + + it_behaves_like params[:shared_examples_name] + end + end + + context 'without existing namespace package setting' do + let_it_be(:package_settings) { namespace.package_settings } + + where(:user_role, :shared_examples_name) do + :maintainer | 'creating the namespace package setting' + :developer | 'creating the namespace package setting' + :reporter | 'denying access to namespace package setting' + :guest | 'denying access to namespace package setting' + :anonymous | 'denying access to namespace package setting' + end + + with_them do + before do + namespace.send("add_#{user_role}", user) unless user_role == :anonymous + end + + it_behaves_like params[:shared_examples_name] + end + end + end +end diff --git a/spec/graphql/mutations/releases/create_spec.rb b/spec/graphql/mutations/releases/create_spec.rb index d6305691dac..7776f968346 100644 --- a/spec/graphql/mutations/releases/create_spec.rb +++ b/spec/graphql/mutations/releases/create_spec.rb @@ -88,12 +88,9 @@ RSpec.describe Mutations::Releases::Create do it 'creates the release with the correct milestone associations' do expected_milestone_titles = [milestone_12_3.title, milestone_12_4.title] - actual_milestone_titles = new_release.milestones.map { |m| m.title } + actual_milestone_titles = new_release.milestones.order_by_dates_and_title.map { |m| m.title } - # Right now the milestones are returned in a non-deterministic order. - # `match_array` should be updated to `eq` once - # https://gitlab.com/gitlab-org/gitlab/-/issues/259012 is addressed. - expect(actual_milestone_titles).to match_array(expected_milestone_titles) + expect(actual_milestone_titles).to eq(expected_milestone_titles) end describe 'asset links' do diff --git a/spec/graphql/mutations/releases/update_spec.rb b/spec/graphql/mutations/releases/update_spec.rb index 0406e9c96f3..c541afd53a1 100644 --- a/spec/graphql/mutations/releases/update_spec.rb +++ b/spec/graphql/mutations/releases/update_spec.rb @@ -48,12 +48,7 @@ RSpec.describe Mutations::Releases::Update do expect(updated_release.name).to eq(name) unless except_for == :name expect(updated_release.description).to eq(description) unless except_for == :description expect(updated_release.released_at).to eq(released_at) unless except_for == :released_at - - # Right now the milestones are returned in a non-deterministic order. - # Because of this, we need to allow for milestones to be returned in any order. - # Once https://gitlab.com/gitlab-org/gitlab/-/issues/259012 has been - # fixed, this can be updated to expect a specific order. - expect(updated_release.milestones).to match_array([milestone_12_3, milestone_12_4]) unless except_for == :milestones + expect(updated_release.milestones.order_by_dates_and_title).to eq([milestone_12_3, milestone_12_4]) unless except_for == :milestones end end diff --git a/spec/graphql/resolvers/ci/config_resolver_spec.rb b/spec/graphql/resolvers/ci/config_resolver_spec.rb index 6911acdb4ec..ca7ae73fef8 100644 --- a/spec/graphql/resolvers/ci/config_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/config_resolver_spec.rb @@ -7,16 +7,26 @@ RSpec.describe Resolvers::Ci::ConfigResolver do describe '#resolve' do before do - yaml_processor_double = instance_double(::Gitlab::Ci::YamlProcessor) - allow(yaml_processor_double).to receive(:execute).and_return(fake_result) + ci_lint_double = instance_double(::Gitlab::Ci::Lint) + allow(ci_lint_double).to receive(:validate).and_return(fake_result) - allow(::Gitlab::Ci::YamlProcessor).to receive(:new).and_return(yaml_processor_double) + allow(::Gitlab::Ci::Lint).to receive(:new).and_return(ci_lint_double) + end + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) } + + subject(:response) do + resolve(described_class, + args: { project_path: project.full_path, content: content }, + ctx: { current_user: user }) end context 'with a valid .gitlab-ci.yml' do let(:fake_result) do - ::Gitlab::Ci::YamlProcessor::Result.new( - ci_config: ::Gitlab::Ci::Config.new(content), + ::Gitlab::Ci::Lint::Result.new( + merged_yaml: content, + jobs: [], errors: [], warnings: [] ) @@ -27,8 +37,6 @@ RSpec.describe Resolvers::Ci::ConfigResolver do end it 'lints the ci config file' do - response = resolve(described_class, args: { content: content }, ctx: {}) - expect(response[:status]).to eq(:valid) expect(response[:errors]).to be_empty end @@ -38,16 +46,15 @@ RSpec.describe Resolvers::Ci::ConfigResolver do let(:content) { 'invalid' } let(:fake_result) do - Gitlab::Ci::YamlProcessor::Result.new( - ci_config: nil, + Gitlab::Ci::Lint::Result.new( + jobs: [], + merged_yaml: content, errors: ['Invalid configuration format'], warnings: [] ) end it 'responds with errors about invalid syntax' do - response = resolve(described_class, args: { content: content }, ctx: {}) - expect(response[:status]).to eq(:invalid) expect(response[:errors]).to eq(['Invalid configuration format']) end diff --git a/spec/graphql/resolvers/ci/jobs_resolver_spec.rb b/spec/graphql/resolvers/ci/jobs_resolver_spec.rb index 46ee74a5f7e..c44f6b623d7 100644 --- a/spec/graphql/resolvers/ci/jobs_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/jobs_resolver_spec.rb @@ -5,7 +5,8 @@ require 'spec_helper' RSpec.describe Resolvers::Ci::JobsResolver do include GraphqlHelpers - let_it_be(:pipeline) { create(:ci_pipeline) } + let_it_be(:project) { create(:project, :repository, :public) } + let_it_be(:pipeline) { create(:ci_pipeline, project: project) } before_all do create(:ci_build, name: 'Normal job', pipeline: pipeline) diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb index f6f746a8572..269ee9eabf9 100644 --- a/spec/graphql/resolvers/issues_resolver_spec.rb +++ b/spec/graphql/resolvers/issues_resolver_spec.rb @@ -264,13 +264,13 @@ RSpec.describe Resolvers::IssuesResolver do end it 'finds a specific issue with iid', :request_store do - result = batch_sync(max_queries: 2) { resolve_issues(iid: issue1.iid) } + result = batch_sync(max_queries: 4) { resolve_issues(iid: issue1.iid) } expect(result).to contain_exactly(issue1) end it 'batches queries that only include IIDs', :request_store do - result = batch_sync(max_queries: 2) do + result = batch_sync(max_queries: 4) do [issue1, issue2] .map { |issue| resolve_issues(iid: issue.iid.to_s) } .flat_map(&:to_a) @@ -280,7 +280,7 @@ RSpec.describe Resolvers::IssuesResolver do end it 'finds a specific issue with iids', :request_store do - result = batch_sync(max_queries: 2) do + result = batch_sync(max_queries: 4) do resolve_issues(iids: [issue1.iid]) end diff --git a/spec/graphql/resolvers/merge_requests_resolver_spec.rb b/spec/graphql/resolvers/merge_requests_resolver_spec.rb index 63fbd04848d..50b9243efa5 100644 --- a/spec/graphql/resolvers/merge_requests_resolver_spec.rb +++ b/spec/graphql/resolvers/merge_requests_resolver_spec.rb @@ -231,6 +231,16 @@ RSpec.describe Resolvers::MergeRequestsResolver do it 'sorts merge requests descending' do expect(resolve_mr(project, sort: :merged_at_desc)).to eq [merge_request_3, merge_request_1, merge_request_with_milestone, merge_request_6, merge_request_5, merge_request_4, merge_request_2] end + + context 'when label filter is given and the optimized_issuable_label_filter feature flag is off' do + before do + stub_feature_flags(optimized_issuable_label_filter: false) + end + + it 'does not raise PG::GroupingError' do + expect { resolve_mr(project, sort: :merged_at_desc, labels: %w[a b]) }.not_to raise_error + end + end end end end diff --git a/spec/graphql/resolvers/package_details_resolver_spec.rb b/spec/graphql/resolvers/package_details_resolver_spec.rb new file mode 100644 index 00000000000..825b2aed40a --- /dev/null +++ b/spec/graphql/resolvers/package_details_resolver_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::PackageDetailsResolver do + include GraphqlHelpers + + let_it_be_with_reload(:project) { create(:project) } + let_it_be(:user) { project.owner } + let_it_be(:package) { create(:composer_package, project: project) } + + describe '#resolve' do + let(:args) do + { id: package.to_global_id.to_s } + end + + subject { resolve(described_class, ctx: { current_user: user }, args: args).sync } + + it { is_expected.to eq(package) } + end +end diff --git a/spec/graphql/resolvers/projects_resolver_spec.rb b/spec/graphql/resolvers/projects_resolver_spec.rb index 3de54c7e410..34ddc9cd8cb 100644 --- a/spec/graphql/resolvers/projects_resolver_spec.rb +++ b/spec/graphql/resolvers/projects_resolver_spec.rb @@ -129,7 +129,7 @@ RSpec.describe Resolvers::ProjectsResolver do let(:filters) { { search: 'projA', sort: 'similarity' } } it 'returns projects in order of similarity to search' do - stub_feature_flags(project_finder_similarity_sort: true) + stub_feature_flags(project_finder_similarity_sort: current_user) is_expected.to eq([named_project3, named_project1, named_project2]) end diff --git a/spec/graphql/resolvers/release_milestones_resolver_spec.rb b/spec/graphql/resolvers/release_milestones_resolver_spec.rb new file mode 100644 index 00000000000..5f66cba859d --- /dev/null +++ b/spec/graphql/resolvers/release_milestones_resolver_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::ReleaseMilestonesResolver do + include GraphqlHelpers + + let_it_be(:release) { create(:release, :with_milestones, milestones_count: 2) } + + let(:resolved) do + resolve(described_class, obj: release) + end + + describe '#resolve' do + it "returns an OffsetActiveRecordRelationConnection" do + expect(resolved).to be_a(::Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection) + end + + it "includes the release's milestones in the returned OffsetActiveRecordRelationConnection" do + expect(resolved.items).to eq(release.milestones.order_by_dates_and_title) + end + end +end diff --git a/spec/graphql/resolvers/user_notes_count_resolver_spec.rb b/spec/graphql/resolvers/user_notes_count_resolver_spec.rb index 3cb0810c698..6cf23a2f57f 100644 --- a/spec/graphql/resolvers/user_notes_count_resolver_spec.rb +++ b/spec/graphql/resolvers/user_notes_count_resolver_spec.rb @@ -44,7 +44,7 @@ RSpec.describe Resolvers::UserNotesCountResolver do context 'when a user does not have permission to view notes' do subject { batch_sync { resolve_user_notes_count(private_issue) } } - it 'returns no notes' do + it 'raises an error' do expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) end end @@ -80,7 +80,7 @@ RSpec.describe Resolvers::UserNotesCountResolver do context 'when a user does not have permission to view notes' do subject { batch_sync { resolve_user_notes_count(private_merge_request) } } - it 'returns no notes' do + it 'raises an error' do expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) end end diff --git a/spec/graphql/resolvers/users_resolver_spec.rb b/spec/graphql/resolvers/users_resolver_spec.rb index 1aa24055a89..031d7c99eef 100644 --- a/spec/graphql/resolvers/users_resolver_spec.rb +++ b/spec/graphql/resolvers/users_resolver_spec.rb @@ -27,7 +27,7 @@ RSpec.describe Resolvers::UsersResolver do context 'when both ids and usernames are passed ' do it 'raises an error' do - expect { resolve_users(ids: [user1.to_global_id.to_s], usernames: [user1.username]) } + expect { resolve_users( args: { ids: [user1.to_global_id.to_s], usernames: [user1.username] } ) } .to raise_error(Gitlab::Graphql::Errors::ArgumentError) end end @@ -35,7 +35,7 @@ RSpec.describe Resolvers::UsersResolver do context 'when a set of IDs is passed' do it 'returns those users' do expect( - resolve_users(ids: [user1.to_global_id.to_s, user2.to_global_id.to_s]) + resolve_users( args: { ids: [user1.to_global_id.to_s, user2.to_global_id.to_s] } ) ).to contain_exactly(user1, user2) end end @@ -43,21 +43,31 @@ RSpec.describe Resolvers::UsersResolver do context 'when a set of usernames is passed' do it 'returns those users' do expect( - resolve_users(usernames: [user1.username, user2.username]) + resolve_users( args: { usernames: [user1.username, user2.username] } ) ).to contain_exactly(user1, user2) end end + context 'when admins is true', :enable_admin_mode do + let(:admin_user) { create(:user, :admin) } + + it 'returns only admins' do + expect( + resolve_users( args: { admins: true }, ctx: { current_user: admin_user } ) + ).to contain_exactly(admin_user) + end + end + context 'when a search term is passed' do it 'returns all users who match', :aggregate_failures do - expect(resolve_users(search: "some")).to contain_exactly(user1, user2) - expect(resolve_users(search: "123784")).to contain_exactly(user2) - expect(resolve_users(search: "someperson")).to contain_exactly(user1) + expect(resolve_users( args: { search: "some" } )).to contain_exactly(user1, user2) + expect(resolve_users( args: { search: "123784" } )).to contain_exactly(user2) + expect(resolve_users( args: { search: "someperson" } )).to contain_exactly(user1) end end end - def resolve_users(args = {}) - resolve(described_class, args: args) + def resolve_users(args: {}, ctx: {}) + resolve(described_class, args: args, ctx: ctx) end end diff --git a/spec/graphql/types/admin/analytics/instance_statistics/measurement_type_spec.rb b/spec/graphql/types/admin/analytics/instance_statistics/measurement_type_spec.rb index de8143a5466..ffb1a0f30c9 100644 --- a/spec/graphql/types/admin/analytics/instance_statistics/measurement_type_spec.rb +++ b/spec/graphql/types/admin/analytics/instance_statistics/measurement_type_spec.rb @@ -8,4 +8,48 @@ RSpec.describe GitlabSchema.types['InstanceStatisticsMeasurement'] do it { is_expected.to have_graphql_field(:recorded_at) } it { is_expected.to have_graphql_field(:identifier) } it { is_expected.to have_graphql_field(:count) } + + describe 'authorization' do + let_it_be(:measurement) { create(:instance_statistics_measurement, :project_count) } + let(:user) { create(:user) } + + let(:query) do + <<~GRAPHQL + query instanceStatisticsMeasurements($identifier: MeasurementIdentifier!) { + instanceStatisticsMeasurements(identifier: $identifier) { + nodes { + count + identifier + } + } + } + GRAPHQL + end + + subject do + GitlabSchema.execute( + query, + variables: { identifier: 'PROJECTS' }, + context: { current_user: user } + ).to_h + end + + context 'when the user is not admin' do + it 'returns no data' do + expect(subject.dig('data', 'instanceStatisticsMeasurements')).to be_nil + end + end + + context 'when user is an admin' do + let(:user) { create(:user, :admin) } + + before do + stub_feature_flags(user_mode_in_session: false) + end + + it 'returns data' do + expect(subject.dig('data', 'instanceStatisticsMeasurements', 'nodes')).not_to be_empty + end + end + end end diff --git a/spec/graphql/types/base_enum_spec.rb b/spec/graphql/types/base_enum_spec.rb index b7adcf217f6..744aee40044 100644 --- a/spec/graphql/types/base_enum_spec.rb +++ b/spec/graphql/types/base_enum_spec.rb @@ -3,7 +3,75 @@ require 'spec_helper' RSpec.describe Types::BaseEnum do - describe '#enum' do + describe '.declarative_enum' do + let(:use_name) { true } + let(:use_description) { true } + let(:enum_type) do + Class.new(described_class) do + graphql_name 'OriginalName' + description 'Original description' + end + end + + let(:enum_module) do + Module.new do + extend DeclarativeEnum + + name 'Name' + description 'Description' + + define do + foo value: 0, description: 'description of foo' + end + end + end + + subject(:set_declarative_enum) { enum_type.declarative_enum(enum_module, use_name: use_name, use_description: use_description) } + + describe '#graphql_name' do + context 'when the use_name is `true`' do + it 'changes the graphql_name' do + expect { set_declarative_enum }.to change { enum_type.graphql_name }.from('OriginalName').to('Name') + end + end + + context 'when the use_name is `false`' do + let(:use_name) { false } + + it 'does not change the graphql_name' do + expect { set_declarative_enum }.not_to change { enum_type.graphql_name }.from('OriginalName') + end + end + end + + describe '#description' do + context 'when the use_description is `true`' do + it 'changes the description' do + expect { set_declarative_enum }.to change { enum_type.description }.from('Original description').to('Description') + end + end + + context 'when the use_description is `false`' do + let(:use_description) { false } + + it 'does not change the description' do + expect { set_declarative_enum }.not_to change { enum_type.description }.from('Original description') + end + end + end + + describe '#values' do + it 'sets the values defined by the declarative enum' do + set_declarative_enum + + expect(enum_type.values.keys).to eq(['FOO']) + expect(enum_type.values.values.map(&:description)).to eq(['description of foo']) + expect(enum_type.values.values.map(&:value)).to eq([0]) + end + end + end + + describe '.enum' do let(:enum) do Class.new(described_class) do value 'TEST', value: 3 diff --git a/spec/graphql/types/board_type_spec.rb b/spec/graphql/types/board_type_spec.rb index b02b342390d..5ea87d5f473 100644 --- a/spec/graphql/types/board_type_spec.rb +++ b/spec/graphql/types/board_type_spec.rb @@ -8,7 +8,7 @@ RSpec.describe GitlabSchema.types['Board'] do specify { expect(described_class).to require_graphql_authorizations(:read_board) } it 'has specific fields' do - expected_fields = %w[id name] + expected_fields = %w[id name web_url web_path] expect(described_class).to include_graphql_fields(*expected_fields) end diff --git a/spec/graphql/types/ci/config/job_restriction_type_spec.rb b/spec/graphql/types/ci/config/job_restriction_type_spec.rb new file mode 100644 index 00000000000..dd46a38b7c2 --- /dev/null +++ b/spec/graphql/types/ci/config/job_restriction_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::JobRestrictionType do + specify { expect(described_class.graphql_name).to eq('CiConfigJobRestriction') } + + it 'exposes the expected fields' do + expected_fields = %i[refs] + + expect(described_class).to include_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 index 600d665a84b..de4e167f69c 100644 --- a/spec/graphql/types/ci/config/job_type_spec.rb +++ b/spec/graphql/types/ci/config/job_type_spec.rb @@ -7,10 +7,19 @@ RSpec.describe Types::Ci::Config::JobType do it 'exposes the expected fields' do expected_fields = %i[ + afterScript + allowFailure + beforeScript + environment + except + script name + only group_name stage + tags needs + when ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/ci/job_type_spec.rb b/spec/graphql/types/ci/job_type_spec.rb index 441a719df8c..e277916f5cb 100644 --- a/spec/graphql/types/ci/job_type_spec.rb +++ b/spec/graphql/types/ci/job_type_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe Types::Ci::JobType do specify { expect(described_class.graphql_name).to eq('CiJob') } + specify { expect(described_class).to require_graphql_authorizations(:read_commit_status) } it 'exposes the expected fields' do expected_fields = %i[ diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb index 558fc479af1..21fc530149c 100644 --- a/spec/graphql/types/issue_type_spec.rb +++ b/spec/graphql/types/issue_type_spec.rb @@ -17,7 +17,8 @@ RSpec.describe GitlabSchema.types['Issue'] do fields = %i[id iid title description state reference author assignees updated_by participants labels milestone due_date confidential discussion_locked upvotes downvotes user_notes_count user_discussions_count web_path web_url relative_position emails_disabled subscribed time_estimate total_time_spent human_time_estimate human_total_time_spent closed_at created_at updated_at task_completion_status - design_collection alert_management_alert severity current_user_todos moved moved_to] + design_collection alert_management_alert severity current_user_todos moved moved_to + create_note_email] fields.each do |field_name| expect(described_class).to have_graphql_field(field_name) diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 51e7b4029d5..63d288934e5 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -25,21 +25,15 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do merge_ongoing mergeable_discussions_state web_url source_branch_exists target_branch_exists upvotes downvotes head_pipeline pipelines task_completion_status - milestone assignees participants subscribed labels discussion_locked time_estimate + 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 default_merge_commit_message_with_description squash_on_merge available_auto_merge_strategies - has_ci mergeable commits_without_merge_commits security_auto_fix + has_ci mergeable commits_without_merge_commits squash security_auto_fix default_squash_commit_message + auto_merge_strategy merge_user ] - 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) + expect(described_class).to have_graphql_fields(*expected_fields).at_least end describe '#pipelines' do diff --git a/spec/graphql/types/namespace/package_settings_type_spec.rb b/spec/graphql/types/namespace/package_settings_type_spec.rb new file mode 100644 index 00000000000..b9592d230ca --- /dev/null +++ b/spec/graphql/types/namespace/package_settings_type_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageSettings'] do + specify { expect(described_class.graphql_name).to eq('PackageSettings') } + + specify { expect(described_class.description).to eq('Namespace-level Package Registry settings') } + + specify { expect(described_class).to require_graphql_authorizations(:read_package_settings) } + + describe 'maven_duplicate_exception_regex field' do + subject { described_class.fields['mavenDuplicateExceptionRegex'] } + + it { is_expected.to have_graphql_type(Types::UntrustedRegexp) } + end +end diff --git a/spec/graphql/types/notes/note_type_spec.rb b/spec/graphql/types/notes/note_type_spec.rb index 180d13d35d2..03ff7828cf5 100644 --- a/spec/graphql/types/notes/note_type_spec.rb +++ b/spec/graphql/types/notes/note_type_spec.rb @@ -22,6 +22,7 @@ RSpec.describe GitlabSchema.types['Note'] do system_note_icon_name updated_at user_permissions + url ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/packages/composer/details_type_spec.rb b/spec/graphql/types/packages/composer/details_type_spec.rb new file mode 100644 index 00000000000..2e4cb965ded --- /dev/null +++ b/spec/graphql/types/packages/composer/details_type_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageComposerDetails'] do + it { expect(described_class.graphql_name).to eq('PackageComposerDetails') } + + it 'includes all the package fields' do + expected_fields = %w[ + id name version created_at updated_at package_type tags project pipelines versions + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end + + it 'includes composer specific files' do + expected_fields = %w[ + composer_metadatum + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/packages/composer/json_type_spec.rb b/spec/graphql/types/packages/composer/json_type_spec.rb new file mode 100644 index 00000000000..af5194ffb49 --- /dev/null +++ b/spec/graphql/types/packages/composer/json_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageComposerJsonType'] do + it { expect(described_class.graphql_name).to eq('PackageComposerJsonType') } + + it 'includes composer json files' do + expected_fields = %w[ + name type license version + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/packages/composer/metadatum_type_spec.rb b/spec/graphql/types/packages/composer/metadatum_type_spec.rb new file mode 100644 index 00000000000..0f47d8f1812 --- /dev/null +++ b/spec/graphql/types/packages/composer/metadatum_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageComposerMetadatumType'] do + it { expect(described_class.graphql_name).to eq('PackageComposerMetadatumType') } + + it 'includes composer metadatum fields' do + expected_fields = %w[ + target_sha composer_json + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/package_type_enum_spec.rb b/spec/graphql/types/packages/package_type_enum_spec.rb index 407d5786f65..407d5786f65 100644 --- a/spec/graphql/types/package_type_enum_spec.rb +++ b/spec/graphql/types/packages/package_type_enum_spec.rb diff --git a/spec/graphql/types/package_type_spec.rb b/spec/graphql/types/packages/package_type_spec.rb index 22048e7a693..7003a4d4d07 100644 --- a/spec/graphql/types/package_type_spec.rb +++ b/spec/graphql/types/packages/package_type_spec.rb @@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['Package'] do it 'includes all the package fields' do expected_fields = %w[ - id name version created_at updated_at package_type + id name version created_at updated_at package_type tags project pipelines versions ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/packages/tag_type_spec.rb b/spec/graphql/types/packages/tag_type_spec.rb new file mode 100644 index 00000000000..83b705157d8 --- /dev/null +++ b/spec/graphql/types/packages/tag_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageTag'] do + it { expect(described_class.graphql_name).to eq('PackageTag') } + + it 'includes all the package tag fields' do + expected_fields = %w[ + id name created_at updated_at + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index b3028e034cc..9d0d7a3918a 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -31,7 +31,7 @@ RSpec.describe GitlabSchema.types['Project'] do 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 + pipeline_analytics squash_read_only ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/projects/service_type_spec.rb b/spec/graphql/types/projects/service_type_spec.rb index f110322ac89..cca7c49e132 100644 --- a/spec/graphql/types/projects/service_type_spec.rb +++ b/spec/graphql/types/projects/service_type_spec.rb @@ -9,7 +9,7 @@ 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(:alerts_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) end end diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 7a0b3035607..3e716865e56 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -94,4 +94,10 @@ RSpec.describe GitlabSchema.types['Query'] do it { is_expected.to have_graphql_type(Types::ContainerRepositoryDetailsType) } end + + describe 'package_composer_details field' do + subject { described_class.fields['packageComposerDetails'] } + + it { is_expected.to have_graphql_type(Types::Packages::Composer::DetailsType) } + end end diff --git a/spec/graphql/types/repository_type_spec.rb b/spec/graphql/types/repository_type_spec.rb index 27780476421..e9199bd286e 100644 --- a/spec/graphql/types/repository_type_spec.rb +++ b/spec/graphql/types/repository_type_spec.rb @@ -10,4 +10,6 @@ RSpec.describe GitlabSchema.types['Repository'] do specify { expect(described_class).to have_graphql_field(:root_ref) } specify { expect(described_class).to have_graphql_field(:tree) } + + specify { expect(described_class).to have_graphql_field(:exists, calls_gitaly?: true, complexity: 2) } end |