diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-29 15:09:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-29 15:09:08 +0300 |
commit | 7cc6872401eb487ed20dbb9d455f8bb9c97d9e39 (patch) | |
tree | 63f6ed5d4e6c5cec31c43363626d9f5b178eddf8 /spec/graphql | |
parent | 46b10c0fc884400941c17e2777b242ac54d111e5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql')
4 files changed, 212 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 diff --git a/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb new file mode 100644 index 00000000000..1e6b7f89c08 --- /dev/null +++ b/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['SentryErrorCollection'] do + it { expect(described_class.graphql_name).to eq('SentryErrorCollection') } + + it { expect(described_class).to require_graphql_authorizations(:read_sentry_issue) } + + it 'exposes the expected fields' do + expected_fields = %i[ + errors + detailed_error + external_url + ] + + is_expected.to have_graphql_fields(*expected_fields) + end + + describe 'errors field' do + subject { described_class.fields['errors'] } + + it 'returns errors' do + aggregate_failures 'testing the correct types are returned' do + is_expected.to have_graphql_type(Types::ErrorTracking::SentryErrorType.connection_type) + is_expected.to have_graphql_extension(Gitlab::Graphql::Extensions::ExternallyPaginatedArrayExtension) + is_expected.to have_graphql_resolver(Resolvers::ErrorTracking::SentryErrorsResolver) + end + end + end +end diff --git a/spec/graphql/types/error_tracking/sentry_error_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_type_spec.rb new file mode 100644 index 00000000000..51acd035024 --- /dev/null +++ b/spec/graphql/types/error_tracking/sentry_error_type_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['SentryError'] do + it { expect(described_class.graphql_name).to eq('SentryError') } + + it 'exposes the expected fields' do + expected_fields = %i[ + id + sentryId + title + type + userCount + count + firstSeen + lastSeen + message + culprit + externalUrl + sentryProjectId + sentryProjectName + sentryProjectSlug + shortId + status + frequency + ] + + is_expected.to have_graphql_fields(*expected_fields) + end +end |