mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Add specs for GoogleMaps::SemanticHistoryParser
This commit is contained in:
parent
9a962bca72
commit
2d26418337
2 changed files with 107 additions and 3 deletions
|
|
@ -57,15 +57,15 @@ class GoogleMaps::SemanticHistoryParser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
elsif timeline_object['placeVisit'].present?
|
elsif timeline_object['placeVisit'].present?
|
||||||
if timeline_object['placeVisit']['location']['latitudeE7'].present? &&
|
if timeline_object.dig('placeVisit', 'location', 'latitudeE7').present? &&
|
||||||
timeline_object['placeVisit']['location']['longitudeE7'].present?
|
timeline_object.dig('placeVisit', 'location', 'longitudeE7').present?
|
||||||
{
|
{
|
||||||
latitude: timeline_object['placeVisit']['location']['latitudeE7'].to_f / 10**7,
|
latitude: timeline_object['placeVisit']['location']['latitudeE7'].to_f / 10**7,
|
||||||
longitude: timeline_object['placeVisit']['location']['longitudeE7'].to_f / 10**7,
|
longitude: timeline_object['placeVisit']['location']['longitudeE7'].to_f / 10**7,
|
||||||
timestamp: DateTime.parse(timeline_object['placeVisit']['duration']['startTimestamp']),
|
timestamp: DateTime.parse(timeline_object['placeVisit']['duration']['startTimestamp']),
|
||||||
raw_data: timeline_object
|
raw_data: timeline_object
|
||||||
}
|
}
|
||||||
elsif timeline_object['placeVisit']['otherCandidateLocations'].any?
|
elsif timeline_object.dig('placeVisit', 'otherCandidateLocations')&.any?
|
||||||
point = timeline_object['placeVisit']['otherCandidateLocations'][0]
|
point = timeline_object['placeVisit']['otherCandidateLocations'][0]
|
||||||
|
|
||||||
next unless point['latitudeE7'].present? && point['longitudeE7'].present?
|
next unless point['latitudeE7'].present? && point['longitudeE7'].present?
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,109 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe GoogleMaps::SemanticHistoryParser do
|
RSpec.describe GoogleMaps::SemanticHistoryParser do
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
|
subject(:parser) { described_class.new(import, user.id).call }
|
||||||
|
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
context 'when activitySegment is present' do
|
||||||
|
context 'when startLocation is blank' do
|
||||||
|
let(:import) { create(:import, raw_data: { 'timelineObjects' => [activity_segment] }) }
|
||||||
|
let(:activity_segment) do
|
||||||
|
{
|
||||||
|
'activitySegment' => {
|
||||||
|
'waypointPath' => {
|
||||||
|
'waypoints' => [
|
||||||
|
{ 'latE7' => 123_456_789, 'lngE7' => 123_456_789 }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'duration' => { 'startTimestamp' => Time.zone.now.to_s }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a point' do
|
||||||
|
expect { parser }.to change(Point, :count).by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when waypointPath is blank' do
|
||||||
|
let(:activity_segment) do
|
||||||
|
{
|
||||||
|
'activitySegment' => {
|
||||||
|
'duration' => { 'startTimestamp' => Time.zone.now.to_s }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not create a point' do
|
||||||
|
expect { parser }.not_to change(Point, :count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when startLocation is present' do
|
||||||
|
let(:import) { create(:import, raw_data: { 'timelineObjects' => [activity_segment] }) }
|
||||||
|
let(:activity_segment) do
|
||||||
|
{
|
||||||
|
'activitySegment' => {
|
||||||
|
'startLocation' => { 'latitudeE7' => 123_456_789, 'longitudeE7' => 123_456_789 },
|
||||||
|
'duration' => { 'startTimestamp' => Time.zone.now.to_s }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a point' do
|
||||||
|
expect { parser }.to change(Point, :count).by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when placeVisit is present' do
|
||||||
|
context 'when location with coordinates is present' do
|
||||||
|
let(:import) { create(:import, raw_data: { 'timelineObjects' => [place_visit] }) }
|
||||||
|
let(:place_visit) do
|
||||||
|
{
|
||||||
|
'placeVisit' => {
|
||||||
|
'location' => { 'latitudeE7' => 123_456_789, 'longitudeE7' => 123_456_789 },
|
||||||
|
'duration' => { 'startTimestamp' => Time.zone.now.to_s }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a point' do
|
||||||
|
expect { parser }.to change(Point, :count).by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when location with coordinates is blank' do
|
||||||
|
let(:import) { create(:import, raw_data: { 'timelineObjects' => [place_visit] }) }
|
||||||
|
let(:place_visit) do
|
||||||
|
{
|
||||||
|
'placeVisit' => {
|
||||||
|
'location' => {},
|
||||||
|
'duration' => { 'startTimestamp' => Time.zone.now.to_s }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not create a point' do
|
||||||
|
expect { parser }.not_to change(Point, :count)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when otherCandidateLocations is present' do
|
||||||
|
let(:place_visit) do
|
||||||
|
{
|
||||||
|
'placeVisit' => {
|
||||||
|
'otherCandidateLocations' => [{ 'latitudeE7' => 123_456_789, 'longitudeE7' => 123_456_789 }],
|
||||||
|
'duration' => { 'startTimestamp' => Time.zone.now.to_s }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a point' do
|
||||||
|
expect { parser }.to change(Point, :count).by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue