Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2019-06-07 20:13:26 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2019-06-14 13:36:27 +0300
commitb6ff5f1e141162e701c33647aae5015e5d42cc11 (patch)
treefb6ec57e96dc811d07c75d6b32f9471263c85166 /spec/requests/api/graphql
parent8934ddbb47d24dac937351588bc28551bd7654e7 (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/requests/api/graphql')
-rw-r--r--spec/requests/api/graphql/project/issue/notes_spec.rb24
-rw-r--r--spec/requests/api/graphql/project/merge_request/diff_notes_spec.rb90
2 files changed, 114 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/project/issue/notes_spec.rb b/spec/requests/api/graphql/project/issue/notes_spec.rb
new file mode 100644
index 00000000000..bfc89434370
--- /dev/null
+++ b/spec/requests/api/graphql/project/issue/notes_spec.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'getting notes for an issue' do
+ include GraphqlHelpers
+
+ let(:noteable) { create(:issue) }
+ let(:noteable_data) { graphql_data['project']['issue'] }
+
+ def noteable_query(noteable_fields)
+ <<~QRY
+ {
+ project(fullPath: "#{noteable.project.full_path}") {
+ issue(iid: "#{noteable.iid}") {
+ #{noteable_fields}
+ }
+ }
+ }
+ QRY
+ end
+
+ it_behaves_like 'exposing regular notes on a noteable in GraphQL'
+end
diff --git a/spec/requests/api/graphql/project/merge_request/diff_notes_spec.rb b/spec/requests/api/graphql/project/merge_request/diff_notes_spec.rb
new file mode 100644
index 00000000000..e260e4463f4
--- /dev/null
+++ b/spec/requests/api/graphql/project/merge_request/diff_notes_spec.rb
@@ -0,0 +1,90 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'getting notes for a merge request' do
+ include GraphqlHelpers
+
+ let(:noteable) { create(:merge_request) }
+
+ def noteable_query(noteable_fields)
+ <<~QRY
+ {
+ project(fullPath: "#{noteable.project.full_path}") {
+ id
+ mergeRequest(iid: "#{noteable.iid}") {
+ #{noteable_fields}
+ }
+ }
+ }
+ QRY
+ end
+ let(:noteable_data) { graphql_data['project']['mergeRequest'] }
+
+ it_behaves_like "exposing regular notes on a noteable in GraphQL"
+
+ context 'diff notes on a merge request' do
+ let(:project) { noteable.project }
+ let!(:note) { create(:diff_note_on_merge_request, noteable: noteable, project: project) }
+ let(:user) { note.author }
+
+ let(:query) do
+ noteable_query(
+ <<~NOTES
+ notes {
+ edges {
+ node {
+ #{all_graphql_fields_for('Note')}
+ }
+ }
+ }
+ NOTES
+ )
+ 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(graphql_data['project']['mergeRequest']['notes']['edges'].last['node']['body'])
+ .to eq(note.note)
+ end
+
+ context 'the position of the diffnote' do
+ it 'includes a correct position' do
+ post_graphql(query, current_user: user)
+
+ note_data = noteable_data['notes']['edges'].last['node']
+
+ expect(note_data['position']['positionType']).to eq('text')
+ expect(note_data['position']['newLine']).to be_present
+ expect(note_data['position']['x']).not_to be_present
+ expect(note_data['position']['y']).not_to be_present
+ expect(note_data['position']['width']).not_to be_present
+ expect(note_data['position']['height']).not_to be_present
+ end
+
+ context 'with a note on an image' do
+ let(:note) { create(:image_diff_note_on_merge_request, noteable: noteable, project: project) }
+
+ it 'includes a correct position' do
+ post_graphql(query, current_user: user)
+
+ note_data = noteable_data['notes']['edges'].last['node']
+
+ expect(note_data['position']['positionType']).to eq('image')
+ expect(note_data['position']['x']).to be_present
+ expect(note_data['position']['y']).to be_present
+ expect(note_data['position']['width']).to be_present
+ expect(note_data['position']['height']).to be_present
+ expect(note_data['position']['newLine']).not_to be_present
+ end
+ end
+ end
+ end
+end