Remove obsolete specs

This commit is contained in:
Eugene Burmakin 2025-08-29 14:23:38 +02:00
parent 30fb51940c
commit e95ad88382
5 changed files with 28 additions and 303 deletions

View file

@ -24,14 +24,6 @@ RSpec.describe Tracks::CleanupJob, type: :job do
described_class.new.perform(older_than: 1.day.ago)
end
it 'logs processing information' do
allow(Tracks::Generator).to receive(:new).and_return(double(call: nil))
expect(Rails.logger).to receive(:info).with(/Processing missed tracks for user #{user.id}/)
described_class.new.perform(older_than: 1.day.ago)
end
end
context 'with users having insufficient points' do

View file

@ -7,13 +7,10 @@ RSpec.describe Tracks::CreateJob, type: :job do
describe '#perform' do
let(:generator_instance) { instance_double(Tracks::Generator) }
let(:notification_service) { instance_double(Notifications::Create) }
before do
allow(Tracks::Generator).to receive(:new).and_return(generator_instance)
allow(generator_instance).to receive(:call)
allow(Notifications::Create).to receive(:new).and_return(notification_service)
allow(notification_service).to receive(:call)
allow(generator_instance).to receive(:call).and_return(2)
end
@ -27,13 +24,6 @@ RSpec.describe Tracks::CreateJob, type: :job do
mode: :daily
)
expect(generator_instance).to have_received(:call)
expect(Notifications::Create).to have_received(:new).with(
user: user,
kind: :info,
title: 'Tracks Generated',
content: 'Created 2 tracks from your location data. Check your tracks section to view them.'
)
expect(notification_service).to have_received(:call)
end
context 'with custom parameters' do
@ -44,8 +34,6 @@ RSpec.describe Tracks::CreateJob, type: :job do
before do
allow(Tracks::Generator).to receive(:new).and_return(generator_instance)
allow(generator_instance).to receive(:call)
allow(Notifications::Create).to receive(:new).and_return(notification_service)
allow(notification_service).to receive(:call)
allow(generator_instance).to receive(:call).and_return(1)
end
@ -59,37 +47,16 @@ RSpec.describe Tracks::CreateJob, type: :job do
mode: :daily
)
expect(generator_instance).to have_received(:call)
expect(Notifications::Create).to have_received(:new).with(
user: user,
kind: :info,
title: 'Tracks Generated',
content: 'Created 1 tracks from your location data. Check your tracks section to view them.'
)
expect(notification_service).to have_received(:call)
end
end
context 'when generator raises an error' do
let(:error_message) { 'Something went wrong' }
let(:notification_service) { instance_double(Notifications::Create) }
before do
allow(Tracks::Generator).to receive(:new).and_return(generator_instance)
allow(generator_instance).to receive(:call).and_raise(StandardError, error_message)
allow(Notifications::Create).to receive(:new).and_return(notification_service)
allow(notification_service).to receive(:call)
end
it 'creates an error notification' do
described_class.new.perform(user.id)
expect(Notifications::Create).to have_received(:new).with(
user: user,
kind: :error,
title: 'Track Generation Failed',
content: "Failed to generate tracks from your location data: #{error_message}"
)
expect(notification_service).to have_received(:call)
allow(ExceptionReporter).to receive(:call)
end
it 'reports the error using ExceptionReporter' do
@ -135,13 +102,6 @@ RSpec.describe Tracks::CreateJob, type: :job do
mode: :incremental
)
expect(generator_instance).to have_received(:call)
expect(Notifications::Create).to have_received(:new).with(
user: user,
kind: :info,
title: 'Tracks Generated',
content: 'Created 2 tracks from your location data. Check your tracks section to view them.'
)
expect(notification_service).to have_received(:call)
end
end
end
@ -152,32 +112,6 @@ RSpec.describe Tracks::CreateJob, type: :job do
end
end
context 'when self-hosted' do
let(:generator_instance) { instance_double(Tracks::Generator) }
let(:notification_service) { instance_double(Notifications::Create) }
let(:error_message) { 'Something went wrong' }
before do
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
allow(Tracks::Generator).to receive(:new).and_return(generator_instance)
allow(generator_instance).to receive(:call).and_raise(StandardError, error_message)
allow(Notifications::Create).to receive(:new).and_return(notification_service)
allow(notification_service).to receive(:call)
end
it 'creates a failure notification when self-hosted' do
described_class.new.perform(user.id)
expect(Notifications::Create).to have_received(:new).with(
user: user,
kind: :error,
title: 'Track Generation Failed',
content: "Failed to generate tracks from your location data: #{error_message}"
)
expect(notification_service).to have_received(:call)
end
end
context 'when not self-hosted' do
let(:generator_instance) { instance_double(Tracks::Generator) }
let(:notification_service) { instance_double(Notifications::Create) }

View file

@ -36,26 +36,6 @@ RSpec.describe Tracks::ParallelGeneratorJob do
job.perform(user_id)
end
it 'logs the start of the operation' do
# Allow other logs to pass through
allow(Rails.logger).to receive(:info).and_call_original
expect(Rails.logger).to receive(:info)
.with("Starting parallel track generation for user #{user_id} (mode: bulk)")
job.perform(user_id)
end
it 'logs successful session creation' do
# Allow other logs to pass through
allow(Rails.logger).to receive(:info).and_call_original
expect(Rails.logger).to receive(:info)
.with(/Parallel track generation initiated for user #{user_id}/)
job.perform(user_id)
end
it 'accepts custom parameters' do
start_at = 1.week.ago
end_at = Time.current
@ -68,50 +48,6 @@ RSpec.describe Tracks::ParallelGeneratorJob do
job.perform(user_id, start_at: start_at, end_at: end_at, mode: mode, chunk_size: chunk_size)
end
it 'does not create notifications when session is created successfully' do
expect(Notifications::Create).not_to receive(:new)
job.perform(user_id)
end
end
context 'when no tracks are generated (no time chunks)' do
let(:user_no_points) { create(:user) }
it 'logs a warning' do
# Allow other logs to pass through
allow(Rails.logger).to receive(:info).and_call_original
allow(Rails.logger).to receive(:warn).and_call_original
expect(Rails.logger).to receive(:warn)
.with("No tracks to generate for user #{user_no_points.id} (no time chunks created)")
job.perform(user_no_points.id)
end
it 'creates info notification with 0 tracks' do
notification_service = double('notification_service')
expect(Notifications::Create).to receive(:new)
.with(
user: user_no_points,
kind: :info,
title: 'Track Generation Complete',
content: 'Generated 0 tracks from your location data. Check your tracks section to view them.'
).and_return(notification_service)
expect(notification_service).to receive(:call)
job.perform(user_no_points.id)
end
end
context 'when user is not found' do
let(:invalid_user_id) { 99999 }
it 'raises ActiveRecord::RecordNotFound' do
expect {
job.perform(invalid_user_id)
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'when an error occurs' do
@ -127,52 +63,6 @@ RSpec.describe Tracks::ParallelGeneratorJob do
job.perform(user_id)
end
it 'logs the error' do
# Allow other logs to pass through
allow(Rails.logger).to receive(:info).and_call_original
allow(Rails.logger).to receive(:error).and_call_original
expect(Rails.logger).to receive(:error)
.with("Parallel track generation failed for user #{user_id}: #{error_message}")
job.perform(user_id)
end
it 'creates error notification for self-hosted instances' do
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
notification_service = double('notification_service')
expect(Notifications::Create).to receive(:new)
.with(
user: user,
kind: :error,
title: 'Track Generation Failed',
content: "Failed to generate tracks from your location data: #{error_message}"
).and_return(notification_service)
expect(notification_service).to receive(:call)
job.perform(user_id)
end
it 'does not create error notification for hosted instances' do
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
expect(Notifications::Create).not_to receive(:new)
job.perform(user_id)
end
context 'when user is nil (error before user is found)' do
before do
allow(User).to receive(:find).and_raise(StandardError.new('Database error'))
end
it 'does not create notification' do
expect(Notifications::Create).not_to receive(:new)
job.perform(user_id)
end
end
end
context 'with different modes' do
@ -262,59 +152,4 @@ RSpec.describe Tracks::ParallelGeneratorJob do
}.to have_enqueued_job(described_class)
end
end
describe 'private methods' do
describe '#create_info_notification' do
it 'creates info notification with correct parameters' do
tracks_created = 5
notification_service = double('notification_service')
expect(Notifications::Create).to receive(:new)
.with(
user: user,
kind: :info,
title: 'Track Generation Complete',
content: "Generated #{tracks_created} tracks from your location data. Check your tracks section to view them."
).and_return(notification_service)
expect(notification_service).to receive(:call)
job.send(:create_info_notification, user, tracks_created)
end
end
describe '#create_error_notification' do
let(:error) { StandardError.new('Test error') }
context 'when self-hosted' do
before do
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
end
it 'creates error notification' do
notification_service = double('notification_service')
expect(Notifications::Create).to receive(:new)
.with(
user: user,
kind: :error,
title: 'Track Generation Failed',
content: "Failed to generate tracks from your location data: #{error.message}"
).and_return(notification_service)
expect(notification_service).to receive(:call)
job.send(:create_error_notification, user, error)
end
end
context 'when not self-hosted' do
before do
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
end
it 'does not create notification' do
expect(Notifications::Create).not_to receive(:new)
job.send(:create_error_notification, user, error)
end
end
end
end
end

View file

@ -73,17 +73,6 @@ RSpec.describe Tracks::BoundaryDetector do
expect(detector.resolve_cross_chunk_tracks).to eq(1)
end
it 'logs the operation' do
# Use allow() to handle all the SQL debug logs, then expect the specific ones we care about
allow(Rails.logger).to receive(:debug).and_call_original
allow(Rails.logger).to receive(:info).and_call_original
expect(Rails.logger).to receive(:debug).with(/Found \d+ boundary track candidates for user #{user.id}/)
expect(Rails.logger).to receive(:info).with(/Resolved 1 boundary tracks for user #{user.id}/)
detector.resolve_cross_chunk_tracks
end
it 'creates a merged track with all points' do
expect {
detector.resolve_cross_chunk_tracks
@ -100,19 +89,6 @@ RSpec.describe Tracks::BoundaryDetector do
expect(Track.where(id: original_track_ids)).to be_empty
end
it 'logs track deletion and creation' do
# Use allow() to handle all the SQL debug logs, then expect the specific ones we care about
allow(Rails.logger).to receive(:debug).and_call_original
allow(Rails.logger).to receive(:info).and_call_original
expect(Rails.logger).to receive(:debug).with(/Merging \d+ boundary tracks for user #{user.id}/)
expect(Rails.logger).to receive(:debug).with(/Deleting boundary track #{track1.id}/)
expect(Rails.logger).to receive(:debug).with(/Deleting boundary track #{track2.id}/)
expect(Rails.logger).to receive(:info).with(/Created merged boundary track \d+ with \d+ points/)
detector.resolve_cross_chunk_tracks
end
end
context 'when merge fails' do
@ -132,12 +108,6 @@ RSpec.describe Tracks::BoundaryDetector do
end
it 'returns 0 and logs warning' do
# Use allow() to handle all the SQL debug logs
allow(Rails.logger).to receive(:debug).and_call_original
allow(Rails.logger).to receive(:info).and_call_original
allow(Rails.logger).to receive(:warn).and_call_original
expect(Rails.logger).to receive(:warn).with(/Failed to create merged boundary track for user #{user.id}/)
expect(detector.resolve_cross_chunk_tracks).to eq(0)
end

View file

@ -128,12 +128,6 @@ RSpec.describe Tracks::ParallelGenerator do
expect(user.tracks.count).to eq(0)
end
it 'logs track cleanup' do
allow(Rails.logger).to receive(:info) # Allow any log messages
expect(Rails.logger).to receive(:info).with(/Cleaning \d+ existing tracks for bulk regeneration/).at_least(:once)
generator.call
end
end
context 'daily mode' do