Commit 3abacca2 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fj-fix-bug-snippet-blob-viewer-graphql' into 'master'

Avoid some fields to be null in Snippet BlobViewer GraphQL definition

Closes #216338 and #216370

See merge request gitlab-org/gitlab!30927
parents f76cb49c 180203a5
......@@ -14,6 +14,7 @@ module Types
field :plain_data, GraphQL::STRING_TYPE,
description: 'Blob plain highlighted data',
calls_gitaly: true,
null: true
field :raw_path, GraphQL::STRING_TYPE,
......
......@@ -17,12 +17,14 @@ module Types
field :collapsed, GraphQL::BOOLEAN_TYPE,
description: 'Shows whether the blob should be displayed collapsed',
method: :collapsed?,
null: false
null: false,
resolve: -> (viewer, _args, _ctx) { !!viewer&.collapsed? }
field :too_large, GraphQL::BOOLEAN_TYPE,
description: 'Shows whether the blob too large to be displayed',
method: :too_large?,
null: false
null: false,
resolve: -> (viewer, _args, _ctx) { !!viewer&.too_large? }
field :render_error, GraphQL::STRING_TYPE,
description: 'Error rendering the blob content',
......
---
title: Fix bug in Snippet BlobViewer GraphQL definition
merge_request: 30927
author:
type: fixed
......@@ -3,10 +3,91 @@
require 'spec_helper'
describe GitlabSchema.types['SnippetBlobViewer'] do
let_it_be(:snippet) { create(:personal_snippet, :repository) }
let_it_be(:blob) { snippet.repository.blob_at('HEAD', 'files/images/6049019_460s.jpg') }
it 'has the correct fields' do
expected_fields = [:type, :load_async, :too_large, :collapsed,
:render_error, :file_type, :loading_partial_name]
expect(described_class).to have_graphql_fields(*expected_fields)
end
it { expect(described_class.fields['type'].type).to be_non_null }
it { expect(described_class.fields['loadAsync'].type).to be_non_null }
it { expect(described_class.fields['collapsed'].type).to be_non_null }
it { expect(described_class.fields['tooLarge'].type).to be_non_null }
it { expect(described_class.fields['renderError'].type).not_to be_non_null }
it { expect(described_class.fields['fileType'].type).to be_non_null }
it { expect(described_class.fields['loadingPartialName'].type).to be_non_null }
shared_examples 'nil field converted to false' do
subject { GitlabSchema.execute(query, context: { current_user: snippet.author }).as_json }
before do
allow_next_instance_of(SnippetPresenter) do |instance|
allow(instance).to receive(:blob).and_return(blob)
end
end
it 'returns false' do
snippet_blob = subject.dig('data', 'snippets', 'edges')[0].dig('node', 'blob')
expect(snippet_blob['path']).to eq blob.path
expect(blob_attribute).to be_nil
expect(snippet_blob['simpleViewer'][attribute]).to eq false
end
end
describe 'collapsed' do
it_behaves_like 'nil field converted to false' do
let(:query) do
%(
query {
snippets(ids:"#{snippet.to_global_id}"){
edges {
node {
blob {
path
simpleViewer {
collapsed
}
}
}
}
}
}
)
end
let(:attribute) { 'collapsed' }
let(:blob_attribute) { blob.simple_viewer.collapsed? }
end
end
describe 'tooLarge' do
it_behaves_like 'nil field converted to false' do
let(:query) do
%(
query {
snippets(ids:"#{snippet.to_global_id}"){
edges {
node {
blob {
path
simpleViewer {
tooLarge
}
}
}
}
}
}
)
end
let(:attribute) { 'tooLarge' }
let(:blob_attribute) { blob.simple_viewer.too_large? }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment