diff options
| author | Achilleas Pipinellis <axil@gitlab.com> | 2019-08-20 20:22:43 +0200 |
|---|---|---|
| committer | Achilleas Pipinellis <axil@gitlab.com> | 2019-08-20 20:22:43 +0200 |
| commit | e61308ce1d82e12e5087371469baea4a452875d1 (patch) | |
| tree | 62551a3ae4eab75e5af7e3b35358c07a51b2132f /spec/graphql | |
| parent | 4f323bb62fbe71a4352de25cab141f361a3fe1a6 (diff) | |
| parent | 2989ed078c1d45b0959dcecb1bc3c8f4740a3c0d (diff) | |
| download | gitlab-ce-docs-patch-71.tar.gz | |
Merge branch 'master' into docs-patch-71docs-patch-71
Diffstat (limited to 'spec/graphql')
20 files changed, 240 insertions, 25 deletions
diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb index 4076c1f824b..dec6b23d72a 100644 --- a/spec/graphql/gitlab_schema_spec.rb +++ b/spec/graphql/gitlab_schema_spec.rb @@ -21,6 +21,10 @@ describe GitlabSchema do expect(field_instrumenters).to include(instance_of(::Gitlab::Graphql::Present::Instrumentation)) end + it 'enables using gitaly call checker' do + expect(field_instrumenters).to include(instance_of(::Gitlab::Graphql::CallsGitaly::Instrumentation)) + end + it 'has the base mutation' do expect(described_class.mutation).to eq(::Types::MutationType.to_graphql) end @@ -113,7 +117,7 @@ describe GitlabSchema do end it "raises a meaningful error if a global id couldn't be generated" do - expect { described_class.id_from_object(build(:commit)) } + expect { described_class.id_from_object(build(:wiki_directory)) } .to raise_error(RuntimeError, /include `GlobalID::Identification` into/i) end end @@ -139,6 +143,26 @@ describe GitlabSchema do end end + context 'for classes that are not ActiveRecord subclasses and have implemented .lazy_find' do + it 'returns the correct record' do + note = create(:discussion_note_on_merge_request) + + result = described_class.object_from_id(note.to_global_id) + + expect(result.__sync).to eq(note) + end + + it 'batchloads the queries' do + note1 = create(:discussion_note_on_merge_request) + note2 = create(:discussion_note_on_merge_request) + + expect do + [described_class.object_from_id(note1.to_global_id), + described_class.object_from_id(note2.to_global_id)].map(&:__sync) + end.not_to exceed_query_limit(1) + end + end + context 'for other classes' do # We cannot use an anonymous class here as `GlobalID` expects `.name` not # to return `nil` diff --git a/spec/graphql/resolvers/namespace_projects_resolver_spec.rb b/spec/graphql/resolvers/namespace_projects_resolver_spec.rb index 20e197e9f73..47591445fc0 100644 --- a/spec/graphql/resolvers/namespace_projects_resolver_spec.rb +++ b/spec/graphql/resolvers/namespace_projects_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::NamespaceProjectsResolver, :nested_groups do +describe Resolvers::NamespaceProjectsResolver do include GraphqlHelpers let(:current_user) { create(:user) } diff --git a/spec/graphql/types/award_emojis/award_emoji_type_spec.rb b/spec/graphql/types/award_emojis/award_emoji_type_spec.rb new file mode 100644 index 00000000000..5663a3d7195 --- /dev/null +++ b/spec/graphql/types/award_emojis/award_emoji_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['AwardEmoji'] do + it { expect(described_class.graphql_name).to eq('AwardEmoji') } + + it { is_expected.to require_graphql_authorizations(:read_emoji) } + + it { expect(described_class).to have_graphql_fields(:description, :unicode_version, :emoji, :name, :unicode, :user) } +end diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb index 0d3c3e37daf..77ef8933717 100644 --- a/spec/graphql/types/base_field_spec.rb +++ b/spec/graphql/types/base_field_spec.rb @@ -22,6 +22,24 @@ describe Types::BaseField do expect(field.to_graphql.complexity).to eq 1 end + describe '#base_complexity' do + context 'with no gitaly calls' do + it 'defaults to 1' do + field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, null: true) + + expect(field.base_complexity).to eq 1 + end + end + + context 'with a gitaly call' do + it 'adds 1 to the default value' do + field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, null: true, calls_gitaly: true) + + expect(field.base_complexity).to eq 2 + end + end + end + it 'has specified value' do field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, null: true, complexity: 12) @@ -52,5 +70,46 @@ describe Types::BaseField do end end end + + context 'calls_gitaly' do + context 'for fields with a resolver' do + it 'adds 1 if true' do + with_gitaly_field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, resolver_class: resolver, null: true, calls_gitaly: true) + without_gitaly_field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, resolver_class: resolver, null: true) + base_result = without_gitaly_field.to_graphql.complexity.call({}, {}, 2) + + expect(with_gitaly_field.to_graphql.complexity.call({}, {}, 2)).to eq base_result + 1 + end + end + + context 'for fields without a resolver' do + it 'adds 1 if true' do + field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, null: true, calls_gitaly: true) + + expect(field.to_graphql.complexity).to eq 2 + end + end + + it 'defaults to false' do + field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, null: true) + + expect(field.base_complexity).to eq Types::BaseField::DEFAULT_COMPLEXITY + end + + context 'with declared constant complexity value' do + it 'has complexity set to that constant' do + field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, null: true, complexity: 12) + + expect(field.to_graphql.complexity).to eq 12 + end + + it 'does not raise an error even with Gitaly calls' do + allow(Gitlab::GitalyClient).to receive(:get_request_count).and_return([0, 1]) + field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, null: true, complexity: 12) + + expect(field.to_graphql.complexity).to eq 12 + end + end + end end end diff --git a/spec/graphql/types/commit_type_spec.rb b/spec/graphql/types/commit_type_spec.rb new file mode 100644 index 00000000000..5d8edcf254c --- /dev/null +++ b/spec/graphql/types/commit_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['Commit'] do + it { expect(described_class.graphql_name).to eq('Commit') } + + it { expect(described_class).to require_graphql_authorizations(:download_code) } + + it { expect(described_class).to have_graphql_fields(:id, :sha, :title, :description, :message, :authored_date, :author, :web_url, :latest_pipeline) } +end diff --git a/spec/graphql/types/diff_refs_type_spec.rb b/spec/graphql/types/diff_refs_type_spec.rb new file mode 100644 index 00000000000..91017c827ad --- /dev/null +++ b/spec/graphql/types/diff_refs_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['DiffRefs'] do + it { expect(described_class.graphql_name).to eq('DiffRefs') } + + it { expect(described_class).to have_graphql_fields(:base_sha, :head_sha, :start_sha) } +end diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb index bae560829cc..799a8662b94 100644 --- a/spec/graphql/types/issue_type_spec.rb +++ b/spec/graphql/types/issue_type_spec.rb @@ -7,8 +7,13 @@ 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| + fields = %i[title_html description_html relative_position web_path web_url + reference] + + fields.each do |field_name| expect(described_class).to have_graphql_field(field_name) end end diff --git a/spec/graphql/types/label_type_spec.rb b/spec/graphql/types/label_type_spec.rb new file mode 100644 index 00000000000..8e7b2c69eff --- /dev/null +++ b/spec/graphql/types/label_type_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe GitlabSchema.types['Label'] do + it 'has the correct fields' do + expected_fields = [:description, :description_html, :title, :color, :text_color] + + is_expected.to have_graphql_fields(*expected_fields) + end + + it { is_expected.to require_graphql_authorizations(:read_label) } +end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 89c12879074..59bd0123d88 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -5,7 +5,22 @@ describe GitlabSchema.types['MergeRequest'] do it { expect(described_class).to require_graphql_authorizations(:read_merge_request) } - describe 'nested head pipeline' do - it { expect(described_class).to have_graphql_field(:head_pipeline) } + it { expect(described_class.interfaces).to include(Types::Notes::NoteableType.to_graphql) } + + it 'has the expected fields' do + expected_fields = %w[ + notes discussions user_permissions id iid title title_html description + description_html state created_at updated_at source_project target_project + project project_id source_project_id target_project_id source_branch + target_branch work_in_progress merge_when_pipeline_succeeds diff_head_sha + merge_commit_sha user_notes_count should_remove_source_branch diff_refs + force_remove_source_branch merge_status in_progress_merge_commit_sha + merge_error allow_collaboration should_be_rebased rebase_commit_sha + rebase_in_progress merge_commit_message default_merge_commit_message + merge_ongoing source_branch_exists mergeable_discussions_state web_url + upvotes downvotes subscribed head_pipeline pipelines task_completion_status + ] + + is_expected.to have_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/metadata_type_spec.rb b/spec/graphql/types/metadata_type_spec.rb index 55205bf5b6a..5236380e477 100644 --- a/spec/graphql/types/metadata_type_spec.rb +++ b/spec/graphql/types/metadata_type_spec.rb @@ -2,4 +2,5 @@ require 'spec_helper' describe GitlabSchema.types['Metadata'] do it { expect(described_class.graphql_name).to eq('Metadata') } + it { is_expected.to require_graphql_authorizations(:read_instance_metadata) } end diff --git a/spec/graphql/types/namespace_type_spec.rb b/spec/graphql/types/namespace_type_spec.rb index b4144cc4121..e1153832cc9 100644 --- a/spec/graphql/types/namespace_type_spec.rb +++ b/spec/graphql/types/namespace_type_spec.rb @@ -5,5 +5,14 @@ require 'spec_helper' describe GitlabSchema.types['Namespace'] do it { expect(described_class.graphql_name).to eq('Namespace') } - it { expect(described_class).to have_graphql_field(:projects) } + it 'has the expected fields' do + expected_fields = %w[ + id name path full_name full_path description description_html visibility + lfs_enabled request_access_enabled projects + ] + + is_expected.to have_graphql_fields(*expected_fields) + end + + it { is_expected.to require_graphql_authorizations(:read_namespace) } 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..345bca8f702 --- /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 = [:diff_refs, :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..ba7fc961212 --- /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, :reply_id) } + + 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..e8a58da4b17 --- /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, :body_html] + + 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 diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index cb5ac2e3cb1..69fbc72bdf5 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -7,18 +7,22 @@ describe GitlabSchema.types['Project'] do it { expect(described_class).to require_graphql_authorizations(:read_project) } - describe 'nested merge request' do - it { expect(described_class).to have_graphql_field(:merge_requests) } - it { expect(described_class).to have_graphql_field(:merge_request) } + it 'has the expected fields' do + expected_fields = %w[ + user_permissions id full_path path name_with_namespace + name description description_html tag_list ssh_url_to_repo + http_url_to_repo web_url star_count forks_count + created_at last_activity_at archived visibility + container_registry_enabled shared_runners_enabled + lfs_enabled merge_requests_ff_only_enabled avatar_url + issues_enabled merge_requests_enabled wiki_enabled + snippets_enabled jobs_enabled public_jobs open_issues_count import_status + only_allow_merge_if_pipeline_succeeds request_access_enabled + only_allow_merge_if_all_discussions_are_resolved printing_merge_request_link_enabled + namespace group statistics repository merge_requests merge_request issues + issue pipelines + ] + + is_expected.to have_graphql_fields(*expected_fields) end - - describe 'nested issues' do - it { expect(described_class).to have_graphql_field(:issues) } - end - - it { is_expected.to have_graphql_field(:pipelines) } - - it { is_expected.to have_graphql_field(:repository) } - - it { is_expected.to have_graphql_field(:statistics) } end diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index af1972a2513..bc3b8a42392 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -34,9 +34,5 @@ describe GitlabSchema.types['Query'] do is_expected.to have_graphql_type(Types::MetadataType) is_expected.to have_graphql_resolver(Resolvers::MetadataResolver) end - - it 'authorizes with read_instance_metadata' do - is_expected.to require_graphql_authorizations(:read_instance_metadata) - end end end diff --git a/spec/graphql/types/tree/submodule_type_spec.rb b/spec/graphql/types/tree/submodule_type_spec.rb index bdb3149b41c..768eccba68c 100644 --- a/spec/graphql/types/tree/submodule_type_spec.rb +++ b/spec/graphql/types/tree/submodule_type_spec.rb @@ -5,5 +5,5 @@ require 'spec_helper' describe Types::Tree::SubmoduleType do it { expect(described_class.graphql_name).to eq('Submodule') } - it { expect(described_class).to have_graphql_fields(:id, :name, :type, :path, :flat_path) } + it { expect(described_class).to have_graphql_fields(:id, :name, :type, :path, :flat_path, :web_url, :tree_url) } end diff --git a/spec/graphql/types/tree/tree_type_spec.rb b/spec/graphql/types/tree/tree_type_spec.rb index b9c5570115e..23779d75600 100644 --- a/spec/graphql/types/tree/tree_type_spec.rb +++ b/spec/graphql/types/tree/tree_type_spec.rb @@ -5,5 +5,5 @@ require 'spec_helper' describe Types::Tree::TreeType do it { expect(described_class.graphql_name).to eq('Tree') } - it { expect(described_class).to have_graphql_fields(:trees, :submodules, :blobs) } + it { expect(described_class).to have_graphql_fields(:trees, :submodules, :blobs, :last_commit) } end |
