Files
erahn-click/tests/Feature/SingleApiPembiayaanTest.php

67 lines
2.7 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\CompanyStatus;
use App\Services\PembiayaanService;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class SingleApiPembiayaanTest extends TestCase
{
/** @dataProvider paymentCases */
public function test_single_api_preserves_company_and_payment_restrictions($company, $pending, $ujrahBlocked, $disabled)
{
config([
'api.url' => 'https://customer.example',
'api.url_koop' => 'https://customer.example/',
'api.company' => $company,
]);
Auth::shouldReceive('user')->andReturn(['icno' => 'test-customer']);
$record = [
'norujukan' => 'TEST-001', 'kodcaw' => 'X03', 'tempoh' => 1,
'bakipjm' => 350, 'hargajualan' => 1, 'tagbaru' => $ujrahBlocked ? 1 : 0,
'lelong_tawarruq' => 1, 't_lelong' => '',
];
Http::fake(function ($request) use ($record, $pending, $ujrahBlocked) {
$path = parse_url($request->url(), PHP_URL_PATH);
// A trailing slash in the alias must not affect the fake response.
$path = '/' . ltrim($path, '/');
if ($path === '/portal/customer/info') {
return Http::response(['gadai' => [$record], 'lelong' => []]);
}
if (strpos($path, '/api/upahtawarruq/') === 0) {
return Http::response($ujrahBlocked ? ['keuntungan' => 3, 'ujrah' => 0.5] : 3.5);
}
if ($path === '/api/cawangan') {
return Http::response([['kodcaw' => 'X03', 'details_caw' => 'Xtra']]);
}
if ($path === '/portal/searchsagonline/') {
return Http::response(json_encode($pending));
}
if ($path === '/api/payable-ujrah-branches') {
return Http::response($ujrahBlocked ? [['kodcaw' => 'X03', 'gadaian_ujrah_payable' => 0]] : []);
}
throw new \RuntimeException('Unexpected request: ' . $request->url());
});
$rows = (new PembiayaanService)->getPembiayaan(null);
$this->assertCount(1, $rows);
$row = array_values($rows)[0];
$this->assertSame($company, $row->tag_syarikat);
$this->assertSame($disabled, $row->disabled_payment);
}
public function paymentCases()
{
return [
'eligible KOOP' => [CompanyStatus::COM_KOOPPKB, false, false, false],
'pending payment' => [CompanyStatus::COM_KOOPPKB, true, false, true],
'blocked ujrah branch' => [CompanyStatus::COM_KOOPPKB, false, true, true],
'PKB branch restriction' => [CompanyStatus::COM_PKB, false, false, true],
];
}
}