Commit 8f807824 authored by Sean Arnold's avatar Sean Arnold Committed by Rémy Coutable

Add safe navigation when parsing issue_id

- Extend sentry detailed error spec
parent 2741e514
......@@ -9,7 +9,7 @@ module Resolvers
def resolve(**args)
current_user = context[:current_user]
issue_id = GlobalID.parse(args[:id]).model_id
issue_id = GlobalID.parse(args[:id])&.model_id
# Get data from Sentry
response = ::ErrorTracking::IssueDetailsService.new(
......
......@@ -8,7 +8,7 @@ module Resolvers
description: 'ID of the Sentry issue'
def resolve(**args)
issue_id = GlobalID.parse(args[:id]).model_id
issue_id = GlobalID.parse(args[:id])&.model_id
# Get data from Sentry
response = ::ErrorTracking::IssueLatestEventService.new(
......
......@@ -18,6 +18,16 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
.and_return issue_details_service
end
shared_examples 'it resolves to nil' do
it 'resolves to nil' do
allow(issue_details_service).to receive(:execute)
.and_return(issue: nil)
result = resolve_error(args)
expect(result).to be_nil
end
end
describe '#resolve' do
let(:args) { { id: issue_global_id(1234) } }
......@@ -32,7 +42,7 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
before do
allow(issue_details_service).to receive(:execute)
.and_return({ issue: detailed_error })
.and_return(issue: detailed_error)
end
it 'resolves to a detailed error' do
......@@ -44,12 +54,14 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
end
end
it 'resolves to nil if no match' do
allow(issue_details_service).to receive(:execute)
.and_return({ issue: nil })
context 'if id does not match issue' do
it_behaves_like 'it resolves to nil'
end
result = resolve_error(args)
expect(result).to eq nil
context 'blank id' do
let(:args) { { id: '' } }
it_behaves_like 'it resolves to nil'
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment