2024-08-21 12:40:54 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-03-15 18:27:31 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe Import, type: :model do
|
2024-03-15 19:01:00 -04:00
|
|
|
describe 'associations' do
|
|
|
|
|
it { is_expected.to have_many(:points).dependent(:destroy) }
|
|
|
|
|
it { is_expected.to belong_to(:user) }
|
|
|
|
|
end
|
2024-06-08 16:10:10 -04:00
|
|
|
|
2025-06-25 15:14:33 -04:00
|
|
|
describe 'validations' do
|
2025-06-26 13:24:40 -04:00
|
|
|
subject { build(:import, name: 'test import') }
|
|
|
|
|
|
2025-06-25 15:14:33 -04:00
|
|
|
it { is_expected.to validate_presence_of(:name) }
|
|
|
|
|
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:user_id) }
|
|
|
|
|
end
|
|
|
|
|
|
2024-06-08 16:10:10 -04:00
|
|
|
describe 'enums' do
|
2024-06-19 15:16:06 -04:00
|
|
|
it do
|
|
|
|
|
is_expected.to define_enum_for(:source).with_values(
|
|
|
|
|
google_semantic_history: 0,
|
|
|
|
|
owntracks: 1,
|
|
|
|
|
google_records: 2,
|
|
|
|
|
google_phone_takeout: 3,
|
2024-08-21 12:40:54 -04:00
|
|
|
gpx: 4,
|
2024-09-02 16:42:29 -04:00
|
|
|
immich_api: 5,
|
2024-12-03 10:05:38 -05:00
|
|
|
geojson: 6,
|
|
|
|
|
photoprism_api: 7
|
2024-06-19 15:16:06 -04:00
|
|
|
)
|
|
|
|
|
end
|
2024-06-08 16:10:10 -04:00
|
|
|
end
|
2024-12-06 11:32:45 -05:00
|
|
|
|
|
|
|
|
describe '#years_and_months_tracked' do
|
|
|
|
|
let(:import) { create(:import) }
|
|
|
|
|
let(:timestamp) { Time.zone.local(2024, 11, 1) }
|
2025-01-20 11:59:13 -05:00
|
|
|
let!(:points) do
|
|
|
|
|
(1..3).map do |i|
|
|
|
|
|
create(:point, import:, timestamp: timestamp + i.minutes)
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-12-06 11:32:45 -05:00
|
|
|
|
|
|
|
|
it 'returns years and months tracked' do
|
|
|
|
|
expect(import.years_and_months_tracked).to eq([[2024, 11]])
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-04-02 14:58:35 -04:00
|
|
|
|
|
|
|
|
describe '#migrate_to_new_storage' do
|
|
|
|
|
let(:raw_data) { Rails.root.join('spec/fixtures/files/geojson/export.json') }
|
|
|
|
|
let(:import) { create(:import, source: 'geojson', raw_data:) }
|
|
|
|
|
|
|
|
|
|
it 'attaches the file to the import' do
|
|
|
|
|
import.migrate_to_new_storage
|
|
|
|
|
|
|
|
|
|
expect(import.file.attached?).to be_truthy
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when file is attached' do
|
|
|
|
|
it 'is a importable file' do
|
|
|
|
|
import.migrate_to_new_storage
|
|
|
|
|
|
|
|
|
|
expect { import.process! }.to change(Point, :count).by(10)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|