summaryrefslogtreecommitdiff
path: root/spec/helpers/projects/error_tracking_helper_spec.rb
blob: 325ff32dd89afae15d6dcd7259d62f780d63702c (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
# frozen_string_literal: true

require 'spec_helper'

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

  set(:project) { create(:project) }
  set(:current_user) { create(: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')
        )
      end
    end

    context 'with error_tracking_setting' do
      let(:error_tracking_setting) do
        create(:project_error_tracking_setting, project: project)
      end

      context 'when enabled' do
        before do
          error_tracking_setting.update!(enabled: true)
        end

        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
        before do
          error_tracking_setting.update!(enabled: false)
        end

        it 'show error tracking not enabled' do
          expect(helper.error_tracking_data(current_user, project)).to include(
            'error-tracking-enabled' => 'false'
          )
        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(:list_path) { project_error_tracking_index_path(project) }
    let(:details_path) { details_namespace_project_error_tracking_index_path(*route_params) }
    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 list path' do
      expect(result['list-path']).to eq list_path
    end

    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 details path' do
      expect(result['issue-details-path']).to eq details_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