mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Add specs for Imports::Create
This commit is contained in:
parent
9d573d90f3
commit
243a85ed4e
1 changed files with 105 additions and 0 deletions
105
spec/services/imports/create_spec.rb
Normal file
105
spec/services/imports/create_spec.rb
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Imports::Create do
|
||||
let(:user) { create(:user) }
|
||||
let(:service) { described_class.new(user, import) }
|
||||
|
||||
describe '#call' do
|
||||
context 'when source is google_semantic_history' do
|
||||
let(:import) { create(:import, source: 'google_semantic_history') }
|
||||
|
||||
it 'calls the GoogleMaps::SemanticHistoryParser' do
|
||||
expect(GoogleMaps::SemanticHistoryParser).to receive(:new).with(import, user.id).and_return(double(call: true))
|
||||
service.call
|
||||
end
|
||||
end
|
||||
|
||||
context 'when source is google_phone_takeout' do
|
||||
let(:import) { create(:import, source: 'google_phone_takeout') }
|
||||
|
||||
it 'calls the GoogleMaps::PhoneTakeoutParser' do
|
||||
expect(GoogleMaps::PhoneTakeoutParser).to receive(:new).with(import, user.id).and_return(double(call: true))
|
||||
service.call
|
||||
end
|
||||
end
|
||||
|
||||
context 'when source is owntracks' do
|
||||
let(:import) { create(:import, source: 'owntracks') }
|
||||
|
||||
it 'calls the OwnTracks::ExportParser' do
|
||||
expect(OwnTracks::ExportParser).to receive(:new).with(import, user.id).and_return(double(call: true))
|
||||
service.call
|
||||
end
|
||||
|
||||
context 'when import is successful' do
|
||||
it 'creates a finished notification' do
|
||||
service.call
|
||||
|
||||
expect(user.notifications.last.kind).to eq('info')
|
||||
end
|
||||
|
||||
it 'schedules stats creating' do
|
||||
Sidekiq::Testing.inline! do
|
||||
expect { service.call }.to have_enqueued_job(Stats::CalculatingJob)
|
||||
end
|
||||
end
|
||||
|
||||
it 'schedules visit suggesting' do
|
||||
Sidekiq::Testing.inline! do
|
||||
expect { service.call }.to have_enqueued_job(VisitSuggestingJob)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when import fails' do
|
||||
before do
|
||||
allow(OwnTracks::ExportParser).to receive(:new).with(import, user.id).and_return(double(call: false))
|
||||
end
|
||||
|
||||
it 'creates a failed notification' do
|
||||
service.call
|
||||
|
||||
expect(user.notifications.last.kind).to eq('error')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when source is gpx' do
|
||||
let(:import) { create(:import, source: 'gpx') }
|
||||
|
||||
it 'calls the Gpx::TrackParser' do
|
||||
expect(Gpx::TrackParser).to receive(:new).with(import, user.id).and_return(double(call: true))
|
||||
service.call
|
||||
end
|
||||
end
|
||||
|
||||
context 'when source is geojson' do
|
||||
let(:import) { create(:import, source: 'geojson') }
|
||||
|
||||
it 'calls the Geojson::ImportParser' do
|
||||
expect(Geojson::ImportParser).to receive(:new).with(import, user.id).and_return(double(call: true))
|
||||
service.call
|
||||
end
|
||||
end
|
||||
|
||||
context 'when source is immich_api' do
|
||||
let(:import) { create(:import, source: 'immich_api') }
|
||||
|
||||
it 'calls the Photos::ImportParser' do
|
||||
expect(Photos::ImportParser).to receive(:new).with(import, user.id).and_return(double(call: true))
|
||||
service.call
|
||||
end
|
||||
end
|
||||
|
||||
context 'when source is photoprism_api' do
|
||||
let(:import) { create(:import, source: 'photoprism_api') }
|
||||
|
||||
it 'calls the Photos::ImportParser' do
|
||||
expect(Photos::ImportParser).to receive(:new).with(import, user.id).and_return(double(call: true))
|
||||
service.call
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue