summaryrefslogtreecommitdiff
path: root/spec/services/error_tracking/issue_details_service_spec.rb
blob: 7ac41ffead658cb6a80b3fe5f4876c2e12cbaabe (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ErrorTracking::IssueDetailsService, feature_category: :error_tracking do
  include_context 'sentry error tracking context'

  subject { described_class.new(project, user, params) }

  describe '#execute' do
    context 'with authorized user' do
      context 'when issue_details returns a detailed error' do
        let(:detailed_error) { build(:error_tracking_sentry_detailed_error) }
        let(:params) { { issue_id: detailed_error.id } }

        before do
          allow(error_tracking_setting)
            .to receive(:issue_details).and_return(issue: detailed_error)
        end

        it 'returns the detailed error' do
          expect(result).to eq(status: :success, issue: detailed_error)
        end

        it 'returns the gitlab_issue when the error has a sentry_issue' do
          gitlab_issue = create(:issue, project: project)
          create(:sentry_issue, issue: gitlab_issue, sentry_issue_identifier: detailed_error.id)

          expect(result[:issue].gitlab_issue).to include(
            "http", "/#{project.full_path}/-/issues/#{gitlab_issue.iid}"
          )
        end

        it 'returns the gitlab_issue path from sentry when the error has no sentry_issue' do
          expect(result[:issue].gitlab_issue).to eq(detailed_error.gitlab_issue)
        end
      end

      include_examples 'error tracking service data not ready', :issue_details
      include_examples 'error tracking service sentry error handling', :issue_details
      include_examples 'error tracking service http status handling', :issue_details

      context 'with integrated error tracking' do
        let_it_be(:error) { create(:error_tracking_error, project: project) }

        let(:params) { { issue_id: error.id } }

        before do
          error_tracking_setting.update!(integrated: true)
        end

        it 'returns the error in detailed format' do
          expect(result[:status]).to eq(:success)
          expect(result[:issue].to_json).to eq(error.to_sentry_detailed_error.to_json)
        end

        context 'when error does not exist' do
          let(:params) { { issue_id: non_existing_record_id } }

          it 'returns the error in detailed format' do
            expect(result).to match(
              status: :error,
              message: /Couldn't find ErrorTracking::Error/,
              http_status: :bad_request
            )
          end
        end
      end
    end

    include_examples 'error tracking service unauthorized user'
    include_examples 'error tracking service disabled'
  end
end