dawarich/spec/services/own_tracks/importer_spec.rb

77 lines
2.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2024-03-23 08:36:09 -04:00
require 'rails_helper'
2025-02-22 17:14:23 -05:00
RSpec.describe OwnTracks::Importer do
2024-03-23 08:36:09 -04:00
describe '#call' do
2024-05-25 07:36:15 -04:00
subject(:parser) { described_class.new(import, user.id).call }
2024-03-23 08:36:09 -04:00
let(:user) { create(:user) }
let(:import) { create(:import, user:, name: 'owntracks_export.json') }
2024-03-23 08:36:09 -04:00
context 'when file exists' do
it 'creates points' do
expect { parser }.to change { Point.count }.by(9)
2024-03-23 08:36:09 -04:00
end
2024-08-15 13:47:59 -04:00
it 'correctly writes attributes' do
parser
point = Point.first
expect(point.lonlat.x).to be_within(0.001).of(13.332)
expect(point.lonlat.y).to be_within(0.001).of(52.225)
expect(point.attributes.except('lonlat')).to include(
2024-08-15 13:47:59 -04:00
'battery_status' => 'charging',
'battery' => 94,
'ping' => '100.266',
'altitude' => 36,
'accuracy' => 10,
'vertical_accuracy' => 4,
2025-02-07 13:17:28 -05:00
'velocity' => '1.4',
2024-08-15 13:47:59 -04:00
'connection' => 'wifi',
'ssid' => 'Home Wifi',
'bssid' => 'b0:f2:8:45:94:33',
'trigger' => 'background_event',
'tracker_id' => 'RO',
2024-10-19 13:29:43 -04:00
'timestamp' => 1_709_283_789,
2024-08-15 13:47:59 -04:00
'inrids' => ['5f1d1b'],
'in_regions' => ['home'],
'topic' => 'owntracks/test/iPhone 12 Pro',
'visit_id' => nil,
'user_id' => user.id,
'country' => nil,
'raw_data' => {
2024-10-19 13:29:43 -04:00
'm' => 1,
'p' => 100.266,
't' => 'p',
'bs' => 2,
'acc' => 10,
'alt' => 36,
'lat' => 52.225,
'lon' => 13.332,
'tid' => 'RO',
'tst' => 1_709_283_789,
'vac' => 4,
2025-02-07 13:17:28 -05:00
'vel' => 5,
2024-10-19 13:29:43 -04:00
'SSID' => 'Home Wifi',
'batt' => 94,
'conn' => 'w',
'BSSID' => 'b0:f2:8:45:94:33',
'_http' => true,
'_type' => 'location',
'topic' => 'owntracks/test/iPhone 12 Pro',
'inrids' => ['5f1d1b'],
'inregions' => ['home']
2024-08-15 13:47:59 -04:00
}
)
end
2025-02-07 13:17:28 -05:00
it 'correctly converts speed' do
parser
expect(Point.first.velocity).to eq('1.4')
end
2024-03-23 08:36:09 -04:00
end
end
end