summaryrefslogtreecommitdiff
path: root/spec/graphql/resolvers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-29 12:09:08 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-29 12:09:08 +0000
commit7cc6872401eb487ed20dbb9d455f8bb9c97d9e39 (patch)
tree63f6ed5d4e6c5cec31c43363626d9f5b178eddf8 /spec/graphql/resolvers
parent46b10c0fc884400941c17e2777b242ac54d111e5 (diff)
downloadgitlab-ce-7cc6872401eb487ed20dbb9d455f8bb9c97d9e39.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql/resolvers')
-rw-r--r--spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb47
-rw-r--r--spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb103
2 files changed, 150 insertions, 0 deletions
diff --git a/spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb b/spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb
new file mode 100644
index 00000000000..3bb8a5c389d
--- /dev/null
+++ b/spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Resolvers::ErrorTracking::SentryErrorCollectionResolver do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project) }
+ let_it_be(:current_user) { create(:user) }
+
+ let(:list_issues_service) { spy('ErrorTracking::ListIssuesService') }
+
+ before do
+ project.add_developer(current_user)
+
+ allow(ErrorTracking::ListIssuesService)
+ .to receive(:new)
+ .and_return list_issues_service
+ end
+
+ describe '#resolve' do
+ it 'returns an error collection object' do
+ expect(resolve_error_collection).to be_a Gitlab::ErrorTracking::ErrorCollection
+ end
+
+ it 'provides the service url' do
+ fake_url = 'http://test.com'
+
+ expect(list_issues_service)
+ .to receive(:external_url)
+ .and_return(fake_url)
+
+ result = resolve_error_collection
+ expect(result.external_url).to eq fake_url
+ end
+
+ it 'provides the project' do
+ expect(resolve_error_collection.project).to eq project
+ end
+ end
+
+ private
+
+ def resolve_error_collection(context = { current_user: current_user })
+ resolve(described_class, obj: project, args: {}, ctx: context)
+ end
+end
diff --git a/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb b/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb
new file mode 100644
index 00000000000..93f89d077d7
--- /dev/null
+++ b/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb
@@ -0,0 +1,103 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Resolvers::ErrorTracking::SentryErrorsResolver do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project) }
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:error_collection) { Gitlab::ErrorTracking::ErrorCollection.new(project: project) }
+
+ let(:list_issues_service) { spy('ErrorTracking::ListIssuesService') }
+
+ let(:issues) { nil }
+ let(:pagination) { nil }
+
+ describe '#resolve' do
+ context 'insufficient user permission' do
+ let(:user) { create(:user) }
+
+ it 'returns nil' do
+ context = { current_user: user }
+
+ expect(resolve_errors({}, context)).to eq nil
+ end
+ end
+
+ context 'user with permission' do
+ before do
+ project.add_developer(current_user)
+
+ allow(ErrorTracking::ListIssuesService)
+ .to receive(:new)
+ .and_return list_issues_service
+ end
+
+ context 'when after arg given' do
+ let(:after) { "1576029072000:0:0" }
+
+ it 'gives the cursor arg' do
+ expect(ErrorTracking::ListIssuesService)
+ .to receive(:new)
+ .with(project, current_user, { cursor: after })
+ .and_return list_issues_service
+
+ resolve_errors({ after: after })
+ end
+ end
+
+ context 'when no issues fetched' do
+ before do
+ allow(list_issues_service)
+ .to receive(:execute)
+ .and_return(
+ issues: nil
+ )
+ end
+ it 'returns nil' do
+ expect(resolve_errors).to eq nil
+ end
+ end
+
+ context 'when issues returned' do
+ let(:issues) { [:issue_1, :issue_2] }
+ let(:pagination) do
+ {
+ 'next' => { 'cursor' => 'next' },
+ 'previous' => { 'cursor' => 'prev' }
+ }
+ end
+
+ before do
+ allow(list_issues_service)
+ .to receive(:execute)
+ .and_return(
+ issues: issues,
+ pagination: pagination
+ )
+ end
+
+ it 'sets the issues' do
+ expect(resolve_errors).to contain_exactly(*issues)
+ end
+
+ it 'sets the pagination variables' do
+ result = resolve_errors
+ expect(result.next_cursor).to eq 'next'
+ expect(result.previous_cursor).to eq 'prev'
+ end
+
+ it 'returns an externally paginated array' do
+ expect(resolve_errors).to be_a Gitlab::Graphql::ExternallyPaginatedArray
+ end
+ end
+ end
+ end
+
+ private
+
+ def resolve_errors(args = {}, context = { current_user: current_user })
+ resolve(described_class, obj: error_collection, args: args, ctx: context)
+ end
+end