diff options
Diffstat (limited to 'spec/graphql/types/snippets/blob_type_spec.rb')
-rw-r--r-- | spec/graphql/types/snippets/blob_type_spec.rb | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/spec/graphql/types/snippets/blob_type_spec.rb b/spec/graphql/types/snippets/blob_type_spec.rb index bfac08f40d3..60c0db8e551 100644 --- a/spec/graphql/types/snippets/blob_type_spec.rb +++ b/spec/graphql/types/snippets/blob_type_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['SnippetBlob'] do + include GraphqlHelpers + it 'has the correct fields' do expected_fields = [:rich_data, :plain_data, :raw_path, :size, :binary, :name, :path, @@ -12,16 +14,37 @@ RSpec.describe GitlabSchema.types['SnippetBlob'] do expect(described_class).to have_graphql_fields(*expected_fields) end - specify { expect(described_class.fields['richData'].type).not_to be_non_null } - specify { expect(described_class.fields['plainData'].type).not_to be_non_null } - specify { expect(described_class.fields['rawPath'].type).to be_non_null } - specify { expect(described_class.fields['size'].type).to be_non_null } - specify { expect(described_class.fields['binary'].type).to be_non_null } - specify { expect(described_class.fields['name'].type).not_to be_non_null } - specify { expect(described_class.fields['path'].type).not_to be_non_null } - specify { expect(described_class.fields['simpleViewer'].type).to be_non_null } - specify { expect(described_class.fields['richViewer'].type).not_to be_non_null } - specify { expect(described_class.fields['mode'].type).not_to be_non_null } - specify { expect(described_class.fields['externalStorage'].type).not_to be_non_null } - specify { expect(described_class.fields['renderedAsText'].type).to be_non_null } + let_it_be(:nullity) do + { + 'richData' => be_nullable, + 'plainData' => be_nullable, + 'rawPath' => be_non_null, + 'size' => be_non_null, + 'binary' => be_non_null, + 'name' => be_nullable, + 'path' => be_nullable, + 'simpleViewer' => be_non_null, + 'richViewer' => be_nullable, + 'mode' => be_nullable, + 'externalStorage' => be_nullable, + 'renderedAsText' => be_non_null + } + end + + let_it_be(:blob) { create(:snippet, :public, :repository).blobs.first } + + shared_examples 'a field from the snippet blob presenter' do |field| + it "resolves using the presenter", :request_store do + presented = SnippetBlobPresenter.new(blob) + + expect(resolve_field(field, blob)).to eq(presented.try(field.method_sym)) + end + end + + described_class.fields.each_value do |field| + describe field.graphql_name do + it_behaves_like 'a field from the snippet blob presenter', field + specify { expect(field.type).to match(nullity.fetch(field.graphql_name)) } + end + end end |