diff options
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/gitlab_schema_spec.rb | 4 | ||||
-rw-r--r-- | spec/graphql/resolvers/group_resolver_spec.rb | 32 | ||||
-rw-r--r-- | spec/graphql/resolvers/tree_resolver_spec.rb | 35 | ||||
-rw-r--r-- | spec/graphql/types/project_type_spec.rb | 2 | ||||
-rw-r--r-- | spec/graphql/types/repository_type_spec.rb | 11 | ||||
-rw-r--r-- | spec/graphql/types/tree/blob_type_spec.rb | 9 | ||||
-rw-r--r-- | spec/graphql/types/tree/submodule_type_spec.rb | 9 | ||||
-rw-r--r-- | spec/graphql/types/tree/tree_entry_type_spec.rb | 9 | ||||
-rw-r--r-- | spec/graphql/types/tree/tree_type_spec.rb | 9 | ||||
-rw-r--r-- | spec/graphql/types/tree/type_enum_spec.rb | 11 |
10 files changed, 129 insertions, 2 deletions
diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb index c138c87c4ac..e9149f4250f 100644 --- a/spec/graphql/gitlab_schema_spec.rb +++ b/spec/graphql/gitlab_schema_spec.rb @@ -56,10 +56,10 @@ describe GitlabSchema do described_class.execute('query', context: {}) end - it 'returns ANONYMOUS_MAX_DEPTH' do + it 'returns DEFAULT_MAX_DEPTH' do expect(GraphQL::Schema) .to receive(:execute) - .with('query', hash_including(max_depth: GitlabSchema::ANONYMOUS_MAX_DEPTH)) + .with('query', hash_including(max_depth: GitlabSchema::DEFAULT_MAX_DEPTH)) described_class.execute('query', context: {}) end diff --git a/spec/graphql/resolvers/group_resolver_spec.rb b/spec/graphql/resolvers/group_resolver_spec.rb new file mode 100644 index 00000000000..5eb9cd06d15 --- /dev/null +++ b/spec/graphql/resolvers/group_resolver_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Resolvers::GroupResolver do + include GraphqlHelpers + + set(:group1) { create(:group) } + set(:group2) { create(:group) } + + describe '#resolve' do + it 'batch-resolves groups by full path' do + paths = [group1.full_path, group2.full_path] + + result = batch(max_queries: 1) do + paths.map { |path| resolve_group(path) } + end + + expect(result).to contain_exactly(group1, group2) + end + + it 'resolves an unknown full_path to nil' do + result = batch { resolve_group('unknown/project') } + + expect(result).to be_nil + end + end + + def resolve_group(full_path) + resolve(described_class, args: { full_path: full_path }) + end +end diff --git a/spec/graphql/resolvers/tree_resolver_spec.rb b/spec/graphql/resolvers/tree_resolver_spec.rb new file mode 100644 index 00000000000..9f95b740ab1 --- /dev/null +++ b/spec/graphql/resolvers/tree_resolver_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe Resolvers::TreeResolver do + include GraphqlHelpers + + let(:repository) { create(:project, :repository).repository } + + describe '#resolve' do + it 'resolves to a tree' do + result = resolve_repository({ ref: "master" }) + + expect(result).to be_an_instance_of(Tree) + end + + it 'resolve to a recursive tree' do + result = resolve_repository({ ref: "master", recursive: true }) + + expect(result.trees[4].path).to eq('files/html') + end + + context 'when repository does not exist' do + it 'returns nil' do + allow(repository).to receive(:exists?).and_return(false) + + result = resolve_repository({ ref: "master" }) + + expect(result).to be(nil) + end + end + end + + def resolve_repository(args) + resolve(described_class, obj: repository, args: args) + end +end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index e0ad09bdf22..075fa7c7e43 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -17,4 +17,6 @@ describe GitlabSchema.types['Project'] do end it { is_expected.to have_graphql_field(:pipelines) } + + it { is_expected.to have_graphql_field(:repository) } end diff --git a/spec/graphql/types/repository_type_spec.rb b/spec/graphql/types/repository_type_spec.rb new file mode 100644 index 00000000000..8a8238f2a2a --- /dev/null +++ b/spec/graphql/types/repository_type_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe GitlabSchema.types['Repository'] do + it { expect(described_class.graphql_name).to eq('Repository') } + + it { expect(described_class).to require_graphql_authorizations(:download_code) } + + it { is_expected.to have_graphql_field(:root_ref) } + + it { is_expected.to have_graphql_field(:tree) } +end diff --git a/spec/graphql/types/tree/blob_type_spec.rb b/spec/graphql/types/tree/blob_type_spec.rb new file mode 100644 index 00000000000..fa29bb5fff7 --- /dev/null +++ b/spec/graphql/types/tree/blob_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Types::Tree::BlobType do + it { expect(described_class.graphql_name).to eq('Blob') } + + it { expect(described_class).to have_graphql_fields(:id, :name, :type, :path, :flat_path) } +end diff --git a/spec/graphql/types/tree/submodule_type_spec.rb b/spec/graphql/types/tree/submodule_type_spec.rb new file mode 100644 index 00000000000..bdb3149b41c --- /dev/null +++ b/spec/graphql/types/tree/submodule_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +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) } +end diff --git a/spec/graphql/types/tree/tree_entry_type_spec.rb b/spec/graphql/types/tree/tree_entry_type_spec.rb new file mode 100644 index 00000000000..397cabde8e5 --- /dev/null +++ b/spec/graphql/types/tree/tree_entry_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Types::Tree::TreeEntryType do + it { expect(described_class.graphql_name).to eq('TreeEntry') } + + it { expect(described_class).to have_graphql_fields(:id, :name, :type, :path, :flat_path) } +end diff --git a/spec/graphql/types/tree/tree_type_spec.rb b/spec/graphql/types/tree/tree_type_spec.rb new file mode 100644 index 00000000000..b9c5570115e --- /dev/null +++ b/spec/graphql/types/tree/tree_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +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) } +end diff --git a/spec/graphql/types/tree/type_enum_spec.rb b/spec/graphql/types/tree/type_enum_spec.rb new file mode 100644 index 00000000000..4caf9e1c457 --- /dev/null +++ b/spec/graphql/types/tree/type_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Types::Tree::TypeEnum do + it { expect(described_class.graphql_name).to eq('EntryType') } + + it 'exposes all tree entry types' do + expect(described_class.values.keys).to include(*%w[tree blob commit]) + end +end |