summaryrefslogtreecommitdiff
path: root/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb
blob: 7e531910184d4571243df371a46ddd22fefa7957 (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
# 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') }

  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_behaves_like 'it resolves to nil'
    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