1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-06 05:55:21 +02:00

Partial sync interface

This commit is contained in:
Zach Gollwitzer 2025-05-26 05:39:14 -04:00
parent 6e202bd7ec
commit 7a8ac82823
13 changed files with 34 additions and 94 deletions

View file

@ -7,7 +7,7 @@ module SyncableInterfaceTest
test "can sync later" do
assert_difference "@syncable.syncs.count", 1 do
assert_enqueued_with job: SyncJob do
@syncable.sync_later(window_start_date: 2.days.ago.to_date)
@syncable.sync_later
end
end
end
@ -17,20 +17,4 @@ module SyncableInterfaceTest
@syncable.class.any_instance.expects(:perform_sync).with(mock_sync).once
@syncable.perform_sync(mock_sync)
end
test "second sync request widens existing pending window" do
later_start = 2.days.ago.to_date
first_sync = @syncable.sync_later(window_start_date: later_start, window_end_date: later_start)
earlier_start = 5.days.ago.to_date
wider_end = Date.current
assert_no_difference "@syncable.syncs.count" do
@syncable.sync_later(window_start_date: earlier_start, window_end_date: wider_end)
end
first_sync.reload
assert_equal earlier_start, first_sync.window_start_date
assert_equal wider_end, first_sync.window_end_date
end
end

View file

@ -4,7 +4,7 @@ class SyncJobTest < ActiveJob::TestCase
test "sync is performed" do
syncable = accounts(:depository)
sync = syncable.syncs.create!(window_start_date: 2.days.ago.to_date)
sync = syncable.syncs.create!
sync.expects(:perform).once

View file

@ -30,7 +30,7 @@ class EntryTest < ActiveSupport::TestCase
prior_date = @entry.date - 1
@entry.update! date: prior_date
@entry.account.expects(:sync_later).with(window_start_date: prior_date)
@entry.account.expects(:sync_later).once
@entry.sync_account_later
end
@ -38,14 +38,14 @@ class EntryTest < ActiveSupport::TestCase
prior_date = @entry.date
@entry.update! date: @entry.date + 1
@entry.account.expects(:sync_later).with(window_start_date: prior_date)
@entry.account.expects(:sync_later).once
@entry.sync_account_later
end
test "triggers sync with correct start date when transaction deleted" do
@entry.destroy!
@entry.account.expects(:sync_later).with(window_start_date: nil)
@entry.account.expects(:sync_later).once
@entry.sync_account_later
end

View file

@ -15,12 +15,12 @@ class Family::SyncerTest < ActiveSupport::TestCase
Account.any_instance
.expects(:sync_later)
.with(parent_sync: family_sync, window_start_date: nil, window_end_date: nil)
.with(parent_sync: family_sync)
.times(manual_accounts_count)
PlaidItem.any_instance
.expects(:sync_later)
.with(parent_sync: family_sync, window_start_date: nil, window_end_date: nil)
.with(parent_sync: family_sync)
.times(items_count)
syncer.perform_sync(family_sync)

View file

@ -199,24 +199,4 @@ class SyncTest < ActiveSupport::TestCase
assert_equal "stale", stale_pending.reload.status
assert_equal "stale", stale_syncing.reload.status
end
test "expand_window_if_needed widens start and end dates on a pending sync" do
initial_start = 1.day.ago.to_date
initial_end = 1.day.ago.to_date
sync = Sync.create!(
syncable: accounts(:depository),
window_start_date: initial_start,
window_end_date: initial_end
)
new_start = 5.days.ago.to_date
new_end = Date.current
sync.expand_window_if_needed(new_start, new_end)
sync.reload
assert_equal new_start, sync.window_start_date
assert_equal new_end, sync.window_end_date
end
end