2024-08-12 16:18:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe Visits::Suggest do
|
|
|
|
|
describe '#call' do
|
2024-08-13 12:25:48 -04:00
|
|
|
let!(:user) { create(:user) }
|
2024-10-19 17:03:35 -04:00
|
|
|
let(:start_at) { Time.new(2020, 1, 1, 0, 0, 0) }
|
|
|
|
|
let(:end_at) { Time.new(2020, 1, 1, 2, 0, 0) }
|
2024-08-13 12:25:48 -04:00
|
|
|
|
|
|
|
|
let!(:points) do
|
|
|
|
|
[
|
2024-09-28 10:43:36 -04:00
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 5.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 10.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 15.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 20.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 25.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 30.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 35.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 40.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 45.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 50.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 55.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 95.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 100.minutes),
|
|
|
|
|
create(:point, :with_known_location, user:, timestamp: start_at + 105.minutes)
|
2024-08-13 12:25:48 -04:00
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
subject { described_class.new(user, start_at:, end_at:).call }
|
|
|
|
|
|
|
|
|
|
it 'creates places' do
|
|
|
|
|
expect { subject }.to change(Place, :count).by(1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'creates visits' do
|
|
|
|
|
expect { subject }.to change(Visit, :count).by(1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'creates visits notification' do
|
|
|
|
|
expect { subject }.to change(Notification, :count).by(1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when reverse geocoding is enabled' do
|
|
|
|
|
before do
|
|
|
|
|
stub_const('REVERSE_GEOCODING_ENABLED', true)
|
|
|
|
|
stub_const('PHOTON_API_HOST', 'http://localhost:2323')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'reverse geocodes visits' do
|
|
|
|
|
expect_any_instance_of(Visit).to receive(:async_reverse_geocode).and_call_original
|
|
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-10-02 16:05:12 -04:00
|
|
|
|
|
|
|
|
context 'when reverse geocoding is disabled' do
|
|
|
|
|
before do
|
|
|
|
|
stub_const('REVERSE_GEOCODING_ENABLED', false)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not reverse geocode visits' do
|
|
|
|
|
expect_any_instance_of(Visit).not_to receive(:async_reverse_geocode)
|
|
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-08-12 16:18:11 -04:00
|
|
|
end
|
|
|
|
|
end
|