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/graphql | |
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/graphql')
-rw-r--r-- | spec/graphql/types/issue_type_spec.rb | 2 | ||||
-rw-r--r-- | spec/graphql/types/merge_request_type_spec.rb | 2 | ||||
-rw-r--r-- | spec/graphql/types/notes/diff_position_type_spec.rb | 12 | ||||
-rw-r--r-- | spec/graphql/types/notes/discussion_type_spec.rb | 8 | ||||
-rw-r--r-- | spec/graphql/types/notes/note_type_spec.rb | 15 | ||||
-rw-r--r-- | spec/graphql/types/notes/noteable_type_spec.rb | 13 | ||||
-rw-r--r-- | spec/graphql/types/permission_types/note_spec.rb | 11 |
7 files changed, 63 insertions, 0 deletions
diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb index bae560829cc..210932f8488 100644 --- a/spec/graphql/types/issue_type_spec.rb +++ b/spec/graphql/types/issue_type_spec.rb @@ -7,6 +7,8 @@ describe GitlabSchema.types['Issue'] do it { expect(described_class).to require_graphql_authorizations(:read_issue) } + it { expect(described_class.interfaces).to include(Types::Notes::NoteableType.to_graphql) } + it 'has specific fields' do %i[relative_position web_path web_url reference].each do |field_name| expect(described_class).to have_graphql_field(field_name) diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 89c12879074..fd1c782bcc5 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -5,6 +5,8 @@ describe GitlabSchema.types['MergeRequest'] do it { expect(described_class).to require_graphql_authorizations(:read_merge_request) } + it { expect(described_class.interfaces).to include(Types::Notes::NoteableType.to_graphql) } + describe 'nested head pipeline' do it { expect(described_class).to have_graphql_field(:head_pipeline) } end diff --git a/spec/graphql/types/notes/diff_position_type_spec.rb b/spec/graphql/types/notes/diff_position_type_spec.rb new file mode 100644 index 00000000000..2f8724d7f0d --- /dev/null +++ b/spec/graphql/types/notes/diff_position_type_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe GitlabSchema.types['DiffPosition'] do + it 'exposes the expected fields' do + expected_fields = [:head_sha, :base_sha, :start_sha, :file_path, :old_path, + :new_path, :position_type, :old_line, :new_line, :x, :y, + :width, :height] + + is_expected.to have_graphql_field(*expected_fields) + end +end diff --git a/spec/graphql/types/notes/discussion_type_spec.rb b/spec/graphql/types/notes/discussion_type_spec.rb new file mode 100644 index 00000000000..2a1eb0efd35 --- /dev/null +++ b/spec/graphql/types/notes/discussion_type_spec.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe GitlabSchema.types['Discussion'] do + it { is_expected.to have_graphql_fields(:id, :created_at, :notes) } + + it { is_expected.to require_graphql_authorizations(:read_note) } +end diff --git a/spec/graphql/types/notes/note_type_spec.rb b/spec/graphql/types/notes/note_type_spec.rb new file mode 100644 index 00000000000..8022b20f9dd --- /dev/null +++ b/spec/graphql/types/notes/note_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe GitlabSchema.types['Note'] do + it 'exposes the expected fields' do + expected_fields = [:id, :project, :author, :body, :created_at, + :updated_at, :discussion, :resolvable, :position, :user_permissions, + :resolved_by, :resolved_at, :system] + + is_expected.to have_graphql_fields(*expected_fields) + end + + it { is_expected.to expose_permissions_using(Types::PermissionTypes::Note) } + it { is_expected.to require_graphql_authorizations(:read_note) } +end diff --git a/spec/graphql/types/notes/noteable_type_spec.rb b/spec/graphql/types/notes/noteable_type_spec.rb new file mode 100644 index 00000000000..d10c79b5344 --- /dev/null +++ b/spec/graphql/types/notes/noteable_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe Types::Notes::NoteableType do + it { is_expected.to have_graphql_fields(:notes, :discussions) } + + describe ".resolve_type" do + it 'knows the correct type for objects' do + expect(described_class.resolve_type(build(:issue), {})).to eq(Types::IssueType) + expect(described_class.resolve_type(build(:merge_request), {})).to eq(Types::MergeRequestType) + end + end +end diff --git a/spec/graphql/types/permission_types/note_spec.rb b/spec/graphql/types/permission_types/note_spec.rb new file mode 100644 index 00000000000..32d56eb1f7a --- /dev/null +++ b/spec/graphql/types/permission_types/note_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe GitlabSchema.types['NotePermissions'] do + it 'has the expected fields' do + expected_permissions = [ + :read_note, :create_note, :admin_note, :resolve_note, :award_emoji + ] + + is_expected.to have_graphql_fields(expected_permissions) + end +end |