Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix(akahu): pull full history on initial Akahu sync (#2779)

pro395812b040e47eaf
diff --git a/app/models/akahu_item/importer.rb b/app/models/akahu_item/importer.rb
index 2c1f71204d..50077fce9f 100644
--- a/app/models/akahu_item/importer.rb
+++ b/app/models/akahu_item/importer.rb
@@ -236,7 +236,11 @@ class AkahuItem::Importer
if has_stored_transactions && akahu_item.last_synced_at
akahu_item.last_synced_at - 7.days
else
- 90.days.ago
+ # Initial sync: omit the start date entirely. Akahu's transactions
+ # endpoint defaults to the full accessible range when no start is given,
+ # so this pulls the connection's complete history instead of clamping it
+ # to a fixed lookback window (which truncated apps with >5 years of data).
+ nil
end
end
diff --git a/test/models/akahu_item/importer_test.rb b/test/models/akahu_item/importer_test.rb
index 4f751a3848..0f48e6a0bf 100644
--- a/test/models/akahu_item/importer_test.rb
+++ b/test/models/akahu_item/importer_test.rb
@@ -99,6 +99,16 @@ class AkahuItem::ImporterTest < ActiveSupport::TestCase
assert_equal "acc_123", provider.transaction_calls.first[:account_id]
end
+ test "initial sync fetches full history instead of clamping to a recent window" do
+ provider = FakeAkahuProvider.new
+
+ AkahuItem::Importer.new(@akahu_item, akahu_provider: provider).import
+
+ start_date = provider.transaction_calls.first[:start_date]
+ assert_nil start_date,
+ "initial sync should omit the start date so Akahu returns the full accessible history"
+ end
+
test "removes pending transactions that disappear from latest pending response" do
pending = [ pending_transaction(description: "Pending card auth", amount: -8.00) ]
import_with(pending_transactions: pending, posted_transactions: [])