Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 18:08:16 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 18:08:16 +0300
commite80e0dd64fbb04f60394cb1bb08e17dbcb22b8ce (patch)
tree9e538341b9b77e96737964813e10235dbecf47ff /spec/support/shared_examples/graphql
parentef31adeb0fb9a02b2c6a4529ec4e38d7082a4b2b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_examples/graphql')
-rw-r--r--spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb b/spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb
new file mode 100644
index 00000000000..b56181371c3
--- /dev/null
+++ b/spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'resolving an issuable in GraphQL' do |type|
+ subject { mutation.resolve_issuable(type: type, parent_path: parent.full_path, iid: issuable.iid) }
+
+ context 'when user has access' do
+ before do
+ parent.add_developer(user)
+ end
+
+ it 'resolves issuable by iid' do
+ result = type == :merge_request ? subject.sync : subject
+ expect(result).to eq(issuable)
+ end
+
+ it 'uses the correct Resolver to resolve issuable' do
+ resolver_class = "Resolvers::#{type.to_s.classify.pluralize}Resolver".constantize
+ resolve_method = type == :epic ? :resolve_group : :resolve_project
+ resolved_parent = mutation.send(resolve_method, full_path: parent.full_path)
+
+ allow(mutation).to receive(resolve_method)
+ .with(full_path: parent.full_path)
+ .and_return(resolved_parent)
+
+ expect(resolver_class).to receive(:new)
+ .with(object: resolved_parent, context: context, field: nil)
+ .and_call_original
+
+ subject
+ end
+
+ it 'uses correct Resolver to resolve issuable parent' do
+ resolver_class = type == :epic ? 'Resolvers::GroupResolver' : 'Resolvers::ProjectResolver'
+
+ expect(resolver_class.constantize).to receive(:new)
+ .with(object: nil, context: context, field: nil)
+ .and_call_original
+
+ subject
+ end
+
+ it 'returns nil if issuable is not found' do
+ result = mutation.resolve_issuable(type: type, parent_path: parent.full_path, iid: "100")
+ result = type == :merge_request ? result.sync : result
+
+ expect(result).to be_nil
+ end
+
+ it 'returns nil if parent path is not present' do
+ result = mutation.resolve_issuable(type: type, parent_path: "", iid: issuable.iid)
+
+ expect(result).to be_nil
+ end
+ end
+end