2024-05-23 14:35:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-03-24 13:05:39 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
2025-03-23 13:37:10 -04:00
|
|
|
RSpec.describe Import::ProcessJob, type: :job do
|
2024-04-02 11:37:38 -04:00
|
|
|
describe '#perform' do
|
2025-03-23 13:37:10 -04:00
|
|
|
subject(:perform) { described_class.new.perform(import.id) }
|
2024-04-02 11:37:38 -04:00
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
2025-03-23 16:00:31 -04:00
|
|
|
let!(:import) { create(:import, user:, name: '2024-03.rec') }
|
|
|
|
|
let(:file_path) { Rails.root.join('spec/fixtures/files/owntracks/2024-03.rec') }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
import.file.attach(io: File.open(file_path), filename: '2024-03.rec', content_type: 'application/octet-stream')
|
|
|
|
|
end
|
2024-04-02 11:37:38 -04:00
|
|
|
|
|
|
|
|
it 'creates points' do
|
2024-06-30 11:47:36 -04:00
|
|
|
expect { perform }.to change { Point.count }.by(9)
|
2024-04-02 11:37:38 -04:00
|
|
|
end
|
2024-04-02 17:26:26 -04:00
|
|
|
|
2024-10-24 10:59:15 -04:00
|
|
|
it 'calls Stats::CalculatingJob' do
|
2024-12-06 10:52:36 -05:00
|
|
|
# Timestamp of the first point in the "2024-03.rec" fixture file
|
|
|
|
|
expect(Stats::CalculatingJob).to receive(:perform_later).with(user.id, 2024, 3)
|
2024-04-02 17:26:26 -04:00
|
|
|
|
|
|
|
|
perform
|
|
|
|
|
end
|
2024-07-04 16:20:12 -04:00
|
|
|
|
|
|
|
|
context 'when there is an error' do
|
|
|
|
|
before do
|
2025-02-22 17:14:23 -05:00
|
|
|
allow_any_instance_of(OwnTracks::Importer).to receive(:call).and_raise(StandardError)
|
2024-07-04 16:20:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not create points' do
|
|
|
|
|
expect { perform }.not_to(change { Point.count })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'creates a notification' do
|
|
|
|
|
expect { perform }.to change { Notification.count }.by(1)
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-04-02 11:37:38 -04:00
|
|
|
end
|
2024-03-24 13:05:39 -04:00
|
|
|
end
|