2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Projects::ErrorTrackingHelper do
|
2019-02-15 15:39:39 +05:30
|
|
|
include Gitlab::Routing.url_helpers
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project, reload: true) { create(:project) }
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
describe '#error_tracking_data' do
|
2019-12-04 20:38:33 +05:30
|
|
|
let(:can_enable_error_tracking) { true }
|
2019-02-15 15:39:39 +05:30
|
|
|
let(:setting_path) { project_settings_operations_path(project) }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:list_path) { project_error_tracking_index_path(project) }
|
|
|
|
let(:project_path) { project.full_path }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
let(:index_path) do
|
|
|
|
project_error_tracking_index_path(project, format: :json)
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
before do
|
|
|
|
allow(helper)
|
|
|
|
.to receive(:can?)
|
|
|
|
.with(current_user, :admin_operations, project)
|
|
|
|
.and_return(can_enable_error_tracking)
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
context 'without error_tracking_setting' do
|
|
|
|
it 'returns frontend configuration' do
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(helper.error_tracking_data(current_user, project)).to match(
|
2019-02-15 15:39:39 +05:30
|
|
|
'index-path' => index_path,
|
2019-12-04 20:38:33 +05:30
|
|
|
'user-can-enable-error-tracking' => 'true',
|
2019-02-15 15:39:39 +05:30
|
|
|
'enable-error-tracking-link' => setting_path,
|
|
|
|
'error-tracking-enabled' => 'false',
|
2020-03-13 15:44:24 +05:30
|
|
|
'list-path' => list_path,
|
|
|
|
'project-path' => project_path,
|
2019-12-04 20:38:33 +05:30
|
|
|
'illustration-path' => match_asset_path('/assets/illustrations/cluster_popover.svg')
|
2019-02-15 15:39:39 +05:30
|
|
|
)
|
|
|
|
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
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(helper.error_tracking_data(current_user, project)).to include(
|
2019-02-15 15:39:39 +05:30
|
|
|
'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
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(helper.error_tracking_data(current_user, project)).to include(
|
2019-02-15 15:39:39 +05:30
|
|
|
'error-tracking-enabled' => 'false'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
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
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe '#error_details_data' do
|
|
|
|
let(:issue_id) { 1234 }
|
|
|
|
let(:route_params) { [project.owner, project, issue_id, { format: :json }] }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:project_path) { project.full_path }
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:stack_trace_path) { stack_trace_namespace_project_error_tracking_index_path(*route_params) }
|
2020-01-01 13:55:28 +05:30
|
|
|
let(:issues_path) { project_issues_path(project) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
let(:result) { helper.error_details_data(project, issue_id) }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
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
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the correct stack trace path' do
|
|
|
|
expect(result['issue-stack-trace-path']).to eq stack_trace_path
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
it 'creates an issue and redirects to issue show page' do
|
|
|
|
expect(result['project-issues-path']).to eq issues_path
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|