mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
Fix failed specs
This commit is contained in:
parent
b43810b1fb
commit
510868a594
4 changed files with 58 additions and 19 deletions
|
|
@ -35,7 +35,7 @@ class GoogleMaps::RecordsParser
|
||||||
{
|
{
|
||||||
latitude: location['latitudeE7'].to_f / 10**7,
|
latitude: location['latitudeE7'].to_f / 10**7,
|
||||||
longitude: location['longitudeE7'].to_f / 10**7,
|
longitude: location['longitudeE7'].to_f / 10**7,
|
||||||
timestamp: Timestamps.parse_timestamp(location['timestamp'] || location['timestampMs']),
|
timestamp: parse_timestamp(location),
|
||||||
altitude: location['altitude'],
|
altitude: location['altitude'],
|
||||||
velocity: location['velocity'],
|
velocity: location['velocity'],
|
||||||
raw_data: location,
|
raw_data: location,
|
||||||
|
|
@ -85,4 +85,8 @@ class GoogleMaps::RecordsParser
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_timestamp(location)
|
||||||
|
Timestamps.parse_timestamp(location['timestamp'] || location['timestampMs'])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,36 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe GoogleMaps::RecordsParser do
|
RSpec.describe GoogleMaps::RecordsParser do
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
subject(:parser) { described_class.new(import).call(json) }
|
subject(:parser) { described_class.new(import).call(locations) }
|
||||||
|
|
||||||
let(:import) { create(:import) }
|
let(:import) { create(:import) }
|
||||||
let(:time) { DateTime.new(2025, 1, 1, 12, 0, 0) }
|
let(:time) { DateTime.new(2025, 1, 1, 12, 0, 0) }
|
||||||
let(:json) do
|
let(:locations) do
|
||||||
{
|
[
|
||||||
'latitudeE7' => 123_456_789,
|
{
|
||||||
'longitudeE7' => 123_456_789,
|
'timestampMs' => (time.to_f * 1000).to_i.to_s,
|
||||||
'altitude' => 0,
|
'latitudeE7' => 123_456_789,
|
||||||
'velocity' => 0
|
'longitudeE7' => 123_456_789,
|
||||||
}
|
'accuracy' => 10,
|
||||||
|
'altitude' => 100,
|
||||||
|
'verticalAccuracy' => 5,
|
||||||
|
'activity' => [
|
||||||
|
{
|
||||||
|
'timestampMs' => (time.to_f * 1000).to_i.to_s,
|
||||||
|
'activity' => [
|
||||||
|
{
|
||||||
|
'type' => 'STILL',
|
||||||
|
'confidence' => 100
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with regular timestamp' do
|
context 'with regular timestamp' do
|
||||||
let(:json) { super().merge('timestamp' => time.to_s) }
|
let(:locations) { super()[0].merge('timestamp' => time.to_s).to_json }
|
||||||
|
|
||||||
it 'creates a point' do
|
it 'creates a point' do
|
||||||
expect { parser }.to change(Point, :count).by(1)
|
expect { parser }.to change(Point, :count).by(1)
|
||||||
|
|
@ -26,11 +41,23 @@ RSpec.describe GoogleMaps::RecordsParser do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when point already exists' do
|
context 'when point already exists' do
|
||||||
let(:json) { super().merge('timestamp' => time.to_s) }
|
let(:locations) do
|
||||||
|
[
|
||||||
|
super()[0].merge(
|
||||||
|
'timestamp' => time.to_s,
|
||||||
|
'latitudeE7' => 123_456_789,
|
||||||
|
'longitudeE7' => 123_456_789
|
||||||
|
)
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create(
|
create(
|
||||||
:point, user: import.user, import:, latitude: 12.3456789, longitude: 12.3456789,
|
:point,
|
||||||
|
user: import.user,
|
||||||
|
import: import,
|
||||||
|
latitude: 12.3456789,
|
||||||
|
longitude: 12.3456789,
|
||||||
timestamp: time.to_i
|
timestamp: time.to_i
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -41,7 +68,9 @@ RSpec.describe GoogleMaps::RecordsParser do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with timestampMs in milliseconds' do
|
context 'with timestampMs in milliseconds' do
|
||||||
let(:json) { super().merge('timestampMs' => (time.to_f * 1000).to_i.to_s) }
|
let(:locations) do
|
||||||
|
[super()[0].merge('timestampMs' => (time.to_f * 1000).to_i.to_s)]
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates a point using milliseconds timestamp' do
|
it 'creates a point using milliseconds timestamp' do
|
||||||
expect { parser }.to change(Point, :count).by(1)
|
expect { parser }.to change(Point, :count).by(1)
|
||||||
|
|
@ -49,7 +78,9 @@ RSpec.describe GoogleMaps::RecordsParser do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with ISO 8601 timestamp' do
|
context 'with ISO 8601 timestamp' do
|
||||||
let(:json) { super().merge('timestamp' => time.iso8601) }
|
let(:locations) do
|
||||||
|
[super()[0].merge('timestamp' => time.iso8601)]
|
||||||
|
end
|
||||||
|
|
||||||
it 'parses ISO 8601 timestamp correctly' do
|
it 'parses ISO 8601 timestamp correctly' do
|
||||||
expect { parser }.to change(Point, :count).by(1)
|
expect { parser }.to change(Point, :count).by(1)
|
||||||
|
|
@ -59,7 +90,9 @@ RSpec.describe GoogleMaps::RecordsParser do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with timestamp in milliseconds' do
|
context 'with timestamp in milliseconds' do
|
||||||
let(:json) { super().merge('timestamp' => (time.to_f * 1000).to_i.to_s) }
|
let(:locations) do
|
||||||
|
[super()[0].merge('timestamp' => (time.to_f * 1000).to_i.to_s)]
|
||||||
|
end
|
||||||
|
|
||||||
it 'parses millisecond timestamp correctly' do
|
it 'parses millisecond timestamp correctly' do
|
||||||
expect { parser }.to change(Point, :count).by(1)
|
expect { parser }.to change(Point, :count).by(1)
|
||||||
|
|
@ -69,7 +102,9 @@ RSpec.describe GoogleMaps::RecordsParser do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with timestamp in seconds' do
|
context 'with timestamp in seconds' do
|
||||||
let(:json) { super().merge('timestamp' => time.to_i.to_s) }
|
let(:locations) do
|
||||||
|
[super()[0].merge('timestamp' => time.to_i.to_s)]
|
||||||
|
end
|
||||||
|
|
||||||
it 'parses second timestamp correctly' do
|
it 'parses second timestamp correctly' do
|
||||||
expect { parser }.to change(Point, :count).by(1)
|
expect { parser }.to change(Point, :count).by(1)
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ require 'rails_helper'
|
||||||
RSpec.describe Tasks::Imports::GoogleRecords do
|
RSpec.describe Tasks::Imports::GoogleRecords do
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let(:file_path) { Rails.root.join('spec/fixtures/files/google/records.json') }
|
let(:file_path) { Rails.root.join('spec/fixtures/files/google/records.json').to_s }
|
||||||
|
|
||||||
it 'schedules the Import::GoogleTakeoutJob' do
|
it 'schedules the Import::GoogleTakeoutJob' do
|
||||||
expect(Import::GoogleTakeoutJob).to receive(:perform_later).exactly(3).times
|
expect(Import::GoogleTakeoutJob).to receive(:perform_later).exactly(1).time
|
||||||
|
|
||||||
described_class.new(file_path, user.email).call
|
described_class.new(file_path, user.email).call
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe 'import.rake' do
|
describe 'import.rake' do
|
||||||
let(:file_path) { Rails.root.join('spec/fixtures/files/google/records.json') }
|
let(:file_path) { Rails.root.join('spec/fixtures/files/google/records.json').to_s }
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
it 'calls importing class' do
|
it 'calls importing class' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue