summaryrefslogtreecommitdiff
path: root/spec/helpers/projects/error_tracking_helper_spec.rb
blob: f49458be40d342aadbcb896d35173b678a688256 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::ErrorTrackingHelper do
  include Gitlab::Routing.url_helpers

  let(:project) { build_stubbed(:project) }
  let(:current_user) { build_stubbed(:user) }

  describe '#error_tracking_data' do
    let(:can_enable_error_tracking) { true }
    let(:setting_path) { project_settings_operations_path(project) }
    let(:list_path) { project_error_tracking_index_path(project) }
    let(:project_path) { project.full_path }

    let(:index_path) do
      project_error_tracking_index_path(project, format: :json)
    end

    before do
      allow(helper)
        .to receive(:can?)
        .with(current_user, :admin_operations, project)
        .and_return(can_enable_error_tracking)
    end

    context 'without error_tracking_setting' do
      it 'returns frontend configuration' do
        expect(helper.error_tracking_data(current_user, project)).to match(
          'index-path' => index_path,
          'user-can-enable-error-tracking' => 'true',
          'enable-error-tracking-link' => setting_path,
          'error-tracking-enabled' => 'false',
          'list-path' => list_path,
          'project-path' => project_path,
          'illustration-path' => match_asset_path('/assets/illustrations/cluster_popover.svg'),
          'show-integrated-tracking-disabled-alert' => 'false'
        )
      end
    end

    context 'with error_tracking_setting' do
      let(:project) { build_stubbed(:project, :with_error_tracking_setting) }

      before do
        project.error_tracking_setting.enabled = enabled
      end

      context 'when enabled' do
        let(:enabled) { true }

        it 'show error tracking enabled' do
          expect(helper.error_tracking_data(current_user, project)).to include(
            'error-tracking-enabled' => 'true'
          )
        end
      end

      context 'when disabled' do
        let(:enabled) { false }

        it 'show error tracking not enabled' do
          expect(helper.error_tracking_data(current_user, project)).to include(
            'error-tracking-enabled' => 'false'
          )
        end
      end

      context 'with integrated error tracking feature' do
        using RSpec::Parameterized::TableSyntax

        where(:feature_flag, :enabled, :integrated, :show_alert) do
          false | true  | true  | true
          false | true  | false | false
          false | false | true  | false
          false | false | false | false
          true  | true  | true  | false
          true  | true  | false | false
          true  | false | true  | false
          true  | false | false | false
        end

        with_them do
          before do
            stub_feature_flags(integrated_error_tracking: feature_flag)

            project.error_tracking_setting.attributes = {
              enabled: enabled,
              integrated: integrated
            }
          end

          specify do
            expect(helper.error_tracking_data(current_user, project)).to include(
              'show-integrated-tracking-disabled-alert' => show_alert.to_s
            )
          end
        end
      end
    end

    context 'when user is not maintainer' do
      let(:can_enable_error_tracking) { false }

      it 'shows error tracking enablement as disabled' do
        expect(helper.error_tracking_data(current_user, project)).to include(
          'user-can-enable-error-tracking' => 'false'
        )
      end
    end
  end

  describe '#error_details_data' do
    let(:issue_id) { 1234 }
    let(:route_params) { [project.owner, project, issue_id, { format: :json }] }
    let(:project_path) { project.full_path }
    let(:stack_trace_path) { stack_trace_namespace_project_error_tracking_index_path(*route_params) }
    let(:issues_path) { project_issues_path(project) }

    let(:result) { helper.error_details_data(project, issue_id) }

    it 'returns the correct issue id' do
      expect(result['issue-id']).to eq issue_id
    end

    it 'returns the correct project path' do
      expect(result['project-path']).to eq project_path
    end

    it 'returns the correct stack trace path' do
      expect(result['issue-stack-trace-path']).to eq stack_trace_path
    end

    it 'creates an issue and redirects to issue show page' do
      expect(result['project-issues-path']).to eq issues_path
    end
  end
end