From b6ffbc46bce60185c1db19afac552999750ec4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=CC=81ctor=20Falco=CC=81n?= Date: Sat, 4 Jul 2026 20:09:38 +0200 Subject: [PATCH] test(open-banking): cover Interactive Brokers empty-statement guard The one hook with conditional logic, emptyProviderDataMessage(), had no test: no case fetched a valid Flex statement that parsed to zero accounts, so the 422 "No accounts found" branch was unverified and a regression there would be silent. Add a test that fakes a successful Flex response with an empty set and asserts the request is rejected with 422 and the NAV-section message, no banking_connections row is created, and no warning is logged (the empty case must not go through the credential-failure log path). --- .../InteractiveBrokersControllerTest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Feature/OpenBanking/InteractiveBrokersControllerTest.php b/tests/Feature/OpenBanking/InteractiveBrokersControllerTest.php index e780e7a0..eda548a8 100644 --- a/tests/Feature/OpenBanking/InteractiveBrokersControllerTest.php +++ b/tests/Feature/OpenBanking/InteractiveBrokersControllerTest.php @@ -6,6 +6,7 @@ use App\Models\Bank; use App\Models\BankingConnection; use App\Models\User; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Queue; use Illuminate\Support\Sleep; @@ -164,3 +165,24 @@ test('reports a rate-limit message when IB throttles the request', function () { ->assertUnprocessable() ->assertJsonFragment(['message' => 'Interactive Brokers is rate limiting requests. Please wait a few minutes and try again.']); }); + +test('a valid but empty flex statement returns 422 without creating a connection or logging a warning', function () { + Log::spy(); + + $user = User::factory()->onboarded()->create(); + Http::fake([ + '*SendRequest*' => Http::response('Success999'), + '*GetStatement*' => Http::response(''), + ]); + + $this->actingAs($user)->postJson('/open-banking/interactive-brokers/connect', ibConnect()) + ->assertUnprocessable() + ->assertJsonFragment(['message' => 'No accounts found in the Flex statement. Check that your Flex Query includes the NAV section.']); + + $this->assertDatabaseMissing('banking_connections', [ + 'user_id' => $user->id, + 'provider' => 'interactivebrokers', + ]); + + Log::shouldNotHaveReceived('warning'); +});