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 ...@@ -9,7 +9,7 @@ module Resolvers
def resolve(**args) def resolve(**args)
current_user = context[:current_user] 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 # Get data from Sentry
response = ::ErrorTracking::IssueDetailsService.new( response = ::ErrorTracking::IssueDetailsService.new(
......
...@@ -8,7 +8,7 @@ module Resolvers ...@@ -8,7 +8,7 @@ module Resolvers
description: 'ID of the Sentry issue' description: 'ID of the Sentry issue'
def resolve(**args) def resolve(**args)
issue_id = GlobalID.parse(args[:id]).model_id issue_id = GlobalID.parse(args[:id])&.model_id
# Get data from Sentry # Get data from Sentry
response = ::ErrorTracking::IssueLatestEventService.new( response = ::ErrorTracking::IssueLatestEventService.new(
......
...@@ -18,6 +18,16 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do ...@@ -18,6 +18,16 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
.and_return issue_details_service .and_return issue_details_service
end 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 describe '#resolve' do
let(:args) { { id: issue_global_id(1234) } } let(:args) { { id: issue_global_id(1234) } }
...@@ -32,7 +42,7 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do ...@@ -32,7 +42,7 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
before do before do
allow(issue_details_service).to receive(:execute) allow(issue_details_service).to receive(:execute)
.and_return({ issue: detailed_error }) .and_return(issue: detailed_error)
end end
it 'resolves to a detailed error' do it 'resolves to a detailed error' do
...@@ -44,12 +54,14 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do ...@@ -44,12 +54,14 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
end end
end end
it 'resolves to nil if no match' do context 'if id does not match issue' do
allow(issue_details_service).to receive(:execute) it_behaves_like 'it resolves to nil'
.and_return({ issue: nil }) end
result = resolve_error(args) context 'blank id' do
expect(result).to eq nil let(:args) { { id: '' } }
it_behaves_like 'it resolves to nil'
end end
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