Files
sure/test/jobs/sophtron_refresh_poll_job_test.rb
Juan José Mata 81cdccb768 [codex] Complete Sophtron account mapping (#1698)
* Complete Sophtron account mapping

* Clarify Sophtron login challenge flow

* Add Sophtron connection UI timeout

* Treat Sophtron timeout jobs as failed

* Reset failed Sophtron connection state

* Handle stale Sophtron connection jobs

* Advance Sophtron polling timeout

* Shorten Sophtron connection timeout

* Fix Sophtron modal polling updates

* Stabilize Sophtron MFA polling

* Give Sophtron OTP challenges more time

* Clarify Sophtron institution login failures

* Extend Sophtron polling during login progress

* Probe Sophtron accounts after completed MFA step

* Align Sophtron dialogs with design system

* Start Sophtron initial load after linking accounts

* Fix Sophtron initial transaction load

* Fail Sophtron sync without institution connection

* Fix tests

* Wrap Sophtron account linking in transaction

* Wrap Sophtron provider responses

* Fix Sophtron MFA security tests

* Guard Sophtron MFA challenge arrays

* Respect Sophtron initial load window

* Use unique Sophtron MFA answer field ids

* Address Sophtron review follow-ups

* Fix Sophtron transaction sync refresh

* Avoid blocking Sophtron refresh polling

* Move Sophtron account helpers to model

* Keep Sophtron grouping provider-level

* Start new Sophtron institution links

* Isolate Sophtron institution connections

---------

Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
2026-05-08 15:15:23 +02:00

48 lines
1.8 KiB
Ruby

require "test_helper"
class SophtronRefreshPollJobTest < ActiveJob::TestCase
setup do
@family = families(:dylan_family)
@item = @family.sophtron_items.create!(
name: "Sophtron",
user_id: "developer-user",
access_key: Base64.strict_encode64("secret-key"),
customer_id: "cust-1",
user_institution_id: "ui-1"
)
@account = accounts(:depository)
@sophtron_account = @item.sophtron_accounts.create!(
account_id: "acct-1",
name: "Checking",
currency: "USD",
balance: 100,
raw_transactions_payload: [ { id: "existing-tx" } ]
)
AccountProvider.create!(account: @account, provider: @sophtron_account)
end
test "re-enqueues while Sophtron refresh job is still running" do
provider = mock
provider.expects(:get_job_information).with("refresh-job").returns({ LastStatus: "Started" })
SophtronItem.any_instance.stubs(:sophtron_provider).returns(provider)
assert_enqueued_with(job: SophtronRefreshPollJob) do
SophtronRefreshPollJob.perform_now(@sophtron_account, job_id: "refresh-job", attempts_remaining: 2)
end
end
test "imports transactions and schedules account sync when refresh completes" do
provider = mock
provider.expects(:get_job_information).with("refresh-job").returns({ LastStatus: "Completed" })
SophtronItem.any_instance.stubs(:sophtron_provider).returns(provider)
SophtronItem::Importer.any_instance.expects(:import_transactions_after_refresh)
.with(@sophtron_account)
.returns({ success: true, transactions_count: 1 })
SophtronAccount::Processor.any_instance.expects(:process).returns({ transactions_imported: 1 })
assert_enqueued_with(job: SyncJob) do
SophtronRefreshPollJob.perform_now(@sophtron_account, job_id: "refresh-job")
end
end
end