diff options
author | Phil Hughes <me@iamphill.com> | 2019-05-22 14:43:35 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-05-22 14:43:35 +0300 |
commit | 67a50861953be9347e267795a9ce736dfea5316b (patch) | |
tree | b9546274a629204b8c2ae9a60c5da70ae3a06ba7 /spec/requests | |
parent | c841c8771b8d69034c1ceb6e452746d193865cb0 (diff) |
Added repository files to GraphQL API
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/graphql/project/repository_spec.rb | 37 | ||||
-rw-r--r-- | spec/requests/api/graphql/project/tree/tree_spec.rb | 73 |
2 files changed, 110 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/project/repository_spec.rb b/spec/requests/api/graphql/project/repository_spec.rb new file mode 100644 index 00000000000..67af612a4a0 --- /dev/null +++ b/spec/requests/api/graphql/project/repository_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe 'getting a repository in a project' do + include GraphqlHelpers + + let(:project) { create(:project, :repository) } + let(:current_user) { project.owner } + let(:fields) do + <<~QUERY + #{all_graphql_fields_for('repository'.classify)} + QUERY + end + let(:query) do + graphql_query_for( + 'project', + { 'fullPath' => project.full_path }, + query_graphql_field('repository', {}, fields) + ) + end + + it 'returns repository' do + post_graphql(query, current_user: current_user) + + expect(graphql_data['project']['repository']).to be_present + end + + context 'as a non-authorized user' do + let(:current_user) { create(:user) } + + it 'returns nil' do + post_graphql(query, current_user: current_user) + + expect(graphql_data['project']).to be(nil) + end + end +end diff --git a/spec/requests/api/graphql/project/tree/tree_spec.rb b/spec/requests/api/graphql/project/tree/tree_spec.rb new file mode 100644 index 00000000000..b07aa1e12d3 --- /dev/null +++ b/spec/requests/api/graphql/project/tree/tree_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe 'getting a tree in a project' do + include GraphqlHelpers + + let(:project) { create(:project, :repository) } + let(:current_user) { project.owner } + let(:path) { "" } + let(:ref) { "master" } + let(:fields) do + <<~QUERY + tree(path:"#{path}", ref:"#{ref}") { + #{all_graphql_fields_for('tree'.classify)} + } + QUERY + end + let(:query) do + graphql_query_for( + 'project', + { 'fullPath' => project.full_path }, + query_graphql_field('repository', {}, fields) + ) + end + + context 'when path does not exist' do + let(:path) { "testing123" } + + it 'returns empty tree' do + post_graphql(query, current_user: current_user) + + expect(graphql_data['project']['repository']['tree']['trees']['edges']).to eq([]) + expect(graphql_data['project']['repository']['tree']['submodules']['edges']).to eq([]) + expect(graphql_data['project']['repository']['tree']['blobs']['edges']).to eq([]) + end + end + + context 'when ref does not exist' do + let(:ref) { "testing123" } + + it 'returns empty tree' do + post_graphql(query, current_user: current_user) + + expect(graphql_data['project']['repository']['tree']['trees']['edges']).to eq([]) + expect(graphql_data['project']['repository']['tree']['submodules']['edges']).to eq([]) + expect(graphql_data['project']['repository']['tree']['blobs']['edges']).to eq([]) + end + end + + context 'when ref and path exist' do + it 'returns tree' do + post_graphql(query, current_user: current_user) + + expect(graphql_data['project']['repository']['tree']).to be_present + end + + it 'returns blobs, subtrees and submodules inside tree' do + post_graphql(query, current_user: current_user) + + expect(graphql_data['project']['repository']['tree']['trees']['edges'].size).to be > 0 + expect(graphql_data['project']['repository']['tree']['blobs']['edges'].size).to be > 0 + expect(graphql_data['project']['repository']['tree']['submodules']['edges'].size).to be > 0 + end + end + + context 'when current user is nil' do + it 'returns empty project' do + post_graphql(query, current_user: nil) + + expect(graphql_data['project']).to be(nil) + end + end +end |