diff options
Diffstat (limited to 'spec/graphql')
21 files changed, 206 insertions, 26 deletions
diff --git a/spec/graphql/graphql_triggers_spec.rb b/spec/graphql/graphql_triggers_spec.rb index 2d83edca363..84af33a5cb3 100644 --- a/spec/graphql/graphql_triggers_spec.rb +++ b/spec/graphql/graphql_triggers_spec.rb @@ -31,4 +31,20 @@ RSpec.describe GraphqlTriggers do GraphqlTriggers.issuable_title_updated(work_item) end end + + describe '.issuable_labels_updated' do + it 'triggers the issuableLabelsUpdated subscription' do + project = create(:project) + labels = create_list(:label, 3, project: project) + issue = create(:issue, labels: labels) + + expect(GitlabSchema.subscriptions).to receive(:trigger).with( + 'issuableLabelsUpdated', + { issuable_id: issue.to_gid }, + issue + ) + + GraphqlTriggers.issuable_labels_updated(issue) + end + end end diff --git a/spec/graphql/mutations/ci/runner/delete_spec.rb b/spec/graphql/mutations/ci/runner/delete_spec.rb index c0f979e43cc..ee640b21918 100644 --- a/spec/graphql/mutations/ci/runner/delete_spec.rb +++ b/spec/graphql/mutations/ci/runner/delete_spec.rb @@ -37,7 +37,9 @@ RSpec.describe Mutations::Ci::Runner::Delete do it 'raises an error' do mutation_params[:id] = two_projects_runner.to_global_id - expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do + subject + end end end end @@ -115,7 +117,10 @@ RSpec.describe Mutations::Ci::Runner::Delete do allow_next_instance_of(::Ci::Runners::UnregisterRunnerService) do |service| expect(service).not_to receive(:execute) end - expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + + expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do + subject + end end end end diff --git a/spec/graphql/mutations/environments/canary_ingress/update_spec.rb b/spec/graphql/mutations/environments/canary_ingress/update_spec.rb index 48e55828a6b..fdf9cbaf25b 100644 --- a/spec/graphql/mutations/environments/canary_ingress/update_spec.rb +++ b/spec/graphql/mutations/environments/canary_ingress/update_spec.rb @@ -36,6 +36,20 @@ RSpec.describe Mutations::Environments::CanaryIngress::Update do it 'returns no errors' do expect(subject[:errors]).to be_empty end + + context 'with certificate_based_clusters disabled' do + before do + stub_feature_flags(certificate_based_clusters: false) + end + + it 'returns notice about feature removal' do + expect(subject[:errors]).to match_array([ + 'This endpoint was deactivated as part of the certificate-based' \ + 'kubernetes integration removal. See Epic:' \ + 'https://gitlab.com/groups/gitlab-org/configure/-/epics/8' + ]) + end + end end context 'when service encounters a problem' do diff --git a/spec/graphql/mutations/saved_replies/destroy_spec.rb b/spec/graphql/mutations/saved_replies/destroy_spec.rb new file mode 100644 index 00000000000..6cff28ec0b2 --- /dev/null +++ b/spec/graphql/mutations/saved_replies/destroy_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::SavedReplies::Destroy do + let_it_be(:current_user) { create(:user) } + let_it_be(:saved_reply) { create(:saved_reply, user: current_user) } + + let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) } + + describe '#resolve' do + subject(:resolve) do + mutation.resolve(id: saved_reply.to_global_id) + end + + context 'when feature is disabled' do + before do + stub_feature_flags(saved_replies: false) + end + + it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled') + end + end + + context 'when feature is enabled for current user' do + before do + stub_feature_flags(saved_replies: current_user) + end + + context 'when service fails to delete a new saved reply' do + before do + saved_reply.destroy! + end + + it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + + context 'when service successfully deletes the saved reply' do + it { expect(subject[:errors]).to be_empty } + end + end + end +end diff --git a/spec/graphql/resolvers/blobs_resolver_spec.rb b/spec/graphql/resolvers/blobs_resolver_spec.rb index 4b75351147c..a666ed2a9fc 100644 --- a/spec/graphql/resolvers/blobs_resolver_spec.rb +++ b/spec/graphql/resolvers/blobs_resolver_spec.rb @@ -75,10 +75,9 @@ RSpec.describe Resolvers::BlobsResolver do let(:ref) { 'ma:in' } it 'raises an ArgumentError' do - expect { resolve_blobs }.to raise_error( - Gitlab::Graphql::Errors::ArgumentError, - 'Ref is not valid' - ) + expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Ref is not valid') do + resolve_blobs + end end end @@ -86,10 +85,9 @@ RSpec.describe Resolvers::BlobsResolver do let(:ref) { '' } it 'raises an ArgumentError' do - expect { resolve_blobs }.to raise_error( - Gitlab::Graphql::Errors::ArgumentError, - 'Ref is not valid' - ) + expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Ref is not valid') do + resolve_blobs + end end end end diff --git a/spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb b/spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb index fcf67120b0e..8d0b8f9398d 100644 --- a/spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb +++ b/spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb @@ -35,7 +35,9 @@ RSpec.describe Resolvers::GroupMembers::NotificationEmailResolver do let(:current_user) { create(:user) } it 'raises ResourceNotAvailable error' do - expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do + subject + end end end end diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb index 5e9a3d0a68b..81aeee0a3d2 100644 --- a/spec/graphql/resolvers/issues_resolver_spec.rb +++ b/spec/graphql/resolvers/issues_resolver_spec.rb @@ -522,11 +522,53 @@ RSpec.describe Resolvers::IssuesResolver do end end + context 'when sorting by escalation status' do + let_it_be(:project) { create(:project, :public) } + let_it_be(:triggered_incident) { create(:incident, :with_escalation_status, project: project) } + let_it_be(:issue_no_status) { create(:issue, project: project) } + let_it_be(:resolved_incident) do + create(:incident, :with_escalation_status, project: project) + .tap { |issue| issue.escalation_status.resolve } + end + + it 'sorts issues ascending' do + issues = resolve_issues(sort: :escalation_status_asc).to_a + expect(issues).to eq([triggered_incident, resolved_incident, issue_no_status]) + end + + it 'sorts issues descending' do + issues = resolve_issues(sort: :escalation_status_desc).to_a + expect(issues).to eq([resolved_incident, triggered_incident, issue_no_status]) + end + + it 'sorts issues created_at' do + issues = resolve_issues(sort: :created_desc).to_a + expect(issues).to eq([resolved_incident, issue_no_status, triggered_incident]) + end + + context 'when incident_escalations feature flag is disabled' do + before do + stub_feature_flags(incident_escalations: false) + end + + it 'defaults ascending status sort to created_desc' do + issues = resolve_issues(sort: :escalation_status_asc).to_a + expect(issues).to eq([resolved_incident, issue_no_status, triggered_incident]) + end + + it 'defaults descending status sort to created_desc' do + issues = resolve_issues(sort: :escalation_status_desc).to_a + expect(issues).to eq([resolved_incident, issue_no_status, triggered_incident]) + end + end + end + context 'when sorting with non-stable cursors' do %i[priority_asc priority_desc popularity_asc popularity_desc label_priority_asc label_priority_desc - milestone_due_asc milestone_due_desc].each do |sort_by| + milestone_due_asc milestone_due_desc + escalation_status_asc escalation_status_desc].each do |sort_by| it "uses offset-pagination when sorting by #{sort_by}" do resolved = resolve_issues(sort: sort_by) diff --git a/spec/graphql/resolvers/project_jobs_resolver_spec.rb b/spec/graphql/resolvers/project_jobs_resolver_spec.rb index 94df2999163..bb711a4c857 100644 --- a/spec/graphql/resolvers/project_jobs_resolver_spec.rb +++ b/spec/graphql/resolvers/project_jobs_resolver_spec.rb @@ -9,9 +9,10 @@ RSpec.describe Resolvers::ProjectJobsResolver do let_it_be(:irrelevant_project) { create(:project, :repository) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let_it_be(:irrelevant_pipeline) { create(:ci_pipeline, project: irrelevant_project) } - let_it_be(:build_one) { create(:ci_build, :success, name: 'Build One', pipeline: pipeline) } - let_it_be(:build_two) { create(:ci_build, :success, name: 'Build Two', pipeline: pipeline) } - let_it_be(:build_three) { create(:ci_build, :failed, name: 'Build Three', pipeline: pipeline) } + let_it_be(:successful_build) { create(:ci_build, :success, name: 'Build One', pipeline: pipeline) } + let_it_be(:successful_build_two) { create(:ci_build, :success, name: 'Build Two', pipeline: pipeline) } + let_it_be(:failed_build) { create(:ci_build, :failed, name: 'Build Three', pipeline: pipeline) } + let_it_be(:pending_build) { create(:ci_build, :pending, name: 'Build Three', pipeline: pipeline) } let(:irrelevant_build) { create(:ci_build, name: 'Irrelevant Build', pipeline: irrelevant_pipeline)} let(:args) { {} } @@ -28,11 +29,17 @@ RSpec.describe Resolvers::ProjectJobsResolver do context 'with statuses argument' do let(:args) { { statuses: [Types::Ci::JobStatusEnum.coerce_isolated_input('SUCCESS')] } } - it { is_expected.to contain_exactly(build_one, build_two) } + it { is_expected.to contain_exactly(successful_build, successful_build_two) } + end + + context 'with multiple statuses' do + let(:args) { { statuses: [Types::Ci::JobStatusEnum.coerce_isolated_input('SUCCESS'), Types::Ci::JobStatusEnum.coerce_isolated_input('FAILED')] } } + + it { is_expected.to contain_exactly(successful_build, successful_build_two, failed_build) } end context 'without statuses argument' do - it { is_expected.to contain_exactly(build_one, build_two, build_three) } + it { is_expected.to contain_exactly(successful_build, successful_build_two, failed_build, pending_build) } end end diff --git a/spec/graphql/resolvers/users_resolver_spec.rb b/spec/graphql/resolvers/users_resolver_spec.rb index b01cc0d43e3..1ba296912a3 100644 --- a/spec/graphql/resolvers/users_resolver_spec.rb +++ b/spec/graphql/resolvers/users_resolver_spec.rb @@ -74,7 +74,9 @@ RSpec.describe Resolvers::UsersResolver do let_it_be(:current_user) { nil } it 'prohibits search without usernames passed' do - expect { resolve_users }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do + resolve_users + end end it 'allows to search by username' do diff --git a/spec/graphql/resolvers/work_item_resolver_spec.rb b/spec/graphql/resolvers/work_item_resolver_spec.rb index c7e2beecb51..bfa0cf1d8a2 100644 --- a/spec/graphql/resolvers/work_item_resolver_spec.rb +++ b/spec/graphql/resolvers/work_item_resolver_spec.rb @@ -22,7 +22,9 @@ RSpec.describe Resolvers::WorkItemResolver do let(:current_user) { create(:user) } it 'raises a resource not available error' do - expect { resolved_work_item }.to raise_error(::Gitlab::Graphql::Errors::ResourceNotAvailable) + expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do + resolved_work_item + end end end diff --git a/spec/graphql/resolvers/work_items/types_resolver_spec.rb b/spec/graphql/resolvers/work_items/types_resolver_spec.rb index f7aeed30fd3..868f4566ad6 100644 --- a/spec/graphql/resolvers/work_items/types_resolver_spec.rb +++ b/spec/graphql/resolvers/work_items/types_resolver_spec.rb @@ -53,5 +53,15 @@ RSpec.describe Resolvers::WorkItems::TypesResolver do it_behaves_like 'a work item type resolver' end + + context 'when parent is not a group or project' do + let(:object) { 'not a project/group' } + + it 'returns nil because of feature flag check' do + result = resolve(described_class, obj: object, args: {}) + + expect(result).to be_nil + end + end end end diff --git a/spec/graphql/types/base_object_spec.rb b/spec/graphql/types/base_object_spec.rb index d8f2ef58ea5..45dc885ecba 100644 --- a/spec/graphql/types/base_object_spec.rb +++ b/spec/graphql/types/base_object_spec.rb @@ -428,5 +428,25 @@ RSpec.describe Types::BaseObject do expect(result.dig('data', 'users', 'nodes')) .to contain_exactly({ 'name' => active_users.first.name }) end + + describe '.authorize' do + let_it_be(:read_only_type) do + Class.new(described_class) do + authorize :read_only + end + end + + let_it_be(:inherited_read_only_type) { Class.new(read_only_type) } + + it 'keeps track of the specified value' do + expect(described_class.authorize).to be_nil + expect(read_only_type.authorize).to match_array [:read_only] + expect(inherited_read_only_type.authorize).to match_array [:read_only] + end + + it 'can not redefine the authorize value' do + expect { read_only_type.authorize(:write_only) }.to raise_error('Cannot redefine authorize') + end + end end end diff --git a/spec/graphql/types/ci/job_kind_enum_spec.rb b/spec/graphql/types/ci/job_kind_enum_spec.rb new file mode 100644 index 00000000000..b48d20b71e2 --- /dev/null +++ b/spec/graphql/types/ci/job_kind_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CiJobKind'] do + it 'exposes some job type values' do + expect(described_class.values.keys).to match_array( + (%w[BRIDGE BUILD]) + ) + end +end diff --git a/spec/graphql/types/ci/job_type_spec.rb b/spec/graphql/types/ci/job_type_spec.rb index 47d697ab8b8..655c3636883 100644 --- a/spec/graphql/types/ci/job_type_spec.rb +++ b/spec/graphql/types/ci/job_type_spec.rb @@ -21,6 +21,7 @@ RSpec.describe Types::Ci::JobType do downstreamPipeline finished_at id + kind manual_job name needs diff --git a/spec/graphql/types/container_repository_details_type_spec.rb b/spec/graphql/types/container_repository_details_type_spec.rb index aa770284f89..d94516c6fce 100644 --- a/spec/graphql/types/container_repository_details_type_spec.rb +++ b/spec/graphql/types/container_repository_details_type_spec.rb @@ -3,7 +3,9 @@ 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 size project] + fields = %i[id name path location created_at updated_at expiration_policy_started_at + status tags_count can_delete expiration_policy_cleanup_status tags size + project migration_state] 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 87e1c11ce19..9815449dd68 100644 --- a/spec/graphql/types/container_repository_type_spec.rb +++ b/spec/graphql/types/container_repository_type_spec.rb @@ -3,7 +3,9 @@ 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 project] + fields = %i[id name path location created_at updated_at expiration_policy_started_at + status tags_count can_delete expiration_policy_cleanup_status project + migration_state] it { expect(described_class.graphql_name).to eq('ContainerRepository') } diff --git a/spec/graphql/types/dependency_proxy/manifest_type_spec.rb b/spec/graphql/types/dependency_proxy/manifest_type_spec.rb index b251ca63c4f..f688b085b10 100644 --- a/spec/graphql/types/dependency_proxy/manifest_type_spec.rb +++ b/spec/graphql/types/dependency_proxy/manifest_type_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['DependencyProxyManifest'] do it 'includes dependency proxy manifest fields' do expected_fields = %w[ - id file_name image_name size created_at updated_at digest + id file_name image_name size created_at updated_at digest status ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/issue_sort_enum_spec.rb b/spec/graphql/types/issue_sort_enum_spec.rb index 4433709d193..95184477e75 100644 --- a/spec/graphql/types/issue_sort_enum_spec.rb +++ b/spec/graphql/types/issue_sort_enum_spec.rb @@ -9,7 +9,7 @@ RSpec.describe GitlabSchema.types['IssueSort'] do it 'exposes all the existing issue sort values' do expect(described_class.values.keys).to include( - *%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC SEVERITY_ASC SEVERITY_DESC] + *%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC SEVERITY_ASC SEVERITY_DESC ESCALATION_STATUS_ASC ESCALATION_STATUS_DESC] ) end end diff --git a/spec/graphql/types/range_input_type_spec.rb b/spec/graphql/types/range_input_type_spec.rb index fc9126247fa..dbfcf4a41c7 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: double('query', schema: nil), + query: GraphQL::Query.new(GitlabSchema), values: {}, object: nil ) diff --git a/spec/graphql/types/repository/blob_type_spec.rb b/spec/graphql/types/repository/blob_type_spec.rb index a813ef85e6e..787b5f4a311 100644 --- a/spec/graphql/types/repository/blob_type_spec.rb +++ b/spec/graphql/types/repository/blob_type_spec.rb @@ -34,7 +34,6 @@ RSpec.describe Types::Repository::BlobType do :environment_external_url_for_route_map, :code_navigation_path, :project_blob_path_root, - :code_owners, :simple_viewer, :rich_viewer, :plain_data, @@ -47,6 +46,6 @@ RSpec.describe Types::Repository::BlobType do :ide_fork_and_edit_path, :fork_and_view_path, :language - ) + ).at_least end end diff --git a/spec/graphql/types/subscription_type_spec.rb b/spec/graphql/types/subscription_type_spec.rb index 593795de004..1a2629ed422 100644 --- a/spec/graphql/types/subscription_type_spec.rb +++ b/spec/graphql/types/subscription_type_spec.rb @@ -8,6 +8,7 @@ RSpec.describe GitlabSchema.types['Subscription'] do issuable_assignees_updated issue_crm_contacts_updated issuable_title_updated + issuable_labels_updated ] expect(described_class).to have_graphql_fields(*expected_fields).only |