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 <FlexStatements> 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).
This commit is contained in:
parent
08430c8b32
commit
b6ffbc46bc
|
|
@ -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('<FlexStatementResponse><Status>Success</Status><ReferenceCode>999</ReferenceCode></FlexStatementResponse>'),
|
||||
'*GetStatement*' => Http::response('<FlexQueryResponse queryName="Whisper" type="AF"><FlexStatements count="0"></FlexStatements></FlexQueryResponse>'),
|
||||
]);
|
||||
|
||||
$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');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue