summaryrefslogtreecommitdiff
path: root/spec/graphql
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-21 14:21:10 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-21 14:21:10 +0000
commitcb0d23c455b73486fd1015f8ca9479b5b7e3585d (patch)
treed7dc129a407fd74266d2dc561bebf24665197c2f /spec/graphql
parentc3e911be175c0aabfea1eb030f9e0ef23f5f3887 (diff)
downloadgitlab-ce-cb0d23c455b73486fd1015f8ca9479b5b7e3585d.tar.gz
Add latest changes from gitlab-org/gitlab@12-7-stable-ee
Diffstat (limited to 'spec/graphql')
-rw-r--r--spec/graphql/gitlab_schema_spec.rb16
-rw-r--r--spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb29
-rw-r--r--spec/graphql/types/environment_type_spec.rb17
-rw-r--r--spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb2
-rw-r--r--spec/graphql/types/grafana_integration_type_spec.rb22
-rw-r--r--spec/graphql/types/group_type_spec.rb6
-rw-r--r--spec/graphql/types/project_type_spec.rb45
-rw-r--r--spec/graphql/types/query_type_spec.rb11
8 files changed, 125 insertions, 23 deletions
diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb
index dcf3c989047..2ec477fc494 100644
--- a/spec/graphql/gitlab_schema_spec.rb
+++ b/spec/graphql/gitlab_schema_spec.rb
@@ -124,14 +124,26 @@ describe GitlabSchema do
describe '.object_from_id' do
context 'for subclasses of `ApplicationRecord`' do
- it 'returns the correct record' do
- user = create(:user)
+ let_it_be(:user) { create(:user) }
+ it 'returns the correct record' do
result = described_class.object_from_id(user.to_global_id.to_s)
expect(result.sync).to eq(user)
end
+ it 'returns the correct record, of the expected type' do
+ result = described_class.object_from_id(user.to_global_id.to_s, expected_type: ::User)
+
+ expect(result.sync).to eq(user)
+ end
+
+ it 'fails if the type does not match' do
+ expect do
+ described_class.object_from_id(user.to_global_id.to_s, expected_type: ::Project)
+ end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
+ end
+
it 'batchloads the queries' do
user1 = create(:user)
user2 = create(:user)
diff --git a/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb b/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb
new file mode 100644
index 00000000000..416a90a841f
--- /dev/null
+++ b/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Resolvers::Projects::GrafanaIntegrationResolver do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project) }
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:grafana_integration) { create(:grafana_integration, project: project)}
+
+ describe '#resolve' do
+ context 'when object is not a project' do
+ it { expect(resolve_integration(obj: current_user)).to eq nil }
+ end
+
+ context 'when object is a project' do
+ it { expect(resolve_integration(obj: project)).to eq grafana_integration }
+ end
+
+ context 'when object is nil' do
+ it { expect(resolve_integration(obj: nil)).to eq nil}
+ end
+ end
+
+ def resolve_integration(obj: project, context: { current_user: current_user })
+ resolve(described_class, obj: obj, ctx: context)
+ end
+end
diff --git a/spec/graphql/types/environment_type_spec.rb b/spec/graphql/types/environment_type_spec.rb
new file mode 100644
index 00000000000..cf30893b3ca
--- /dev/null
+++ b/spec/graphql/types/environment_type_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe GitlabSchema.types['Environment'] do
+ it { expect(described_class.graphql_name).to eq('Environment') }
+
+ it 'has the expected fields' do
+ expected_fields = %w[
+ name id
+ ]
+
+ is_expected.to have_graphql_fields(*expected_fields)
+ end
+
+ it { is_expected.to require_graphql_authorizations(:read_environment) }
+end
diff --git a/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb b/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb
index 3576adb5272..30cede6f4cf 100644
--- a/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb
+++ b/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb
@@ -30,6 +30,8 @@ describe GitlabSchema.types['SentryDetailedError'] do
lastReleaseLastCommit
firstReleaseShortVersion
lastReleaseShortVersion
+ gitlabCommit
+ gitlabCommitPath
]
is_expected.to have_graphql_fields(*expected_fields)
diff --git a/spec/graphql/types/grafana_integration_type_spec.rb b/spec/graphql/types/grafana_integration_type_spec.rb
new file mode 100644
index 00000000000..ddfedc5a75c
--- /dev/null
+++ b/spec/graphql/types/grafana_integration_type_spec.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe GitlabSchema.types['GrafanaIntegration'] do
+ let(:expected_fields) do
+ %i[
+ id
+ grafana_url
+ token
+ enabled
+ created_at
+ updated_at
+ ]
+ end
+
+ it { expect(described_class.graphql_name).to eq('GrafanaIntegration') }
+
+ it { expect(described_class).to require_graphql_authorizations(:admin_operations) }
+
+ it { is_expected.to have_graphql_fields(*expected_fields) }
+end
diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb
index 3dd5b602aa2..de11bad0723 100644
--- a/spec/graphql/types/group_type_spec.rb
+++ b/spec/graphql/types/group_type_spec.rb
@@ -8,4 +8,10 @@ describe GitlabSchema.types['Group'] do
it { expect(described_class.graphql_name).to eq('Group') }
it { expect(described_class).to require_graphql_authorizations(:read_group) }
+
+ it 'has the expected fields' do
+ expected_fields = %w[web_url avatar_url mentions_disabled parent]
+
+ is_expected.to include_graphql_fields(*expected_fields)
+ end
end
diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb
index a3c51f24307..ac2d2d6f7f0 100644
--- a/spec/graphql/types/project_type_spec.rb
+++ b/spec/graphql/types/project_type_spec.rb
@@ -23,6 +23,7 @@ describe GitlabSchema.types['Project'] do
only_allow_merge_if_all_discussions_are_resolved printing_merge_request_link_enabled
namespace group statistics repository merge_requests merge_request issues
issue pipelines removeSourceBranchAfterMerge sentryDetailedError snippets
+ grafanaIntegration autocloseReferencedIssues suggestion_commit_message environments
]
is_expected.to include_graphql_fields(*expected_fields)
@@ -31,45 +32,49 @@ describe GitlabSchema.types['Project'] do
describe 'issue field' do
subject { described_class.fields['issue'] }
- it 'returns issue' do
- is_expected.to have_graphql_type(Types::IssueType)
- is_expected.to have_graphql_resolver(Resolvers::IssuesResolver.single)
- end
+ it { is_expected.to have_graphql_type(Types::IssueType) }
+ it { is_expected.to have_graphql_resolver(Resolvers::IssuesResolver.single) }
end
describe 'issues field' do
subject { described_class.fields['issues'] }
- it 'returns issue' do
- is_expected.to have_graphql_type(Types::IssueType.connection_type)
- is_expected.to have_graphql_resolver(Resolvers::IssuesResolver)
- end
+ it { is_expected.to have_graphql_type(Types::IssueType.connection_type) }
+ it { is_expected.to have_graphql_resolver(Resolvers::IssuesResolver) }
end
describe 'merge_requests field' do
subject { described_class.fields['mergeRequest'] }
- it 'returns merge requests' do
- is_expected.to have_graphql_type(Types::MergeRequestType)
- is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver.single)
- end
+ it { is_expected.to have_graphql_type(Types::MergeRequestType) }
+ it { is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver.single) }
end
describe 'merge_request field' do
subject { described_class.fields['mergeRequests'] }
- it 'returns merge request' do
- is_expected.to have_graphql_type(Types::MergeRequestType.connection_type)
- is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver)
- end
+ it { is_expected.to have_graphql_type(Types::MergeRequestType.connection_type) }
+ it { is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver) }
end
describe 'snippets field' do
subject { described_class.fields['snippets'] }
- it 'returns snippets' do
- is_expected.to have_graphql_type(Types::SnippetType.connection_type)
- is_expected.to have_graphql_resolver(Resolvers::Projects::SnippetsResolver)
- end
+ it { is_expected.to have_graphql_type(Types::SnippetType.connection_type) }
+ it { is_expected.to have_graphql_resolver(Resolvers::Projects::SnippetsResolver) }
+ end
+
+ describe 'grafana_integration field' do
+ subject { described_class.fields['grafanaIntegration'] }
+
+ it { is_expected.to have_graphql_type(Types::GrafanaIntegrationType) }
+ it { is_expected.to have_graphql_resolver(Resolvers::Projects::GrafanaIntegrationResolver) }
+ end
+
+ describe 'environments field' do
+ subject { described_class.fields['environments'] }
+
+ it { is_expected.to have_graphql_type(Types::EnvironmentType.connection_type) }
+ it { is_expected.to have_graphql_resolver(Resolvers::EnvironmentsResolver) }
end
end
diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb
index b2d0ba27d4e..39a363cb913 100644
--- a/spec/graphql/types/query_type_spec.rb
+++ b/spec/graphql/types/query_type_spec.rb
@@ -7,7 +7,16 @@ describe GitlabSchema.types['Query'] do
expect(described_class.graphql_name).to eq('Query')
end
- it { is_expected.to have_graphql_fields(:project, :namespace, :group, :echo, :metadata, :current_user, :snippets) }
+ it do
+ is_expected.to have_graphql_fields(:project,
+ :namespace,
+ :group,
+ :echo,
+ :metadata,
+ :current_user,
+ :snippets
+ ).at_least
+ end
describe 'namespace field' do
subject { described_class.fields['namespace'] }