diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-06-07 20:13:26 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-06-14 13:36:27 +0300 |
commit | b6ff5f1e141162e701c33647aae5015e5d42cc11 (patch) | |
tree | fb6ec57e96dc811d07c75d6b32f9471263c85166 /spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb | |
parent | 8934ddbb47d24dac937351588bc28551bd7654e7 (diff) |
Expose comments on Noteables in GraphQL
This exposes `Note`s on Issues & MergeRequests using a
`Types::Notes::NoteableType` in GraphQL.
Exposing notes on a new type can be done by implementing the
`NoteableType` interface on the type. The presented object should
be a `Noteable`.
Diffstat (limited to 'spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb b/spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb new file mode 100644 index 00000000000..323d1c51ffd --- /dev/null +++ b/spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true +require 'spec_helper' + +shared_context 'exposing regular notes on a noteable in GraphQL' do + include GraphqlHelpers + + let(:note) do + create(:note, + noteable: noteable, + project: (noteable.project if noteable.respond_to?(:project))) + end + let(:user) { note.author } + + context 'for regular notes' do + let(:query) do + note_fields = <<~NOTES + notes { + edges { + node { + #{all_graphql_fields_for('Note')} + } + } + } + NOTES + + noteable_query(note_fields) + end + + it_behaves_like 'a working graphql query' do + before do + post_graphql(query, current_user: user) + end + end + + it 'includes the note' do + post_graphql(query, current_user: user) + + expect(noteable_data['notes']['edges'].first['node']['body']) + .to eq(note.note) + end + end + + context "for discussions" do + let(:query) do + discussion_fields = <<~DISCUSSIONS + discussions { + edges { + node { + #{all_graphql_fields_for('Discussion')} + } + } + } + DISCUSSIONS + + noteable_query(discussion_fields) + end + + let!(:reply) { create(:note, noteable: noteable, in_reply_to: note, discussion_id: note.discussion_id) } + + it_behaves_like 'a working graphql query' do + before do + post_graphql(query, current_user: user) + end + end + + it 'includes all discussion notes' do + post_graphql(query, current_user: user) + + discussion = noteable_data['discussions']['edges'].first['node'] + ids = discussion['notes']['edges'].map { |note_edge| note_edge['node']['id'] } + + expect(ids).to eq([note.to_global_id.to_s, reply.to_global_id.to_s]) + end + end +end |