Update owntracks params spec

This commit is contained in:
Eugene Burmakin 2024-10-15 22:30:16 +02:00
parent a2f3aef608
commit 11d024127e
3 changed files with 49 additions and 40 deletions

View file

@ -33,7 +33,7 @@ class ImportsController < ApplicationController
raw_data =
case params[:import][:source]
when 'gpx' then Hash.from_xml(file)
when 'owntracks' then file
when 'owntracks' then OwnTracks::RecParser.new(file).call
else JSON.parse(file)
end

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class OwnTracks::RecParser
attr_reader :file
def initialize(file)
@file = file.read
end
def call
file.split("\n").map do |line|
JSON.parse(line.split("\t* \t")[1])
end
end
end

View file

@ -8,56 +8,50 @@ RSpec.describe OwnTracks::Params do
let(:file_path) { 'spec/fixtures/files/owntracks/2024-03.rec' }
let(:file) { File.open(file_path) }
let(:json) { JSON.parse(file.read) }
let(:user) { json.keys.first }
let(:topic) { json[user].keys.first }
let(:raw_point_params) { json[user][topic].first }
let(:json) { OwnTracks::RecParser.new(file).call }
let(:raw_point_params) { json.first }
let(:expected_json) do
{
latitude: 40.7128,
longitude: -74.006,
battery_status: 'charging',
battery: 85,
ping: nil,
altitude: 41,
accuracy: 8,
vertical_accuracy: 3,
velocity: nil,
connection: 'wifi',
latitude: 52.225,
longitude: 13.332,
battery: 94,
ping: 100.266,
altitude: 36,
accuracy: 10,
vertical_accuracy: 4,
velocity: 0,
ssid: 'Home Wifi',
bssid: 'b0:f2:8:45:94:33',
trigger: 'background_event',
tracker_id: 'RO',
timestamp: 1_706_965_203,
timestamp: 1_709_283_789,
inrids: ['5f1d1b'],
in_regions: ['home'],
topic: 'owntracks/test/iPhone 12 Pro',
raw_data: {
'batt' => 85,
'lon' => -74.006,
'acc' => 8,
'bs' => 2,
'inrids' => ['5f1d1b'],
'BSSID' => 'b0:f2:8:45:94:33',
'SSID' => 'Home Wifi',
'vac' => 3,
'inregions' => ['home'],
'lat' => 40.7128,
'topic' => 'owntracks/test/iPhone 12 Pro',
't' => 'p',
'conn' => 'w',
'm' => 1,
'tst' => 1_706_965_203,
'alt' => 41,
battery_status: 'charging',
connection: 'wifi',
trigger: 'background_event',
raw_data: { 'bs' => 2,
'p' => 100.266,
'batt' => 94,
'_type' => 'location',
'tid' => 'RO',
'_http' => true,
'ghash' => 'u33d773',
'isorcv' => '2024-02-03T13:00:03Z',
'isotst' => '2024-02-03T13:00:03Z',
'disptst' => '2024-02-03 13:00:03'
}
'topic' => 'owntracks/test/iPhone 12 Pro',
'alt' => 36,
'lon' => 13.332,
'vel' => 0,
't' => 'p',
'BSSID' => 'b0:f2:8:45:94:33',
'SSID' => 'Home Wifi',
'conn' => 'w',
'vac' => 4,
'acc' => 10,
'tst' => 1_709_283_789,
'lat' => 52.225,
'm' => 1,
'inrids' => ['5f1d1b'],
'inregions' => ['home'],
'_http' => true }
}
end