diff options
Diffstat (limited to 'spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb')
-rw-r--r-- | spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb | 46 |
1 files changed, 22 insertions, 24 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..32c53ba2302 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,11 +49,16 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do end end - context 'if id does not match issue' do - it_behaves_like 'it resolves to nil' + context 'when id does not match issue' do + let(:service_response) { { issue: nil } } + + it 'resolves to nil' do + result = resolve_error(args) + expect(result).to be_nil + end end - context 'blank id' do + context 'with blank id' do let(:args) { { id: '' } } it 'responds with an error' do @@ -71,6 +67,8 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do end end + private + def resolve_error(args = {}, context = { current_user: current_user }) resolve(described_class, obj: project, args: args, ctx: context) end |