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/types/snippet_type_spec.rb | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'spec/graphql/types/snippet_type_spec.rb')
-rw-r--r-- | spec/graphql/types/snippet_type_spec.rb | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/spec/graphql/types/snippet_type_spec.rb b/spec/graphql/types/snippet_type_spec.rb index 86af69f1294..2ea215450cb 100644 --- a/spec/graphql/types/snippet_type_spec.rb +++ b/spec/graphql/types/snippet_type_spec.rb @@ -16,6 +16,15 @@ RSpec.describe GitlabSchema.types['Snippet'] do expect(described_class).to have_graphql_fields(*expected_fields) end + describe 'blobs field' do + subject { described_class.fields['blobs'] } + + it 'returns blobs' do + is_expected.to have_graphql_type(Types::Snippets::BlobType.connection_type) + is_expected.to have_graphql_resolver(Resolvers::Snippets::BlobsResolver) + end + end + context 'when restricted visibility level is set to public' do let_it_be(:snippet) { create(:personal_snippet, :repository, :public, author: user) } @@ -142,9 +151,30 @@ RSpec.describe GitlabSchema.types['Snippet'] do describe '#blobs' do let_it_be(:snippet) { create(:personal_snippet, :public, author: user) } - let(:query_blobs) { subject.dig('data', 'snippets', 'edges')[0]['node']['blobs'] } + let(:query_blobs) { subject.dig('data', 'snippets', 'edges')[0].dig('node', 'blobs', 'edges') } + let(:paths) { [] } + let(:query) do + %( + { + snippets { + edges { + node { + blobs(paths: #{paths}) { + edges { + node { + name + path + } + } + } + } + } + } + } + ) + end - subject { GitlabSchema.execute(snippet_query_for(field: 'blobs'), context: { current_user: user }).as_json } + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } shared_examples 'an array' do it 'returns an array of snippet blobs' do @@ -158,8 +188,8 @@ RSpec.describe GitlabSchema.types['Snippet'] do it_behaves_like 'an array' it 'contains the first blob from the snippet' do - expect(query_blobs.first['name']).to eq blob.name - expect(query_blobs.first['path']).to eq blob.path + expect(query_blobs.first['node']['name']).to eq blob.name + expect(query_blobs.first['node']['path']).to eq blob.path end end @@ -170,10 +200,22 @@ RSpec.describe GitlabSchema.types['Snippet'] do it_behaves_like 'an array' it 'contains all the blobs from the repository' do - resulting_blobs_names = query_blobs.map { |b| b['name'] } + resulting_blobs_names = query_blobs.map { |b| b['node']['name'] } expect(resulting_blobs_names).to match_array(blobs.map(&:name)) end + + context 'when specific path is set' do + let(:paths) { ['CHANGELOG'] } + + it_behaves_like 'an array' + + it 'returns specific files' do + resulting_blobs_names = query_blobs.map { |b| b['node']['name'] } + + expect(resulting_blobs_names).to match(paths) + end + end end end |