feat: add client method to BaseIntegrationService for pre-configured HTTP client and implement test for client functionality

This commit is contained in:
2026-07-06 08:50:52 -03:00
parent 387e136707
commit 1af5b1d7ed
2 changed files with 66 additions and 0 deletions

View File

@@ -247,4 +247,56 @@ class IntegrationServiceTest extends TestCase
$service->getToken();
}
public function test_it_returns_preconfigured_client(): void
{
Integration::create([
'integration_code' => 'telepagos_homo',
'name' => 'Telepagos',
'url' => 'https://api.telepagos.com.ar',
'integration_data_schema' => [
'username' => 'required|string',
'password' => 'required|string',
]
]);
TenantIntegration::create([
'tenant_code' => $this->tenant->codigo,
'integration_code' => 'telepagos_homo',
'integration_data' => [
'username' => 'tele_user',
'password' => 'tele_pass',
]
]);
Http::fake([
'https://api.telepagos.com.ar/v2/auth/token' => Http::response([
'status' => 'ok',
'token' => 'mock-jwt-token-123',
'expires_at' => now()->addHour()->toDateTimeString()
], 200),
'https://api.telepagos.com.ar/v1/payments' => Http::response([
'status' => 'success',
'payment_id' => 999
], 200)
]);
$service = new TelepagosIntegrationService('telepagos');
$service->forTenant($this->tenant->codigo);
// Get configured client and perform GET request
$client = $service->client();
$this->assertInstanceOf(\Illuminate\Http\Client\PendingRequest::class, $client);
$response = $client->get('/v1/payments');
$this->assertTrue($response->successful());
$this->assertEquals(999, $response->json('payment_id'));
// Assert the authorization header was correctly set during request
Http::assertSent(function ($request) {
return $request->hasHeader('Authorization', 'Bearer mock-jwt-token-123')
&& $request->url() === 'https://api.telepagos.com.ar/v1/payments';
});
}
}