diff options
Diffstat (limited to 'spec/graphql/resolvers/error_tracking')
3 files changed, 44 insertions, 54 deletions
diff --git a/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb b/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb index 2aef483ac95..f80b33e644e 100644 --- a/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb +++ b/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb @@ -8,28 +8,23 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do let_it_be(:project) { create(:project) } let_it_be(:current_user) { create(:user) } - let(:issue_details_service) { spy('ErrorTracking::IssueDetailsService') } + let(:issue_details_service) { instance_double('ErrorTracking::IssueDetailsService') } + let(:service_response) { {} } - specify do - expect(described_class).to have_nullable_graphql_type(Types::ErrorTracking::SentryDetailedErrorType) + before_all do + project.add_developer(current_user) end before do - project.add_developer(current_user) - allow(ErrorTracking::IssueDetailsService) .to receive(:new) - .and_return issue_details_service - end + .and_return(issue_details_service) - shared_examples 'it resolves to nil' do - it 'resolves to nil' do - allow(issue_details_service).to receive(:execute) - .and_return(issue: nil) + allow(issue_details_service).to receive(:execute).and_return(service_response) + end - result = resolve_error(args) - expect(result).to be_nil - end + specify do + expect(described_class).to have_nullable_graphql_type(Types::ErrorTracking::SentryDetailedErrorType) end describe '#resolve' do @@ -41,13 +36,9 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do expect(issue_details_service).to have_received(:execute) end - context 'error matched' do - let(:detailed_error) { build(:error_tracking_sentry_detailed_error) } - - before do - allow(issue_details_service).to receive(:execute) - .and_return(issue: detailed_error) - end + context 'when error matches' do + let(:detailed_error) { build_stubbed(:error_tracking_sentry_detailed_error) } + let(:service_response) { { issue: detailed_error } } it 'resolves to a detailed error' do expect(resolve_error(args)).to eq detailed_error @@ -58,24 +49,23 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do end end - context 'if id does not match issue' do - it_behaves_like 'it resolves to nil' - end - - context 'blank id' do - let(:args) { { id: '' } } + context 'when id does not match issue' do + let(:service_response) { { issue: nil } } - it 'responds with an error' do - expect { resolve_error(args) }.to raise_error(::GraphQL::CoercionError) + it 'resolves to nil' do + result = resolve_error(args) + expect(result).to be_nil end end end + private + def resolve_error(args = {}, context = { current_user: current_user }) resolve(described_class, obj: project, args: args, ctx: context) end def issue_global_id(issue_id) - Gitlab::ErrorTracking::DetailedError.new(id: issue_id).to_global_id.to_s + Gitlab::ErrorTracking::DetailedError.new(id: issue_id).to_global_id end end 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 index 20c2bdcd4e1..5834faea97e 100644 --- a/spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb +++ b/spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb @@ -8,18 +8,22 @@ RSpec.describe Resolvers::ErrorTracking::SentryErrorCollectionResolver do let_it_be(:project) { create(:project) } let_it_be(:current_user) { create(:user) } - let(:list_issues_service) { spy('ErrorTracking::ListIssuesService') } + let(:list_issues_service) { instance_double('ErrorTracking::ListIssuesService') } - specify do - expect(described_class).to have_nullable_graphql_type(Types::ErrorTracking::SentryErrorCollectionType) + before_all do + project.add_developer(current_user) end before do - project.add_developer(current_user) - allow(ErrorTracking::ListIssuesService) .to receive(:new) .and_return list_issues_service + + allow(list_issues_service).to receive(:external_url) + end + + specify do + expect(described_class).to have_nullable_graphql_type(Types::ErrorTracking::SentryErrorCollectionType) end describe '#resolve' do @@ -34,8 +38,7 @@ RSpec.describe Resolvers::ErrorTracking::SentryErrorCollectionResolver do .to receive(:external_url) .and_return(fake_url) - result = resolve_error_collection - expect(result.external_url).to eq fake_url + expect(resolve_error_collection.external_url).to eq fake_url end it 'provides the project' do diff --git a/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb b/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb index 68badb8e333..65b6c551dde 100644 --- a/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb +++ b/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Resolvers::ErrorTracking::SentryErrorsResolver do 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(:list_issues_service) { instance_double('ErrorTracking::ListIssuesService') } let(:issues) { nil } let(:pagination) { nil } @@ -19,23 +19,25 @@ RSpec.describe Resolvers::ErrorTracking::SentryErrorsResolver do end describe '#resolve' do + before do + allow(ErrorTracking::ListIssuesService) + .to receive(:new) + .and_return list_issues_service + + allow(list_issues_service).to receive(:execute).and_return({}) + end + context 'with insufficient user permission' do - let(:user) { create(:user) } + let(:current_user) { create(:user) } it 'returns nil' do - context = { current_user: user } - - expect(resolve_errors({}, context)).to eq nil + expect(resolve_errors).to eq nil end end context 'with sufficient permission' do - before do + before_all do project.add_developer(current_user) - - allow(ErrorTracking::ListIssuesService) - .to receive(:new) - .and_return list_issues_service end context 'when after arg given' do @@ -52,14 +54,9 @@ RSpec.describe Resolvers::ErrorTracking::SentryErrorsResolver do 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(list_issues_service).to receive(:execute).and_return(issues: nil) + expect(resolve_errors).to eq nil end end |