blob: bf8d2139c82c840ce74ab0cf1b44638589525031 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
include GraphqlHelpers
let_it_be(:project) { create(:project) }
let_it_be(:current_user) { create(:user) }
let(:issue_details_service) { spy('ErrorTracking::IssueDetailsService') }
specify do
expect(described_class).to have_nullable_graphql_type(Types::ErrorTracking::SentryDetailedErrorType)
end
before do
project.add_developer(current_user)
allow(ErrorTracking::IssueDetailsService)
.to receive(:new)
.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) } }
it 'fetches the data via the sentry API' do
resolve_error(args)
expect(issue_details_service).to have_received(:execute)
end
context 'error matched' do
let(:detailed_error) { build(:detailed_error_tracking_error) }
before do
allow(issue_details_service).to receive(:execute)
.and_return(issue: detailed_error)
end
it 'resolves to a detailed error' do
expect(resolve_error(args)).to eq detailed_error
end
it 'assigns the gitlab project' do
expect(resolve_error(args).gitlab_project).to eq project
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: '' } }
it 'responds with an error' do
expect { resolve_error(args) }.to raise_error(::GraphQL::CoercionError)
end
end
end
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
end
end
|