diff options
Diffstat (limited to 'spec/lib/gitlab/graphql/markdown_field_spec.rb')
-rw-r--r-- | spec/lib/gitlab/graphql/markdown_field_spec.rb | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/spec/lib/gitlab/graphql/markdown_field_spec.rb b/spec/lib/gitlab/graphql/markdown_field_spec.rb index ed3f19d8cf2..974951ab30c 100644 --- a/spec/lib/gitlab/graphql/markdown_field_spec.rb +++ b/spec/lib/gitlab/graphql/markdown_field_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe Gitlab::Graphql::MarkdownField do include Gitlab::Routing + include GraphqlHelpers describe '.markdown_field' do it 'creates the field with some default attributes' do @@ -21,21 +22,12 @@ RSpec.describe Gitlab::Graphql::MarkdownField do expect { class_with_markdown_field(:test_html, null: true, resolver: 'not really') } .to raise_error(expected_error) end - - # TODO: remove as part of https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27536 - # so that until that time, the developer check is there - it 'raises when passing a resolve block' do - expect { class_with_markdown_field(:test_html, null: true, resolve: -> (_, _, _) { 'not really' } ) } - .to raise_error(expected_error) - end end context 'resolving markdown' do let_it_be(:note) { build(:note, note: '# Markdown!') } let_it_be(:expected_markdown) { '<h1 data-sourcepos="1:1-1:11" dir="auto">Markdown!</h1>' } - let_it_be(:query_type) { GraphQL::ObjectType.new } - let_it_be(:schema) { GraphQL::Schema.define(query: query_type, mutation: nil)} - let_it_be(:query) { GraphQL::Query.new(schema, document: nil, context: {}, variables: {}) } + let_it_be(:query) { GraphQL::Query.new(empty_schema, document: nil, context: {}, variables: {}) } let_it_be(:context) { GraphQL::Query::Context.new(query: query, values: {}, object: nil) } let(:type_class) { class_with_markdown_field(:note_html, null: false) } @@ -55,6 +47,20 @@ RSpec.describe Gitlab::Graphql::MarkdownField do end end + context 'when a block is passed for the resolved object' do + let(:type_class) do + class_with_markdown_field(:note_html, null: false) do |resolved_object| + resolved_object.object + end + end + + let(:type_instance) { type_class.authorized_new(class_wrapped_object(note), context) } + + it 'renders markdown from the same property as the field name without the `_html` suffix' do + expect(field.resolve(type_instance, {}, context)).to eq(expected_markdown) + end + end + describe 'basic verification that references work' do let_it_be(:project) { create(:project, :public) } @@ -83,12 +89,22 @@ RSpec.describe Gitlab::Graphql::MarkdownField do end end - def class_with_markdown_field(name, **args) + def class_with_markdown_field(name, **args, &blk) Class.new(Types::BaseObject) do prepend Gitlab::Graphql::MarkdownField graphql_name 'MarkdownFieldTest' - markdown_field name, **args + markdown_field name, **args, &blk end end + + def class_wrapped_object(object) + Class.new do + def initialize(object) + @object = object + end + + attr_accessor :object + end.new(object) + end end |