diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/graphql/resolvers/snippets/blobs_resolver_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/graphql/resolvers/snippets/blobs_resolver_spec.rb')
-rw-r--r-- | spec/graphql/resolvers/snippets/blobs_resolver_spec.rb | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/spec/graphql/resolvers/snippets/blobs_resolver_spec.rb b/spec/graphql/resolvers/snippets/blobs_resolver_spec.rb index 16e69f662c0..ebe286769cf 100644 --- a/spec/graphql/resolvers/snippets/blobs_resolver_spec.rb +++ b/spec/graphql/resolvers/snippets/blobs_resolver_spec.rb @@ -16,16 +16,18 @@ RSpec.describe Resolvers::Snippets::BlobsResolver do 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) + it 'redacts the field' do + expect(resolve_blobs(snippet, user: other_user)).to be_nil 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) + result = resolve_blobs(snippet, args: {}) + + expect(result).to match_array(snippet.list_files.map do |file| + have_attributes(path: file) + end) end end @@ -34,7 +36,13 @@ RSpec.describe Resolvers::Snippets::BlobsResolver do it 'returns an array of files' do path = 'CHANGELOG' - expect(resolve_blobs(snippet, args: { paths: path }).first.path).to eq(path) + expect(resolve_blobs(snippet, paths: [path])).to contain_exactly(have_attributes(path: path)) + end + end + + context 'the argument does not match anything' do + it 'returns an empty result' do + expect(resolve_blobs(snippet, paths: ['does not exist'])).to be_empty end end @@ -42,13 +50,15 @@ RSpec.describe Resolvers::Snippets::BlobsResolver 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) + expect(resolve_blobs(snippet, paths: paths)).to match_array(paths.map do |file| + have_attributes(path: file) + end) end end end end - def resolve_blobs(snippet, user: current_user, args: {}) + def resolve_blobs(snippet, user: current_user, paths: [], args: { paths: paths }) resolve(described_class, args: args, ctx: { current_user: user }, obj: snippet) end end |