Commit 14af275d authored by James Fargher's avatar James Fargher

Merge branch 'dz-error-tracking-refactor-factories' into 'master'

Refactor error tracking factories

See merge request gitlab-org/gitlab!67446
parents 4cd0c1c2 71bea2de
...@@ -40,7 +40,7 @@ RSpec.describe Projects::ErrorTracking::StackTracesController do ...@@ -40,7 +40,7 @@ RSpec.describe Projects::ErrorTracking::StackTracesController do
context 'service result is successful' do context 'service result is successful' do
let(:service_response) { { status: :success, latest_event: error_event } } let(:service_response) { { status: :success, latest_event: error_event } }
let(:error_event) { build(:error_tracking_error_event) } let(:error_event) { build(:error_tracking_sentry_error_event) }
it 'responds with success' do it 'responds with success' do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
......
...@@ -95,7 +95,7 @@ RSpec.describe Projects::ErrorTrackingController do ...@@ -95,7 +95,7 @@ RSpec.describe Projects::ErrorTrackingController do
get :index, params: params get :index, params: params
end end
let(:error) { build(:error_tracking_error) } let(:error) { build(:error_tracking_sentry_error) }
it 'returns a list of errors' do it 'returns a list of errors' do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
...@@ -126,7 +126,7 @@ RSpec.describe Projects::ErrorTrackingController do ...@@ -126,7 +126,7 @@ RSpec.describe Projects::ErrorTrackingController do
.and_return(external_url) .and_return(external_url)
end end
let(:error) { build(:error_tracking_error) } let(:error) { build(:error_tracking_sentry_error) }
it 'returns a list of errors' do it 'returns a list of errors' do
get :index, params: project_params(format: :json) get :index, params: project_params(format: :json)
...@@ -221,7 +221,7 @@ RSpec.describe Projects::ErrorTrackingController do ...@@ -221,7 +221,7 @@ RSpec.describe Projects::ErrorTrackingController do
get :details, params: issue_params(issue_id: issue_id, format: :json) get :details, params: issue_params(issue_id: issue_id, format: :json)
end end
let(:error) { build(:detailed_error_tracking_error) } let(:error) { build(:error_tracking_sentry_detailed_error) }
it 'returns an error' do it 'returns an error' do
expected_error = error.as_json.except('first_release_version').merge( expected_error = error.as_json.except('first_release_version').merge(
......
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
factory :detailed_error_tracking_error, parent: :error_tracking_error, class: 'Gitlab::ErrorTracking::DetailedError' do factory :error_tracking_sentry_detailed_error, parent: :error_tracking_sentry_error, class: 'Gitlab::ErrorTracking::DetailedError' do
gitlab_issue { 'http://gitlab.example.com/issues/1' } gitlab_issue { 'http://gitlab.example.com/issues/1' }
external_base_url { 'http://example.com' } external_base_url { 'http://example.com' }
first_release_last_commit { '68c914da9' } first_release_last_commit { '68c914da9' }
......
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
factory :error_tracking_error, class: 'Gitlab::ErrorTracking::Error' do # There is an issue to rename this class https://gitlab.com/gitlab-org/gitlab/-/issues/323342.
factory :error_tracking_sentry_error, class: 'Gitlab::ErrorTracking::Error' do
id { '1' } id { '1' }
title { 'title' } title { 'title' }
type { 'error' } type { 'error' }
...@@ -25,4 +26,14 @@ FactoryBot.define do ...@@ -25,4 +26,14 @@ FactoryBot.define do
skip_create skip_create
end end
factory :error_tracking_error, class: 'ErrorTracking::Error' do
project
name { 'ActionView::MissingTemplate' }
description { 'Missing template posts/edit' }
actor { 'PostsController#edit' }
platform { 'ruby' }
first_seen_at { Time.now.iso8601 }
last_seen_at { Time.now.iso8601 }
end
end end
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
factory :error_tracking_error_event, class: 'Gitlab::ErrorTracking::ErrorEvent' do # There is an issue to rename this class https://gitlab.com/gitlab-org/gitlab/-/issues/323342.
factory :error_tracking_sentry_error_event, class: 'Gitlab::ErrorTracking::ErrorEvent' do
issue_id { 'id' } issue_id { 'id' }
date_received { Time.now.iso8601 } date_received { Time.now.iso8601 }
stack_trace_entries do stack_trace_entries do
...@@ -53,4 +54,14 @@ FactoryBot.define do ...@@ -53,4 +54,14 @@ FactoryBot.define do
skip_create skip_create
end end
factory :error_tracking_error_event, class: 'ErrorTracking::ErrorEvent' do
error factory: :error_tracking_error
description { 'ActionView::MissingTemplate' }
environment { 'development' }
level { 'error' }
occurred_at { Time.now.iso8601 }
payload { Gitlab::Json.parse(File.read(Rails.root.join('spec/fixtures/', 'error_tracking/parsed_event.json'))) }
end
end end
...@@ -42,7 +42,7 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do ...@@ -42,7 +42,7 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
end end
context 'error matched' do context 'error matched' do
let(:detailed_error) { build(:detailed_error_tracking_error) } let(:detailed_error) { build(:error_tracking_sentry_detailed_error) }
before do before do
allow(issue_details_service).to receive(:execute) allow(issue_details_service).to receive(:execute)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::ErrorTracking::StackTraceHighlightDecorator do RSpec.describe Gitlab::ErrorTracking::StackTraceHighlightDecorator do
let(:error_event) { build(:error_tracking_error_event) } let(:error_event) { build(:error_tracking_sentry_error_event) }
describe '.decorate' do describe '.decorate' do
subject(:decorate) { described_class.decorate(error_event) } subject(:decorate) { described_class.decorate(error_event) }
......
...@@ -241,7 +241,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -241,7 +241,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
describe '#issue_details' do describe '#issue_details' do
let(:issue) { build(:detailed_error_tracking_error) } let(:issue) { build(:error_tracking_sentry_detailed_error) }
let(:sentry_client) { double('sentry_client', issue_details: issue) } let(:sentry_client) { double('sentry_client', issue_details: issue) }
let(:commit_id) { issue.first_release_version } let(:commit_id) { issue.first_release_version }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe SentryErrorPresenter do RSpec.describe SentryErrorPresenter do
let(:error) { build(:detailed_error_tracking_error) } let(:error) { build(:error_tracking_sentry_detailed_error) }
let(:presenter) { described_class.new(error) } let(:presenter) { described_class.new(error) }
describe '#frequency' do describe '#frequency' do
......
...@@ -7,7 +7,7 @@ RSpec.describe 'getting a detailed sentry error' do ...@@ -7,7 +7,7 @@ RSpec.describe 'getting a detailed sentry error' do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:project_setting) { create(:project_error_tracking_setting, project: project) } let_it_be(:project_setting) { create(:project_error_tracking_setting, project: project) }
let_it_be(:current_user) { project.owner } let_it_be(:current_user) { project.owner }
let_it_be(:sentry_detailed_error) { build(:detailed_error_tracking_error) } let_it_be(:sentry_detailed_error) { build(:error_tracking_sentry_detailed_error) }
let(:sentry_gid) { sentry_detailed_error.to_global_id.to_s } let(:sentry_gid) { sentry_detailed_error.to_global_id.to_s }
let(:fields) do let(:fields) do
......
...@@ -16,7 +16,7 @@ RSpec.describe 'sentry errors requests' do ...@@ -16,7 +16,7 @@ RSpec.describe 'sentry errors requests' do
end end
describe 'getting a detailed sentry error' do describe 'getting a detailed sentry error' do
let_it_be(:sentry_detailed_error) { build(:detailed_error_tracking_error) } let_it_be(:sentry_detailed_error) { build(:error_tracking_sentry_detailed_error) }
let(:sentry_gid) { sentry_detailed_error.to_global_id.to_s } let(:sentry_gid) { sentry_detailed_error.to_global_id.to_s }
...@@ -97,7 +97,7 @@ RSpec.describe 'sentry errors requests' do ...@@ -97,7 +97,7 @@ RSpec.describe 'sentry errors requests' do
end end
describe 'getting an errors list' do describe 'getting an errors list' do
let_it_be(:sentry_error) { build(:error_tracking_error) } let_it_be(:sentry_error) { build(:error_tracking_sentry_error) }
let_it_be(:pagination) do let_it_be(:pagination) do
{ {
'next' => { 'cursor' => '2222' }, 'next' => { 'cursor' => '2222' },
...@@ -193,7 +193,7 @@ RSpec.describe 'sentry errors requests' do ...@@ -193,7 +193,7 @@ RSpec.describe 'sentry errors requests' do
end end
describe 'getting a stack trace' do describe 'getting a stack trace' do
let_it_be(:sentry_stack_trace) { build(:error_tracking_error_event) } let_it_be(:sentry_stack_trace) { build(:error_tracking_sentry_error_event) }
let(:sentry_gid) { global_id_of(Gitlab::ErrorTracking::DetailedError.new(id: 1)) } let(:sentry_gid) { global_id_of(Gitlab::ErrorTracking::DetailedError.new(id: 1)) }
......
...@@ -10,7 +10,7 @@ RSpec.describe ErrorTracking::IssueDetailsService do ...@@ -10,7 +10,7 @@ RSpec.describe ErrorTracking::IssueDetailsService do
describe '#execute' do describe '#execute' do
context 'with authorized user' do context 'with authorized user' do
context 'when issue_details returns a detailed error' do context 'when issue_details returns a detailed error' do
let(:detailed_error) { build(:detailed_error_tracking_error) } let(:detailed_error) { build(:error_tracking_sentry_detailed_error) }
let(:params) { { issue_id: detailed_error.id } } let(:params) { { issue_id: detailed_error.id } }
before do before do
......
...@@ -10,7 +10,7 @@ RSpec.describe ErrorTracking::IssueLatestEventService do ...@@ -10,7 +10,7 @@ RSpec.describe ErrorTracking::IssueLatestEventService do
describe '#execute' do describe '#execute' do
context 'with authorized user' do context 'with authorized user' do
context 'when issue_latest_event returns an error event' do context 'when issue_latest_event returns an error event' do
let(:error_event) { build(:error_tracking_error_event) } let(:error_event) { build(:error_tracking_sentry_error_event) }
before do before do
expect(error_tracking_setting) expect(error_tracking_setting)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment