mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 15:35:22 +02:00
Merge branch 'main' of github.com:maybe-finance/maybe into zachgoll/plaid-domain-improvements
This commit is contained in:
commit
db02718d71
4 changed files with 57 additions and 11 deletions
|
@ -11,15 +11,11 @@ module AutoSync
|
|||
end
|
||||
|
||||
def family_needs_auto_sync?
|
||||
return false unless Current.family.present?
|
||||
return false unless Current.family.accounts.active.any?
|
||||
return false unless Current.family&.accounts&.active&.any?
|
||||
return false if (Current.family.last_sync_created_at&.to_date || 1.day.ago) >= Date.current
|
||||
|
||||
should_sync = (Current.family.last_synced_at&.to_date || 1.day.ago) < Date.current
|
||||
Rails.logger.info "Auto-syncing family #{Current.family.id}, last sync was #{Current.family.last_sync_created_at}"
|
||||
|
||||
if should_sync
|
||||
Rails.logger.info "Auto-syncing family #{Current.family.id}, last sync was #{Current.family.last_synced_at}"
|
||||
end
|
||||
|
||||
should_sync
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,6 +30,10 @@ module Syncable
|
|||
latest_sync&.completed_at
|
||||
end
|
||||
|
||||
def last_sync_created_at
|
||||
latest_sync&.created_at
|
||||
end
|
||||
|
||||
private
|
||||
def latest_sync
|
||||
syncs.ordered.first
|
||||
|
|
|
@ -129,8 +129,13 @@ class TradeBuilder
|
|||
def security
|
||||
ticker_symbol, exchange_operating_mic = ticker.present? ? ticker.split("|") : [ manual_ticker, nil ]
|
||||
|
||||
Security.find_or_create_by(ticker: ticker_symbol, exchange_operating_mic: exchange_operating_mic) do |s|
|
||||
FetchSecurityInfoJob.perform_later(s.id)
|
||||
end
|
||||
security = Security.find_or_create_by!(
|
||||
ticker: ticker_symbol,
|
||||
exchange_operating_mic: exchange_operating_mic
|
||||
)
|
||||
|
||||
FetchSecurityInfoJob.perform_later(security.id)
|
||||
|
||||
security
|
||||
end
|
||||
end
|
||||
|
|
41
test/controllers/concerns/auto_sync_test.rb
Normal file
41
test/controllers/concerns/auto_sync_test.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require "test_helper"
|
||||
|
||||
class AutoSyncTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
@family = @user.family
|
||||
|
||||
# Start fresh
|
||||
Sync.destroy_all
|
||||
end
|
||||
|
||||
test "auto-syncs family if hasn't synced" do
|
||||
assert_difference "Sync.count", 1 do
|
||||
get root_path
|
||||
end
|
||||
end
|
||||
|
||||
test "auto-syncs family if hasn't synced in last 24 hours" do
|
||||
# If request comes in at beginning of day, but last sync was 1 hour ago ("yesterday"), we still sync
|
||||
travel_to Time.current.beginning_of_day
|
||||
last_sync_datetime = 1.hour.ago
|
||||
|
||||
Sync.create!(syncable: @family, created_at: last_sync_datetime)
|
||||
|
||||
assert_difference "Sync.count", 1 do
|
||||
get root_path
|
||||
end
|
||||
end
|
||||
|
||||
test "does not auto-sync if family has synced today already" do
|
||||
travel_to Time.current.end_of_day
|
||||
|
||||
last_created_sync_at = 23.hours.ago
|
||||
|
||||
Sync.create!(syncable: @family, created_at: last_created_sync_at)
|
||||
|
||||
assert_no_difference "Sync.count" do
|
||||
get root_path
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue