diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-02 18:07:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-02 18:07:42 +0000 |
commit | 7b52c7cb634ef7047d30b0337fe477bcdcedf41d (patch) | |
tree | 374ca9e908204488422046f10e340d1500780362 /spec/graphql/mutations | |
parent | b375c6c05fbd03aea33a9ee9f82e678bdaa8c3cc (diff) | |
download | gitlab-ce-7b52c7cb634ef7047d30b0337fe477bcdcedf41d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql/mutations')
-rw-r--r-- | spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb b/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb new file mode 100644 index 00000000000..064ad90f707 --- /dev/null +++ b/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Mutations::ResolvesIssuable do + let(:mutation_class) do + Class.new(Mutations::BaseMutation) do + include Mutations::ResolvesIssuable + end + end + + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:context) { { current_user: user } } + let(:mutation) { mutation_class.new(object: nil, context: context) } + + shared_examples 'resolving an issuable' do |type| + context 'when user has access' do + let(:source) { type == :merge_request ? 'source_project' : 'project' } + let(:issuable) { create(type, author: user, "#{source}" => project) } + + subject { mutation.resolve_issuable(type: type, parent_path: project.full_path, iid: issuable.iid) } + + before do + project.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 + resolved_project = mutation.resolve_project(full_path: project.full_path) + + allow(mutation).to receive(:resolve_project) + .with(full_path: project.full_path) + .and_return(resolved_project) + + expect(resolver_class).to receive(:new) + .with(object: resolved_project, context: context) + .and_call_original + + subject + end + + it 'uses the ResolvesProject to resolve project' do + expect(Resolvers::ProjectResolver).to receive(:new) + .with(object: nil, context: context) + .and_call_original + + subject + end + + it 'returns nil if issuable is not found' do + result = mutation.resolve_issuable(type: type, parent_path: project.full_path, iid: "100") + result = type == :merge_request ? result.sync : result + + expect(result).to be_nil + end + end + end + + context 'with issues' do + it_behaves_like 'resolving an issuable', :issue + end + + context 'with merge requests' do + it_behaves_like 'resolving an issuable', :merge_request + end +end |