2024-10-03 09:08:23 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe Imports::Watcher do
|
|
|
|
|
describe '#call' do
|
|
|
|
|
subject(:service) { described_class.new.call }
|
2024-12-16 14:53:48 -05:00
|
|
|
|
2024-10-03 09:08:23 -04:00
|
|
|
let(:watched_dir_path) { Rails.root.join('spec/fixtures/files/watched') }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
stub_const('Imports::Watcher::WATCHED_DIR_PATH', watched_dir_path)
|
2024-12-16 06:13:38 -05:00
|
|
|
end
|
|
|
|
|
|
2025-06-09 07:39:25 -04:00
|
|
|
after { Sidekiq::Testing.fake! }
|
|
|
|
|
|
2024-12-25 07:05:42 -05:00
|
|
|
context 'when user exists' do
|
|
|
|
|
let!(:user) { create(:user, email: 'user@domain.com') }
|
2024-12-24 07:08:14 -05:00
|
|
|
|
2024-12-25 07:05:42 -05:00
|
|
|
it 'creates an import for the user' do
|
|
|
|
|
expect { service }.to change(user.imports, :count).by(6)
|
2024-12-16 06:13:38 -05:00
|
|
|
end
|
2024-10-03 09:08:23 -04:00
|
|
|
|
2024-12-25 07:05:42 -05:00
|
|
|
it 'enqueues importing jobs for the user' do
|
2025-03-23 13:37:10 -04:00
|
|
|
expect { service }.to have_enqueued_job(Import::ProcessJob).exactly(6).times
|
2024-12-16 06:13:38 -05:00
|
|
|
end
|
2024-10-03 09:08:23 -04:00
|
|
|
|
2024-12-16 06:13:38 -05:00
|
|
|
context 'when the import already exists' do
|
|
|
|
|
it 'does not create a new import' do
|
2024-12-16 14:53:48 -05:00
|
|
|
create(:import, user:, name: '2023_January.json')
|
2024-12-16 06:13:38 -05:00
|
|
|
create(:import, user:, name: 'export_same_points.json')
|
|
|
|
|
create(:import, user:, name: 'gpx_track_single_segment.gpx')
|
|
|
|
|
create(:import, user:, name: 'location-history.json')
|
2024-12-16 14:53:48 -05:00
|
|
|
create(:import, user:, name: 'owntracks.rec')
|
2024-12-16 06:13:38 -05:00
|
|
|
create(:import, user:, name: 'Records.json')
|
2024-12-16 14:53:48 -05:00
|
|
|
|
2024-12-16 06:13:38 -05:00
|
|
|
expect { service }.not_to change(Import, :count)
|
2024-10-03 09:08:23 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-12-25 07:05:42 -05:00
|
|
|
|
|
|
|
|
context 'when user does not exist' do
|
2025-03-23 13:37:10 -04:00
|
|
|
it 'does not call Import::ProcessJob' do
|
|
|
|
|
expect(Import::ProcessJob).not_to receive(:perform_later)
|
2024-12-25 07:05:42 -05:00
|
|
|
|
|
|
|
|
service
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not create an import' do
|
|
|
|
|
expect { service }.not_to change(Import, :count)
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-10-03 09:08:23 -04:00
|
|
|
end
|
|
|
|
|
end
|