summaryrefslogtreecommitdiff
path: root/spec/graphql/resolvers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-03-18 20:02:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-03-18 20:02:30 +0000
commit41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch)
tree9c8d89a8624828992f06d892cd2f43818ff5dcc8 /spec/graphql/resolvers
parent0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff)
downloadgitlab-ce-41fe97390ceddf945f3d967b8fdb3de4c66b7dea.tar.gz
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'spec/graphql/resolvers')
-rw-r--r--spec/graphql/resolvers/admin/analytics/usage_trends/measurements_resolver_spec.rb12
-rw-r--r--spec/graphql/resolvers/base_resolver_spec.rb10
-rw-r--r--spec/graphql/resolvers/blobs_resolver_spec.rb28
-rw-r--r--spec/graphql/resolvers/board_list_issues_resolver_spec.rb12
-rw-r--r--spec/graphql/resolvers/board_lists_resolver_spec.rb7
-rw-r--r--spec/graphql/resolvers/board_resolver_spec.rb4
-rw-r--r--spec/graphql/resolvers/ci/config_resolver_spec.rb40
-rw-r--r--spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb40
-rw-r--r--spec/graphql/resolvers/design_management/design_at_version_resolver_spec.rb12
-rw-r--r--spec/graphql/resolvers/design_management/design_resolver_spec.rb12
-rw-r--r--spec/graphql/resolvers/design_management/version/design_at_version_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/design_management/version_in_collection_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/design_management/version_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/design_management/versions_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/environments_resolver_spec.rb8
-rw-r--r--spec/graphql/resolvers/group_issues_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/group_labels_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb46
-rw-r--r--spec/graphql/resolvers/group_milestones_resolver_spec.rb24
-rw-r--r--spec/graphql/resolvers/issue_status_counts_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/issues_resolver_spec.rb35
-rw-r--r--spec/graphql/resolvers/kas/agent_configurations_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/labels_resolver_spec.rb4
-rw-r--r--spec/graphql/resolvers/namespace_projects_resolver_spec.rb4
-rw-r--r--spec/graphql/resolvers/package_pipelines_resolver_spec.rb24
-rw-r--r--spec/graphql/resolvers/paginated_tree_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/project_milestones_resolver_spec.rb24
-rw-r--r--spec/graphql/resolvers/project_pipeline_resolver_spec.rb10
-rw-r--r--spec/graphql/resolvers/project_resolver_spec.rb4
-rw-r--r--spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb13
-rw-r--r--spec/graphql/resolvers/projects/snippets_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/snippets_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/timelog_resolver_spec.rb49
-rw-r--r--spec/graphql/resolvers/topics_resolver_spec.rb6
-rw-r--r--spec/graphql/resolvers/user_discussions_count_resolver_spec.rb4
-rw-r--r--spec/graphql/resolvers/user_notes_count_resolver_spec.rb12
-rw-r--r--spec/graphql/resolvers/user_resolver_spec.rb14
-rw-r--r--spec/graphql/resolvers/users_resolver_spec.rb13
-rw-r--r--spec/graphql/resolvers/work_item_resolver_spec.rb43
-rw-r--r--spec/graphql/resolvers/work_items/types_resolver_spec.rb41
41 files changed, 444 insertions, 183 deletions
diff --git a/spec/graphql/resolvers/admin/analytics/usage_trends/measurements_resolver_spec.rb b/spec/graphql/resolvers/admin/analytics/usage_trends/measurements_resolver_spec.rb
index b63eca4359d..6b5e351a610 100644
--- a/spec/graphql/resolvers/admin/analytics/usage_trends/measurements_resolver_spec.rb
+++ b/spec/graphql/resolvers/admin/analytics/usage_trends/measurements_resolver_spec.rb
@@ -31,16 +31,20 @@ RSpec.describe Resolvers::Admin::Analytics::UsageTrends::MeasurementsResolver do
context 'as a non-admin user' do
let(:current_user) { user }
- it 'raises ResourceNotAvailable error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates a ResourceNotAvailable error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ subject
+ end
end
end
context 'as an unauthenticated user' do
let(:current_user) { nil }
- it 'raises ResourceNotAvailable error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates a ResourceNotAvailable error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ subject
+ end
end
end
diff --git a/spec/graphql/resolvers/base_resolver_spec.rb b/spec/graphql/resolvers/base_resolver_spec.rb
index d77a0b6242e..39b00c14161 100644
--- a/spec/graphql/resolvers/base_resolver_spec.rb
+++ b/spec/graphql/resolvers/base_resolver_spec.rb
@@ -239,16 +239,16 @@ RSpec.describe Resolvers::BaseResolver do
it 'increases complexity based on arguments' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: described_class, null: false, max_page_size: 1)
- expect(field.to_graphql.complexity.call({}, { sort: 'foo' }, 1)).to eq 3
- expect(field.to_graphql.complexity.call({}, { search: 'foo' }, 1)).to eq 7
+ expect(field.complexity.call({}, { sort: 'foo' }, 1)).to eq 3
+ expect(field.complexity.call({}, { search: 'foo' }, 1)).to eq 7
end
it 'does not increase complexity when filtering by iids' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: described_class, null: false, max_page_size: 100)
- expect(field.to_graphql.complexity.call({}, { sort: 'foo' }, 1)).to eq 6
- expect(field.to_graphql.complexity.call({}, { sort: 'foo', iid: 1 }, 1)).to eq 3
- expect(field.to_graphql.complexity.call({}, { sort: 'foo', iids: [1, 2, 3] }, 1)).to eq 3
+ expect(field.complexity.call({}, { sort: 'foo' }, 1)).to eq 6
+ expect(field.complexity.call({}, { sort: 'foo', iid: 1 }, 1)).to eq 3
+ expect(field.complexity.call({}, { sort: 'foo', iids: [1, 2, 3] }, 1)).to eq 3
end
end
diff --git a/spec/graphql/resolvers/blobs_resolver_spec.rb b/spec/graphql/resolvers/blobs_resolver_spec.rb
index bc0344796ee..4b75351147c 100644
--- a/spec/graphql/resolvers/blobs_resolver_spec.rb
+++ b/spec/graphql/resolvers/blobs_resolver_spec.rb
@@ -26,8 +26,10 @@ RSpec.describe Resolvers::BlobsResolver do
subject(:resolve_blobs) { resolve(described_class, obj: repository, args: args, ctx: { current_user: user }) }
context 'when unauthorized' do
- it 'raises an exception' do
- expect { resolve_blobs }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ resolve_blobs
+ end
end
end
@@ -68,6 +70,28 @@ RSpec.describe Resolvers::BlobsResolver do
)
end
end
+
+ context 'when specifying an invalid ref' do
+ let(:ref) { 'ma:in' }
+
+ it 'raises an ArgumentError' do
+ expect { resolve_blobs }.to raise_error(
+ Gitlab::Graphql::Errors::ArgumentError,
+ 'Ref is not valid'
+ )
+ end
+ end
+
+ context 'when passing an empty ref' do
+ let(:ref) { '' }
+
+ it 'raises an ArgumentError' do
+ expect { resolve_blobs }.to raise_error(
+ Gitlab::Graphql::Errors::ArgumentError,
+ 'Ref is not valid'
+ )
+ end
+ end
end
end
end
diff --git a/spec/graphql/resolvers/board_list_issues_resolver_spec.rb b/spec/graphql/resolvers/board_list_issues_resolver_spec.rb
index 6907c55bd48..392385d2a30 100644
--- a/spec/graphql/resolvers/board_list_issues_resolver_spec.rb
+++ b/spec/graphql/resolvers/board_list_issues_resolver_spec.rb
@@ -25,10 +25,10 @@ RSpec.describe Resolvers::BoardListIssuesResolver do
let(:wildcard_started) { 'STARTED' }
let(:filters) { { milestone_title: ["started"], milestone_wildcard_id: wildcard_started } }
- it 'raises a mutually exclusive filter error when milestone wildcard and title are provided' do
- expect do
+ it 'generates a mutually exclusive filter error when milestone wildcard and title are provided' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve_board_list_issues(args: { filters: filters })
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ end
end
it 'returns the issues in the correct order' do
@@ -63,10 +63,10 @@ RSpec.describe Resolvers::BoardListIssuesResolver do
expect(result).to contain_exactly(incident)
end
- it 'raises an exception if both assignee_username and assignee_wildcard_id are present' do
- expect do
+ it 'generates an error if both assignee_username and assignee_wildcard_id are present' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve_board_list_issues(args: { filters: { assignee_username: ['username'], assignee_wildcard_id: 'NONE' } })
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ end
end
it 'accepts assignee wildcard id NONE' do
diff --git a/spec/graphql/resolvers/board_lists_resolver_spec.rb b/spec/graphql/resolvers/board_lists_resolver_spec.rb
index fdcebd30bb3..7a1d8590546 100644
--- a/spec/graphql/resolvers/board_lists_resolver_spec.rb
+++ b/spec/graphql/resolvers/board_lists_resolver_spec.rb
@@ -74,9 +74,10 @@ RSpec.describe Resolvers::BoardListsResolver do
expect(list).to eq List.none
end
- it 'raises an argument error if list ID is not valid' do
- expect { resolve_board_lists(args: { id: 'test' }) }
- .to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ it 'generates an error if list ID is not valid' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ resolve_board_lists(args: { id: 'test' })
+ end
end
end
end
diff --git a/spec/graphql/resolvers/board_resolver_spec.rb b/spec/graphql/resolvers/board_resolver_spec.rb
index e9c51a536ee..51a13850366 100644
--- a/spec/graphql/resolvers/board_resolver_spec.rb
+++ b/spec/graphql/resolvers/board_resolver_spec.rb
@@ -23,9 +23,9 @@ RSpec.describe Resolvers::BoardResolver do
end
it 'requires an ID' do
- expect do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve(described_class, obj: board_parent, args: {}, ctx: { current_user: user })
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ end
end
context 'when querying for a single board' do
diff --git a/spec/graphql/resolvers/ci/config_resolver_spec.rb b/spec/graphql/resolvers/ci/config_resolver_spec.rb
index 97eee749290..3ff6d8f4347 100644
--- a/spec/graphql/resolvers/ci/config_resolver_spec.rb
+++ b/spec/graphql/resolvers/ci/config_resolver_spec.rb
@@ -6,16 +6,24 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
include GraphqlHelpers
describe '#resolve' do
- before do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
+ let_it_be(:sha) { nil }
+
+ let_it_be(:content) do
+ File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml'))
+ end
+
+ let(:ci_lint) do
ci_lint_double = instance_double(::Gitlab::Ci::Lint)
allow(ci_lint_double).to receive(:validate).and_return(fake_result)
- allow(::Gitlab::Ci::Lint).to receive(:new).and_return(ci_lint_double)
+ ci_lint_double
end
- let_it_be(:user) { create(:user) }
- let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
- let_it_be(:sha) { nil }
+ before do
+ allow(::Gitlab::Ci::Lint).to receive(:new).and_return(ci_lint)
+ end
subject(:response) do
resolve(described_class,
@@ -33,10 +41,6 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
)
end
- let_it_be(:content) do
- File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml'))
- end
-
it 'lints the ci config file and returns the merged yaml file' do
expect(response[:status]).to eq(:valid)
expect(response[:merged_yaml]).to eq(content)
@@ -74,5 +78,23 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
expect(response[:errors]).to eq(['Invalid configuration format'])
end
end
+
+ context 'with an invalid SHA' do
+ let_it_be(:sha) { ':' }
+
+ let(:ci_lint) do
+ ci_lint_double = instance_double(::Gitlab::Ci::Lint)
+ allow(ci_lint_double).to receive(:validate).and_raise(GRPC::InvalidArgument)
+
+ ci_lint_double
+ end
+
+ it 'logs the invalid SHA to Sentry' do
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_exception)
+ .with(GRPC::InvalidArgument, sha: ':')
+
+ response
+ end
+ end
end
end
diff --git a/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb b/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb
index 8522542498d..59616815de0 100644
--- a/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb
+++ b/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb
@@ -54,10 +54,8 @@ RSpec.describe Resolvers::Ci::JobTokenScopeResolver do
project.add_user(current_user, :developer)
end
- it 'raises error' do
- expect do
- resolve_scope
- end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) { resolve_scope }
end
end
end
diff --git a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb
index 9fe4c78f551..4c4aa4f53e1 100644
--- a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb
+++ b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe ResolvesPipelines do
end
end
- let(:current_user) { create(:user) }
+ let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project, :private) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
@@ -23,13 +23,15 @@ RSpec.describe ResolvesPipelines do
let_it_be(:success_pipeline) { create(:ci_pipeline, :success, project: project) }
let_it_be(:ref_pipeline) { create(:ci_pipeline, project: project, ref: 'awesome-feature') }
let_it_be(:sha_pipeline) { create(:ci_pipeline, project: project, sha: 'deadbeef') }
+ let_it_be(:username_pipeline) { create(:ci_pipeline, project: project, user: current_user) }
let_it_be(:all_pipelines) do
[
pipeline,
failed_pipeline,
success_pipeline,
ref_pipeline,
- sha_pipeline
+ sha_pipeline,
+ username_pipeline
]
end
@@ -37,7 +39,7 @@ RSpec.describe ResolvesPipelines do
project.add_developer(current_user)
end
- it { is_expected.to have_graphql_arguments(:status, :scope, :ref, :sha, :source) }
+ it { is_expected.to have_graphql_arguments(:status, :scope, :ref, :sha, :source, :updated_after, :updated_before, :username) }
it 'finds all pipelines' do
expect(resolve_pipelines).to contain_exactly(*all_pipelines)
@@ -71,6 +73,32 @@ RSpec.describe ResolvesPipelines do
end
end
+ it 'allows filtering by username' do
+ expect(resolve_pipelines(username: current_user.username)).to contain_exactly(username_pipeline)
+ end
+
+ context 'filtering by updated_at' do
+ let_it_be(:old_pipeline) { create(:ci_pipeline, project: project, updated_at: 2.days.ago) }
+ let_it_be(:older_pipeline) { create(:ci_pipeline, project: project, updated_at: 5.days.ago) }
+
+ it 'filters by updated_after' do
+ expect(resolve_pipelines(updated_after: 3.days.ago)).to contain_exactly(old_pipeline, *all_pipelines)
+ end
+
+ it 'filters by updated_before' do
+ expect(resolve_pipelines(updated_before: 3.days.ago)).to contain_exactly(older_pipeline)
+ end
+
+ it 'filters by both updated_after and updated_before with valid date range' do
+ expect(resolve_pipelines(updated_after: 10.days.ago, updated_before: 3.days.ago)).to contain_exactly(older_pipeline)
+ end
+
+ it 'filters by both updated_after and updated_before with invalid date range' do
+ # updated_after is before updated_before so result set is empty - impossible
+ expect(resolve_pipelines(updated_after: 3.days.ago, updated_before: 10.days.ago)).to be_empty
+ end
+ end
+
it 'does not return any pipelines if the user does not have access' do
expect(resolve_pipelines({}, {})).to be_empty
end
@@ -78,9 +106,9 @@ RSpec.describe ResolvesPipelines do
it 'increases field complexity based on arguments' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String, resolver_class: resolver, null: false, max_page_size: 1)
- expect(field.to_graphql.complexity.call({}, {}, 1)).to eq 2
- expect(field.to_graphql.complexity.call({}, { sha: 'foo' }, 1)).to eq 4
- expect(field.to_graphql.complexity.call({}, { sha: 'ref' }, 1)).to eq 4
+ expect(field.complexity.call({}, {}, 1)).to eq 2
+ expect(field.complexity.call({}, { sha: 'foo' }, 1)).to eq 4
+ expect(field.complexity.call({}, { sha: 'ref' }, 1)).to eq 4
end
def resolve_pipelines(args = {}, context = { current_user: current_user })
diff --git a/spec/graphql/resolvers/design_management/design_at_version_resolver_spec.rb b/spec/graphql/resolvers/design_management/design_at_version_resolver_spec.rb
index 4bdef49499c..a16e8821cb5 100644
--- a/spec/graphql/resolvers/design_management/design_at_version_resolver_spec.rb
+++ b/spec/graphql/resolvers/design_management/design_at_version_resolver_spec.rb
@@ -29,8 +29,10 @@ RSpec.describe Resolvers::DesignManagement::DesignAtVersionResolver do
context 'when the user cannot see designs' do
let(:current_user) { create(:user) }
- it 'raises ResourceNotAvailable' do
- expect { resolve_design }.to raise_error(resource_not_available)
+ it 'generates ResourceNotAvailable' do
+ expect_graphql_error_to_be_created(resource_not_available) do
+ resolve_design
+ end
end
end
@@ -45,8 +47,10 @@ RSpec.describe Resolvers::DesignManagement::DesignAtVersionResolver do
let(:global_id) { global_id_of(other_dav) }
- it 'raises ResourceNotAvailable' do
- expect { resolve_design }.to raise_error(resource_not_available)
+ it 'generates ResourceNotAvailable' do
+ expect_graphql_error_to_be_created(resource_not_available) do
+ resolve_design
+ end
end
context 'the current object does not constrain the issue' do
diff --git a/spec/graphql/resolvers/design_management/design_resolver_spec.rb b/spec/graphql/resolvers/design_management/design_resolver_spec.rb
index e33eaedf167..4c8b3116875 100644
--- a/spec/graphql/resolvers/design_management/design_resolver_spec.rb
+++ b/spec/graphql/resolvers/design_management/design_resolver_spec.rb
@@ -42,16 +42,20 @@ RSpec.describe Resolvers::DesignManagement::DesignResolver do
context 'when no argument has been passed' do
let(:args) { {} }
- it 'raises an error' do
- expect { resolve_design }.to raise_error(::Gitlab::Graphql::Errors::ArgumentError, /must/)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(::Gitlab::Graphql::Errors::ArgumentError, /must/) do
+ resolve_design
+ end
end
end
context 'when both arguments have been passed' do
let(:args) { { filename: first_design.filename, id: GitlabSchema.id_from_object(first_design).to_s } }
- it 'raises an error' do
- expect { resolve_design }.to raise_error(::Gitlab::Graphql::Errors::ArgumentError, /may/)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(::Gitlab::Graphql::Errors::ArgumentError, /may/) do
+ resolve_design
+ end
end
end
diff --git a/spec/graphql/resolvers/design_management/version/design_at_version_resolver_spec.rb b/spec/graphql/resolvers/design_management/version/design_at_version_resolver_spec.rb
index cc7e2f6814a..829227185c2 100644
--- a/spec/graphql/resolvers/design_management/version/design_at_version_resolver_spec.rb
+++ b/spec/graphql/resolvers/design_management/version/design_at_version_resolver_spec.rb
@@ -24,8 +24,10 @@ RSpec.describe Resolvers::DesignManagement::Version::DesignAtVersionResolver do
shared_examples 'a bad argument' do
let(:err_class) { ::Gitlab::Graphql::Errors::ArgumentError }
- it 'raises an appropriate error' do
- expect { resolve_objects }.to raise_error(err_class)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(err_class) do
+ resolve_objects
+ end
end
end
diff --git a/spec/graphql/resolvers/design_management/version_in_collection_resolver_spec.rb b/spec/graphql/resolvers/design_management/version_in_collection_resolver_spec.rb
index b0fc78af2af..8b9874c3580 100644
--- a/spec/graphql/resolvers/design_management/version_in_collection_resolver_spec.rb
+++ b/spec/graphql/resolvers/design_management/version_in_collection_resolver_spec.rb
@@ -26,8 +26,10 @@ RSpec.describe Resolvers::DesignManagement::VersionInCollectionResolver do
subject(:result) { resolve_version(issue.design_collection) }
context 'Neither id nor sha is passed as parameters' do
- it 'raises an appropriate error' do
- expect { result }.to raise_error(appropriate_error)
+ it 'generates an appropriate error' do
+ expect_graphql_error_to_be_created(appropriate_error) do
+ result
+ end
end
end
diff --git a/spec/graphql/resolvers/design_management/version_resolver_spec.rb b/spec/graphql/resolvers/design_management/version_resolver_spec.rb
index af1e6a73d09..ab1d7d4d9c5 100644
--- a/spec/graphql/resolvers/design_management/version_resolver_spec.rb
+++ b/spec/graphql/resolvers/design_management/version_resolver_spec.rb
@@ -22,8 +22,10 @@ RSpec.describe Resolvers::DesignManagement::VersionResolver do
context 'the current user is not authorized' do
let(:current_user) { create(:user) }
- it 'raises an error on resolution' do
- expect { resolve_version }.to raise_error(::Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error on resolution' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ resolve_version
+ end
end
end
diff --git a/spec/graphql/resolvers/design_management/versions_resolver_spec.rb b/spec/graphql/resolvers/design_management/versions_resolver_spec.rb
index 2c9c3a47650..d98138f6385 100644
--- a/spec/graphql/resolvers/design_management/versions_resolver_spec.rb
+++ b/spec/graphql/resolvers/design_management/versions_resolver_spec.rb
@@ -98,8 +98,10 @@ RSpec.describe Resolvers::DesignManagement::VersionsResolver do
}
end
- it 'raises a suitable error' do
- expect { result }.to raise_error(GraphQL::ExecutionError)
+ it 'generates a suitable error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ result
+ end
end
end
end
diff --git a/spec/graphql/resolvers/environments_resolver_spec.rb b/spec/graphql/resolvers/environments_resolver_spec.rb
index 6c999e5d0e7..9f4c4716de0 100644
--- a/spec/graphql/resolvers/environments_resolver_spec.rb
+++ b/spec/graphql/resolvers/environments_resolver_spec.rb
@@ -46,10 +46,10 @@ RSpec.describe Resolvers::EnvironmentsResolver do
expect(resolve_environments(states: ['available'])).to contain_exactly(environment1, environment3)
end
- it 'returns error if requested state is invalid' do
- expect { resolve_environments(states: ['invalid']) }.to(
- raise_error(Gitlab::Graphql::Errors::ArgumentError)
- )
+ it 'generates an error if requested state is invalid' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ resolve_environments(states: ['invalid'])
+ end
end
end
diff --git a/spec/graphql/resolvers/group_issues_resolver_spec.rb b/spec/graphql/resolvers/group_issues_resolver_spec.rb
index e17429560ac..f5f6086cc09 100644
--- a/spec/graphql/resolvers/group_issues_resolver_spec.rb
+++ b/spec/graphql/resolvers/group_issues_resolver_spec.rb
@@ -86,10 +86,10 @@ RSpec.describe Resolvers::GroupIssuesResolver do
end
context 'release_tag filter' do
- it 'returns an error when trying to filter by negated release_tag' do
- expect do
+ it 'generates an error when trying to filter by negated release_tag' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'releaseTag filter is not allowed when parent is a group.') do
resolve_issues(not: { release_tag: ['v1.0'] })
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'releaseTag filter is not allowed when parent is a group.')
+ end
end
end
end
diff --git a/spec/graphql/resolvers/group_labels_resolver_spec.rb b/spec/graphql/resolvers/group_labels_resolver_spec.rb
index 3f4ad8760c0..2031e534703 100644
--- a/spec/graphql/resolvers/group_labels_resolver_spec.rb
+++ b/spec/graphql/resolvers/group_labels_resolver_spec.rb
@@ -27,8 +27,10 @@ RSpec.describe Resolvers::GroupLabelsResolver do
describe '#resolve' do
context 'with unauthorized user' do
- it 'raises error' do
- expect { resolve_labels(subgroup) }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ resolve_labels(subgroup)
+ 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
new file mode 100644
index 00000000000..fcf67120b0e
--- /dev/null
+++ b/spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Resolvers::GroupMembers::NotificationEmailResolver do
+ include GraphqlHelpers
+
+ describe '#resolve' do
+ let_it_be(:group) { create(:group) }
+ let_it_be(:developer) { create(:user) }
+
+ before do
+ group.add_developer(developer)
+ end
+
+ specify do
+ expect(described_class).to have_nullable_graphql_type(GraphQL::Types::String)
+ end
+
+ subject { batch_sync { resolve_notification_email(developer.group_members.first, current_user) }}
+
+ context 'when current_user is admin' do
+ let(:current_user) { create(:user, :admin) }
+
+ before do
+ allow(current_user).to receive(:can_admin_all_resources?).and_return(true)
+ end
+
+ it 'returns email' do
+ expect(subject).to eq(developer.email)
+ end
+ end
+
+ context 'when current_user is not admin' do
+ let(:current_user) { create(:user) }
+
+ it 'raises ResourceNotAvailable error' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+ end
+
+ def resolve_notification_email(obj, user)
+ resolve(described_class, obj: obj, ctx: { current_user: user })
+ end
+end
diff --git a/spec/graphql/resolvers/group_milestones_resolver_spec.rb b/spec/graphql/resolvers/group_milestones_resolver_spec.rb
index acfc8313407..7abc779a63c 100644
--- a/spec/graphql/resolvers/group_milestones_resolver_spec.rb
+++ b/spec/graphql/resolvers/group_milestones_resolver_spec.rb
@@ -101,38 +101,38 @@ RSpec.describe Resolvers::GroupMilestonesResolver do
context 'by timeframe' do
context 'when start_date and end_date are present' do
context 'when start date is after end_date' do
- it 'raises error' do
- expect do
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, "startDate is after endDate") do
resolve_group_milestones(start_date: now, end_date: now - 2.days)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, "startDate is after endDate")
+ end
end
end
end
context 'when only start_date is present' do
- it 'raises error' do
- expect do
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
resolve_group_milestones(start_date: now)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
+ end
end
end
context 'when only end_date is present' do
- it 'raises error' do
- expect do
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
resolve_group_milestones(end_date: now)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
+ end
end
end
end
context 'when user cannot read milestones' do
- it 'raises error' do
+ it 'generates an error' do
unauthorized_user = create(:user)
- expect do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_group_milestones({}, { current_user: unauthorized_user })
- end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
end
end
diff --git a/spec/graphql/resolvers/issue_status_counts_resolver_spec.rb b/spec/graphql/resolvers/issue_status_counts_resolver_spec.rb
index 3fbd9bd2368..77f4ce4cac5 100644
--- a/spec/graphql/resolvers/issue_status_counts_resolver_spec.rb
+++ b/spec/graphql/resolvers/issue_status_counts_resolver_spec.rb
@@ -70,10 +70,10 @@ RSpec.describe Resolvers::IssueStatusCountsResolver do
end
context 'when both assignee_username and assignee_usernames are provided' do
- it 'raises a mutually exclusive filter error' do
- expect do
+ it 'generates a mutually exclusive filter error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [assigneeUsernames, assigneeUsername] arguments is allowed at the same time.') do
resolve_issue_status_counts(assignee_usernames: [current_user.username], assignee_username: current_user.username)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [assigneeUsernames, assigneeUsername] arguments is allowed at the same time.')
+ end
end
end
diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb
index dc717b113c1..5e9a3d0a68b 100644
--- a/spec/graphql/resolvers/issues_resolver_spec.rb
+++ b/spec/graphql/resolvers/issues_resolver_spec.rb
@@ -78,10 +78,10 @@ RSpec.describe Resolvers::IssuesResolver do
expect(resolve_issues(milestone_wildcard_id: wildcard_none)).to contain_exactly(issue2)
end
- it 'raises a mutually exclusive filter error when wildcard and title are provided' do
- expect do
+ it 'generates a mutually exclusive filter error when wildcard and title are provided' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [milestoneTitle, milestoneWildcardId] arguments is allowed at the same time.') do
resolve_issues(milestone_title: ["started milestone"], milestone_wildcard_id: wildcard_started)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [milestoneTitle, milestoneWildcardId] arguments is allowed at the same time.')
+ end
end
context 'negated filtering' do
@@ -97,10 +97,10 @@ RSpec.describe Resolvers::IssuesResolver do
expect(resolve_issues(not: { milestone_wildcard_id: wildcard_upcoming })).to contain_exactly(issue6)
end
- it 'raises a mutually exclusive filter error when wildcard and title are provided as negated filters' do
- expect do
+ it 'generates a mutually exclusive filter error when wildcard and title are provided as negated filters' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [milestoneTitle, milestoneWildcardId] arguments is allowed at the same time.') do
resolve_issues(not: { milestone_title: ["started milestone"], milestone_wildcard_id: wildcard_started })
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [milestoneTitle, milestoneWildcardId] arguments is allowed at the same time.')
+ end
end
end
end
@@ -122,10 +122,10 @@ RSpec.describe Resolvers::IssuesResolver do
end
context 'when release_tag_wildcard_id is also provided' do
- it 'raises a mutually eclusive argument error' do
- expect do
+ it 'generates a mutually eclusive argument error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [releaseTag, releaseTagWildcardId] arguments is allowed at the same time.') do
resolve_issues(release_tag: [release1.tag], release_tag_wildcard_id: 'ANY')
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [releaseTag, releaseTagWildcardId] arguments is allowed at the same time.')
+ end
end
end
end
@@ -191,10 +191,10 @@ RSpec.describe Resolvers::IssuesResolver do
end
context 'when both assignee_username and assignee_usernames are provided' do
- it 'raises a mutually exclusive filter error' do
- expect do
+ it 'generates a mutually exclusive filter error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'only one of [assigneeUsernames, assigneeUsername] arguments is allowed at the same time.') do
resolve_issues(assignee_usernames: [assignee.username], assignee_username: assignee.username)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [assigneeUsernames, assigneeUsername] arguments is allowed at the same time.')
+ end
end
end
end
@@ -331,11 +331,12 @@ RSpec.describe Resolvers::IssuesResolver do
stub_feature_flags(disable_anonymous_search: true)
end
- it 'returns an error' do
+ it 'generates an error' do
error_message = "User must be authenticated to include the `search` argument."
- expect { resolve(described_class, obj: public_project, args: { search: 'test' }, ctx: { current_user: nil }) }
- .to raise_error(Gitlab::Graphql::Errors::ArgumentError, error_message)
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, error_message) do
+ resolve(described_class, obj: public_project, args: { search: 'test' }, ctx: { current_user: nil })
+ end
end
end
@@ -618,8 +619,8 @@ RSpec.describe Resolvers::IssuesResolver do
it 'increases field complexity based on arguments' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: described_class, null: false, max_page_size: 100)
- expect(field.to_graphql.complexity.call({}, {}, 1)).to eq 4
- expect(field.to_graphql.complexity.call({}, { labelName: 'foo' }, 1)).to eq 8
+ expect(field.complexity.call({}, {}, 1)).to eq 4
+ expect(field.complexity.call({}, { labelName: 'foo' }, 1)).to eq 8
end
def create_issue_with_severity(project, severity:)
diff --git a/spec/graphql/resolvers/kas/agent_configurations_resolver_spec.rb b/spec/graphql/resolvers/kas/agent_configurations_resolver_spec.rb
index bdb1ced46ae..e4cf62b0361 100644
--- a/spec/graphql/resolvers/kas/agent_configurations_resolver_spec.rb
+++ b/spec/graphql/resolvers/kas/agent_configurations_resolver_spec.rb
@@ -34,8 +34,10 @@ RSpec.describe Resolvers::Kas::AgentConfigurationsResolver do
allow(kas_client).to receive(:list_agent_config_files).and_raise(GRPC::DeadlineExceeded)
end
- it 'raises a graphql error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, 'GRPC::DeadlineExceeded')
+ it 'generates a graphql error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable, 'GRPC::DeadlineExceeded') do
+ subject
+ end
end
end
diff --git a/spec/graphql/resolvers/labels_resolver_spec.rb b/spec/graphql/resolvers/labels_resolver_spec.rb
index be6229553d7..efd2596b9eb 100644
--- a/spec/graphql/resolvers/labels_resolver_spec.rb
+++ b/spec/graphql/resolvers/labels_resolver_spec.rb
@@ -28,7 +28,9 @@ RSpec.describe Resolvers::LabelsResolver do
describe '#resolve' do
context 'with unauthorized user' do
it 'returns no labels' do
- expect { resolve_labels(project) }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ resolve_labels(project)
+ end
end
end
diff --git a/spec/graphql/resolvers/namespace_projects_resolver_spec.rb b/spec/graphql/resolvers/namespace_projects_resolver_spec.rb
index b1f50a4a4a5..eb4d0ab6f37 100644
--- a/spec/graphql/resolvers/namespace_projects_resolver_spec.rb
+++ b/spec/graphql/resolvers/namespace_projects_resolver_spec.rb
@@ -147,8 +147,8 @@ RSpec.describe Resolvers::NamespaceProjectsResolver do
it 'has an high complexity regardless of arguments' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: described_class, null: false, max_page_size: 100)
- expect(field.to_graphql.complexity.call({}, {}, 1)).to eq 24
- expect(field.to_graphql.complexity.call({}, { include_subgroups: true }, 1)).to eq 24
+ expect(field.complexity.call({}, {}, 1)).to eq 24
+ expect(field.complexity.call({}, { include_subgroups: true }, 1)).to eq 24
end
def resolve_projects(args = { include_subgroups: false, sort: nil, search: nil, ids: nil }, context = { current_user: current_user })
diff --git a/spec/graphql/resolvers/package_pipelines_resolver_spec.rb b/spec/graphql/resolvers/package_pipelines_resolver_spec.rb
index 892dc641201..c757c876616 100644
--- a/spec/graphql/resolvers/package_pipelines_resolver_spec.rb
+++ b/spec/graphql/resolvers/package_pipelines_resolver_spec.rb
@@ -25,32 +25,40 @@ RSpec.describe Resolvers::PackagePipelinesResolver do
context 'with invalid after' do
let(:args) { { first: 1, after: 'not_json_string' } }
- it 'raises argument error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ it 'generates an argument error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ subject
+ end
end
end
context 'with invalid after key' do
let(:args) { { first: 1, after: encode_cursor(foo: 3) } }
- it 'raises argument error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ it 'generates an argument error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ subject
+ end
end
end
context 'with invalid before' do
let(:args) { { last: 1, before: 'not_json_string' } }
- it 'raises argument error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ it 'generates an argument error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ subject
+ end
end
end
context 'with invalid before key' do
let(:args) { { last: 1, before: encode_cursor(foo: 3) } }
- it 'raises argument error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ it 'generates an argument error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ subject
+ end
end
end
diff --git a/spec/graphql/resolvers/paginated_tree_resolver_spec.rb b/spec/graphql/resolvers/paginated_tree_resolver_spec.rb
index 82b05937aa3..4b05e9076d7 100644
--- a/spec/graphql/resolvers/paginated_tree_resolver_spec.rb
+++ b/spec/graphql/resolvers/paginated_tree_resolver_spec.rb
@@ -65,7 +65,11 @@ RSpec.describe Resolvers::PaginatedTreeResolver do
context 'when cursor is invalid' do
let(:args) { super().merge(after: 'invalid') }
- it { expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError) }
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ subject
+ end
+ end
end
it 'returns all tree entries during cursor pagination' do
diff --git a/spec/graphql/resolvers/project_milestones_resolver_spec.rb b/spec/graphql/resolvers/project_milestones_resolver_spec.rb
index e168291c804..2cf490c2b6a 100644
--- a/spec/graphql/resolvers/project_milestones_resolver_spec.rb
+++ b/spec/graphql/resolvers/project_milestones_resolver_spec.rb
@@ -103,27 +103,27 @@ RSpec.describe Resolvers::ProjectMilestonesResolver do
end
context 'when start date is after end_date' do
- it 'raises error' do
- expect do
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'startDate is after endDate') do
resolve_project_milestones(start_date: Time.now, end_date: Time.now - 2.days)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, "startDate is after endDate")
+ end
end
end
end
context 'when only start_date is present' do
- it 'raises error' do
- expect do
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
resolve_project_milestones(start_date: Time.now)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
+ end
end
end
context 'when only end_date is present' do
- it 'raises error' do
- expect do
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
resolve_project_milestones(end_date: Time.now)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/)
+ end
end
end
@@ -174,12 +174,12 @@ RSpec.describe Resolvers::ProjectMilestonesResolver do
end
context 'when user cannot read milestones' do
- it 'raises error' do
+ it 'generates an error' do
unauthorized_user = create(:user)
- expect do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_project_milestones({}, { current_user: unauthorized_user })
- end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
end
end
end
diff --git a/spec/graphql/resolvers/project_pipeline_resolver_spec.rb b/spec/graphql/resolvers/project_pipeline_resolver_spec.rb
index 6a8aa39f3b2..398f8f52269 100644
--- a/spec/graphql/resolvers/project_pipeline_resolver_spec.rb
+++ b/spec/graphql/resolvers/project_pipeline_resolver_spec.rb
@@ -85,13 +85,15 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
end
it 'errors when no iid or sha is passed' do
- expect { resolve_pipeline(project, {}) }
- .to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ resolve_pipeline(project, {})
+ end
end
it 'errors when both iid and sha are passed' do
- expect { resolve_pipeline(project, { iid: '1234', sha: 'sha' }) }
- .to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ resolve_pipeline(project, { iid: '1234', sha: 'sha' })
+ end
end
context 'when the pipeline is a dangling pipeline' do
diff --git a/spec/graphql/resolvers/project_resolver_spec.rb b/spec/graphql/resolvers/project_resolver_spec.rb
index cd3fdc788e6..dec9d4701e1 100644
--- a/spec/graphql/resolvers/project_resolver_spec.rb
+++ b/spec/graphql/resolvers/project_resolver_spec.rb
@@ -36,8 +36,8 @@ RSpec.describe Resolvers::ProjectResolver do
field1 = Types::BaseField.new(name: 'test', type: GraphQL::Types::String, resolver_class: described_class, null: false, max_page_size: 100)
field2 = Types::BaseField.new(name: 'test', type: GraphQL::Types::String, resolver_class: described_class, null: false, max_page_size: 1)
- expect(field1.to_graphql.complexity.call({}, {}, 1)).to eq 2
- expect(field2.to_graphql.complexity.call({}, {}, 1)).to eq 2
+ expect(field1.complexity.call({}, {}, 1)).to eq 2
+ expect(field2.complexity.call({}, {}, 1)).to eq 2
end
def resolve_project(full_path)
diff --git a/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb b/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb
index c6d8c518fb7..b95bab41e3e 100644
--- a/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb
+++ b/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb
@@ -14,10 +14,10 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do
let_it_be(:project) { create(:project) }
shared_examples 'no project service access' do
- it 'raises error' do
- expect do
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_jira_projects
- end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
end
end
@@ -89,11 +89,14 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do
.to_raise(JIRA::HTTPError.new(double(message: '{"errorMessages":["Some failure"]}')))
end
- it 'raises failure error' do
+ it 'generates a failure error' do
config_docs_link_url = Rails.application.routes.url_helpers.help_page_path('integration/jira/configure')
docs_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: config_docs_link_url }
error_message = 'An error occurred while requesting data from Jira: Some failure. Check your %{docs_link_start}Jira integration configuration</a> and try again.' % { docs_link_start: docs_link_start }
- expect { resolve_jira_projects }.to raise_error(error_message)
+
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::BaseError, error_message) do
+ resolve_jira_projects
+ end
end
end
end
diff --git a/spec/graphql/resolvers/projects/snippets_resolver_spec.rb b/spec/graphql/resolvers/projects/snippets_resolver_spec.rb
index 2d8929c0e8f..b963f2509db 100644
--- a/spec/graphql/resolvers/projects/snippets_resolver_spec.rb
+++ b/spec/graphql/resolvers/projects/snippets_resolver_spec.rb
@@ -81,12 +81,14 @@ RSpec.describe Resolvers::Projects::SnippetsResolver do
end
context 'when project snippets are disabled' do
- it 'raises an error' do
+ it 'generates an error' do
disabled_snippet_project = create(:project, :snippets_disabled)
disabled_snippet_project.add_developer(current_user)
expect(SnippetsFinder).not_to receive(:new)
- expect { resolve_snippets(obj: disabled_snippet_project) }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ resolve_snippets(obj: disabled_snippet_project)
+ end
end
end
end
diff --git a/spec/graphql/resolvers/snippets_resolver_spec.rb b/spec/graphql/resolvers/snippets_resolver_spec.rb
index 11cb1c0ec4b..f9feb8901cd 100644
--- a/spec/graphql/resolvers/snippets_resolver_spec.rb
+++ b/spec/graphql/resolvers/snippets_resolver_spec.rb
@@ -108,15 +108,15 @@ RSpec.describe Resolvers::SnippetsResolver do
end.to raise_error(GraphQL::CoercionError, '"foo" is not a valid Global ID')
end
- it 'returns an error if both project and author are provided' do
- expect do
+ it 'generates an error if both project and author are provided' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
args = {
author_id: current_user.to_global_id,
project_id: project.to_global_id
}
resolve_snippets(args: args)
- end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ end
end
end
end
diff --git a/spec/graphql/resolvers/timelog_resolver_spec.rb b/spec/graphql/resolvers/timelog_resolver_spec.rb
index 9b3f555071e..84fa2932829 100644
--- a/spec/graphql/resolvers/timelog_resolver_spec.rb
+++ b/spec/graphql/resolvers/timelog_resolver_spec.rb
@@ -85,27 +85,30 @@ RSpec.describe Resolvers::TimelogResolver do
context 'when start_time and start_date are present' do
let(:args) { { start_time: 6.days.ago, start_date: 6.days.ago } }
- it 'returns correct error' do
- expect { timelogs }
- .to raise_error(error_class, /Provide either a start date or time, but not both/)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(error_class, /Provide either a start date or time, but not both/) do
+ timelogs
+ end
end
end
context 'when end_time and end_date are present' do
let(:args) { { end_time: 2.days.ago, end_date: 2.days.ago } }
- it 'returns correct error' do
- expect { timelogs }
- .to raise_error(error_class, /Provide either an end date or time, but not both/)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(error_class, /Provide either an end date or time, but not both/) do
+ timelogs
+ end
end
end
context 'when start argument is after end argument' do
let(:args) { { start_time: 2.days.ago, end_time: 6.days.ago } }
- it 'returns correct error' do
- expect { timelogs }
- .to raise_error(error_class, /Start argument must be before End argument/)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(error_class, /Start argument must be before End argument/) do
+ timelogs
+ end
end
end
end
@@ -170,27 +173,30 @@ RSpec.describe Resolvers::TimelogResolver do
context 'when start_time and start_date are present' do
let(:args) { { start_time: short_time_ago, start_date: short_time_ago } }
- it 'returns correct error' do
- expect { timelogs }
- .to raise_error(error_class, /Provide either a start date or time, but not both/)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(error_class, /Provide either a start date or time, but not both/) do
+ timelogs
+ end
end
end
context 'when end_time and end_date are present' do
let(:args) { { end_time: short_time_ago, end_date: short_time_ago } }
- it 'returns correct error' do
- expect { timelogs }
- .to raise_error(error_class, /Provide either an end date or time, but not both/)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(error_class, /Provide either an end date or time, but not both/) do
+ timelogs
+ end
end
end
context 'when start argument is after end argument' do
let(:args) { { start_time: short_time_ago, end_time: medium_time_ago } }
- it 'returns correct error' do
- expect { timelogs }
- .to raise_error(error_class, /Start argument must be before End argument/)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(error_class, /Start argument must be before End argument/) do
+ timelogs
+ end
end
end
end
@@ -273,9 +279,10 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { {} }
let(:extra_args) { {} }
- it 'returns correct error' do
- expect { timelogs }
- .to raise_error(error_class, /Provide at least one argument/)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(error_class, /Provide at least one argument/) do
+ timelogs
+ end
end
end
diff --git a/spec/graphql/resolvers/topics_resolver_spec.rb b/spec/graphql/resolvers/topics_resolver_spec.rb
index 3ff1dabc927..89f4583bce8 100644
--- a/spec/graphql/resolvers/topics_resolver_spec.rb
+++ b/spec/graphql/resolvers/topics_resolver_spec.rb
@@ -6,9 +6,9 @@ RSpec.describe Resolvers::TopicsResolver do
include GraphqlHelpers
describe '#resolve' do
- let!(:topic1) { create(:topic, name: 'GitLab', total_projects_count: 1) }
- let!(:topic2) { create(:topic, name: 'git', total_projects_count: 2) }
- let!(:topic3) { create(:topic, name: 'topic3', total_projects_count: 3) }
+ let!(:topic1) { create(:topic, name: 'GitLab', non_private_projects_count: 1) }
+ let!(:topic2) { create(:topic, name: 'git', non_private_projects_count: 2) }
+ let!(:topic3) { create(:topic, name: 'topic3', non_private_projects_count: 3) }
it 'finds all topics' do
expect(resolve_topics).to eq([topic3, topic2, topic1])
diff --git a/spec/graphql/resolvers/user_discussions_count_resolver_spec.rb b/spec/graphql/resolvers/user_discussions_count_resolver_spec.rb
index 70f06b58a65..ef70418ab4b 100644
--- a/spec/graphql/resolvers/user_discussions_count_resolver_spec.rb
+++ b/spec/graphql/resolvers/user_discussions_count_resolver_spec.rb
@@ -43,7 +43,9 @@ RSpec.describe Resolvers::UserDiscussionsCountResolver do
subject { batch_sync { resolve_user_discussions_count(private_issue) } }
it 'returns no discussions' 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/user_notes_count_resolver_spec.rb b/spec/graphql/resolvers/user_notes_count_resolver_spec.rb
index bc173b2a166..b3368d532b2 100644
--- a/spec/graphql/resolvers/user_notes_count_resolver_spec.rb
+++ b/spec/graphql/resolvers/user_notes_count_resolver_spec.rb
@@ -44,8 +44,10 @@ 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 'raises an error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ subject
+ end
end
end
end
@@ -80,8 +82,10 @@ 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 'raises an error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
+ subject
+ end
end
end
end
diff --git a/spec/graphql/resolvers/user_resolver_spec.rb b/spec/graphql/resolvers/user_resolver_spec.rb
index 3ee9f63d832..446d765d3ee 100644
--- a/spec/graphql/resolvers/user_resolver_spec.rb
+++ b/spec/graphql/resolvers/user_resolver_spec.rb
@@ -9,15 +9,17 @@ RSpec.describe Resolvers::UserResolver do
let_it_be(:user) { create(:user) }
context 'when neither an ID or a username is provided' do
- it 'raises an ArgumentError' do
- expect { resolve_user }
- .to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ it 'generates an ArgumentError' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ resolve_user
+ end
end
end
- it 'raises an ArgumentError when both an ID and username are provided' do
- expect { resolve_user(id: user.to_global_id, username: user.username) }
- .to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ it 'generates an ArgumentError when both an ID and username are provided' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ resolve_user(id: user.to_global_id, username: user.username)
+ end
end
context 'by username' do
diff --git a/spec/graphql/resolvers/users_resolver_spec.rb b/spec/graphql/resolvers/users_resolver_spec.rb
index 29947c33430..b01cc0d43e3 100644
--- a/spec/graphql/resolvers/users_resolver_spec.rb
+++ b/spec/graphql/resolvers/users_resolver_spec.rb
@@ -14,10 +14,12 @@ RSpec.describe Resolvers::UsersResolver do
end
describe '#resolve' do
- it 'raises an error when read_users_list is not authorized' do
+ it 'generates an error when read_users_list is not authorized' do
expect(Ability).to receive(:allowed?).with(current_user, :read_users_list).and_return(false)
- 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
context 'when no arguments are passed' do
@@ -27,9 +29,10 @@ RSpec.describe Resolvers::UsersResolver do
end
context 'when both ids and usernames are passed ' do
- it 'raises an error' do
- expect { resolve_users( args: { ids: [user1.to_global_id.to_s], usernames: [user1.username] } ) }
- .to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ it 'generates an error' do
+ expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
+ resolve_users( args: { ids: [user1.to_global_id.to_s], usernames: [user1.username] } )
+ end
end
end
diff --git a/spec/graphql/resolvers/work_item_resolver_spec.rb b/spec/graphql/resolvers/work_item_resolver_spec.rb
new file mode 100644
index 00000000000..c7e2beecb51
--- /dev/null
+++ b/spec/graphql/resolvers/work_item_resolver_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Resolvers::WorkItemResolver do
+ include GraphqlHelpers
+
+ describe '#resolve' do
+ let_it_be(:developer) { create(:user) }
+ let_it_be(:project) { create(:project, :private).tap { |project| project.add_developer(developer) } }
+ let_it_be(:work_item) { create(:work_item, project: project) }
+
+ let(:current_user) { developer }
+
+ subject(:resolved_work_item) { resolve_work_item('id' => work_item.to_gid.to_s) }
+
+ context 'when the user can read the work item' do
+ it { is_expected.to eq(work_item) }
+ end
+
+ context 'when the user can not read the work item' 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)
+ end
+ end
+
+ context 'when the work_items feature flag is disabled' do
+ before do
+ stub_feature_flags(work_items: false)
+ end
+
+ it { is_expected.to be_nil }
+ end
+ end
+
+ private
+
+ def resolve_work_item(args = {})
+ resolve(described_class, args: args, ctx: { current_user: current_user })
+ 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 b85989256b5..f7aeed30fd3 100644
--- a/spec/graphql/resolvers/work_items/types_resolver_spec.rb
+++ b/spec/graphql/resolvers/work_items/types_resolver_spec.rb
@@ -7,16 +7,51 @@ RSpec.describe Resolvers::WorkItems::TypesResolver do
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group) }
+ let_it_be(:project) { create(:project, group: group) }
before_all do
group.add_developer(current_user)
end
- describe '#resolve' do
- it 'returns all default work item types' do
- result = resolve(described_class, obj: group)
+ shared_examples 'a work item type resolver' do
+ let(:args) { {} }
+
+ subject(:result) { resolve(described_class, obj: object, args: args) }
+ it 'returns all default work item types' do
expect(result.to_a).to match(WorkItems::Type.default.order_by_name_asc)
end
+
+ context 'when requesting taskable types' do
+ let(:args) { { taskable: true } }
+
+ it 'returns only taskable types' do
+ expect(result.to_a).to contain_exactly(WorkItems::Type.default_by_type(:task))
+ end
+ end
+
+ context 'when work_items feature flag is disabled' do
+ before do
+ stub_feature_flags(work_items: false)
+ end
+
+ it 'returns nil' do
+ expect(result).to be_nil
+ end
+ end
+ end
+
+ describe '#resolve' do
+ context 'when parent is a group' do
+ let(:object) { group }
+
+ it_behaves_like 'a work item type resolver'
+ end
+
+ context 'when parent is a project' do
+ let(:object) { project }
+
+ it_behaves_like 'a work item type resolver'
+ end
end
end