diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
commit | be834a25982746ffd85252ff502df42bb88cb9d5 (patch) | |
tree | b4d6a8ba0931e12fac08f05abea33a3b8ec2c8a2 /spec/graphql/resolvers/snippets/blobs_resolver_spec.rb | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'spec/graphql/resolvers/snippets/blobs_resolver_spec.rb')
-rw-r--r-- | spec/graphql/resolvers/snippets/blobs_resolver_spec.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/graphql/resolvers/snippets/blobs_resolver_spec.rb b/spec/graphql/resolvers/snippets/blobs_resolver_spec.rb new file mode 100644 index 00000000000..fdbd87c32be --- /dev/null +++ b/spec/graphql/resolvers/snippets/blobs_resolver_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Snippets::BlobsResolver do + include GraphqlHelpers + + describe '#resolve' do + let_it_be(:current_user) { create(:user) } + let_it_be(:snippet) { create(:personal_snippet, :private, :repository, author: current_user) } + + context 'when user is not authorized' do + let(:other_user) { create(:user) } + + it 'raises an error' do + expect do + resolve_blobs(snippet, user: other_user) + end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + + context 'when using no filter' do + it 'returns all snippet blobs' do + expect(resolve_blobs(snippet).map(&:path)).to contain_exactly(*snippet.list_files) + end + end + + context 'when using filters' do + context 'when paths is a single string' do + it 'returns an array of files' do + path = 'CHANGELOG' + + expect(resolve_blobs(snippet, args: { paths: path }).first.path).to eq(path) + end + end + + context 'when paths is an array of string' do + it 'returns an array of files' do + paths = ['CHANGELOG', 'README.md'] + + expect(resolve_blobs(snippet, args: { paths: paths }).map(&:path)).to contain_exactly(*paths) + end + end + end + end + + def resolve_blobs(snippet, user: current_user, args: {}) + resolve(described_class, args: args, ctx: { current_user: user }, obj: snippet) + end +end |