125 lines
5.5 KiB
PHP
125 lines
5.5 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/ShorakaIntegrationTest.php';
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\ShorakaTransaction;
|
|
|
|
class ShorakaGadaiTest extends ShorakaIntegrationTest
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
foreach (['mysql7', 'branch_test'] as $connection) {
|
|
$this->app['config']->set('database.connections.' . $connection, [
|
|
'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '',
|
|
]);
|
|
DB::purge($connection);
|
|
}
|
|
Schema::connection('mysql7')->create('arrahn_master_db', function (Blueprint $table) {
|
|
$table->string('kodcaw'); $table->string('mysql');
|
|
});
|
|
Schema::connection('mysql7')->create('customer', function (Blueprint $table) {
|
|
$table->string('kpbaru'); $table->string('kplama')->nullable(); $table->string('nama');
|
|
});
|
|
Schema::connection('mysql7')->create('komuditi_transaksi', function (Blueprint $table) {
|
|
$table->string('norujukan');
|
|
});
|
|
Schema::connection('branch_test')->create('gadai', function (Blueprint $table) {
|
|
$table->string('norujukan'); $table->string('nokp'); $table->string('kodcaw');
|
|
$table->decimal('pinjaman', 15, 2); $table->decimal('hargajualan', 15, 2);
|
|
$table->integer('tagserah')->default(0);
|
|
$table->integer('tagkomuditi')->default(0); $table->integer('cetak')->default(0);
|
|
$table->string('sttebus')->default('');
|
|
});
|
|
DB::connection('mysql7')->table('arrahn_master_db')->insert([
|
|
['kodcaw' => 'KB2', 'mysql' => 'branch_test'],
|
|
['kodcaw' => 'KB3', 'mysql' => 'branch_test'],
|
|
]);
|
|
DB::connection('mysql7')->table('customer')->insert(['kpbaru' => 'IC-1', 'nama' => 'Nama Database']);
|
|
DB::connection('branch_test')->table('gadai')->insert([
|
|
'norujukan' => 'SAG-001', 'kodcaw' => 'KB2', 'nokp' => 'IC-1',
|
|
'pinjaman' => 1000, 'hargajualan' => 1200,
|
|
]);
|
|
}
|
|
|
|
public function testBranchSubmissionUsesDatabaseAmountsAndSynchronizesTag(): void
|
|
{
|
|
$this->fakeResponse(['orderId' => '9999', 'status' => 'Completed']);
|
|
$this->json('POST', '/api/shoraka/gadai/KB2/SAG-001/submit', [
|
|
'order_amount' => 1, 'ownership' => 'Tampered',
|
|
])->seeStatusCode(200);
|
|
Http::assertSent(function ($request) {
|
|
return $request['order_amount'] === '1000.00'
|
|
&& $request['murabaha_amount'] === '1200.00'
|
|
&& $request['ownership'] === 'Nama Database'
|
|
&& (int) $request['tenor_other'] === 12;
|
|
});
|
|
$this->assertSame('KB2', ShorakaTransaction::first()->kodcaw);
|
|
$this->assertEquals(1, DB::connection('branch_test')->table('gadai')->value('tagkomuditi'));
|
|
$this->json('GET', '/api/shoraka/gadai/KB2/SAG-001')->seeJson(['can_complete' => true]);
|
|
}
|
|
|
|
public function testPendingOrderKeepsTagUnsetAndBlocksSag(): void
|
|
{
|
|
$this->fakeResponse(['orderId' => '9999', 'status' => 'Active']);
|
|
$this->json('POST', '/api/shoraka/gadai/KB2/SAG-001/submit')->seeStatusCode(200);
|
|
$this->assertEquals(0, DB::connection('branch_test')->table('gadai')->value('tagkomuditi'));
|
|
$this->json('PUT', '/api/gadai/norujukan/cetak/KB2/SAG-001')->seeStatusCode(409);
|
|
}
|
|
|
|
public function testLegacyPurchaseCannotBeSubmittedAgain(): void
|
|
{
|
|
DB::connection('mysql7')->table('komuditi_transaksi')->insert(['norujukan' => 'SAG-001']);
|
|
Http::fake();
|
|
$this->json('POST', '/api/shoraka/gadai/KB2/SAG-001/submit')->seeStatusCode(409);
|
|
Http::assertNothingSent();
|
|
}
|
|
|
|
public function testChangedFinancingCannotBeCompleted(): void
|
|
{
|
|
$record = $this->transaction('Completed');
|
|
$record->update(['kodcaw' => 'KB2']);
|
|
DB::connection('branch_test')->table('gadai')->update(['pinjaman' => 900]);
|
|
$this->json('GET', '/api/shoraka/gadai/KB2/SAG-001')->seeJson(['can_complete' => false]);
|
|
$this->json('GET', '/api/shoraka/gadai/KB2/SAG-001/certificate')->seeStatusCode(409);
|
|
}
|
|
|
|
public function testDifferentBranchCannotReadOrder(): void
|
|
{
|
|
$record = $this->transaction('Completed');
|
|
$record->update(['kodcaw' => 'KB2']);
|
|
$this->json('GET', '/api/shoraka/gadai/KB3/SAG-001')->seeStatusCode(404);
|
|
}
|
|
|
|
public function testHistoricalFinancingWithoutCommodityLedgerCanStillBeHandedOver(): void
|
|
{
|
|
Http::fake();
|
|
$this->json('PUT', '/api/gadai/norujukan/serah/KB2/SAG-001')->seeStatusCode(200);
|
|
$this->assertEquals(1, DB::connection('branch_test')->table('gadai')->value('tagserah'));
|
|
Http::assertNothingSent();
|
|
}
|
|
|
|
public function testSubmittedContractCannotBeRegisteredAgain(): void
|
|
{
|
|
$this->transaction('Completed')->update(['kodcaw' => 'KB2']);
|
|
Http::fake();
|
|
$this->json('PUT', '/api/gadai/norujukan/KB2/SAG-001', [
|
|
'kodcaw' => 'KB2', 'norujukan' => 'SAG-001',
|
|
])->seeStatusCode(409);
|
|
Http::assertNothingSent();
|
|
}
|
|
|
|
public function testShorakaOrderCannotUpdateOrCancelLegacyStock(): void
|
|
{
|
|
$this->transaction('Completed')->update(['kodcaw' => 'KB2']);
|
|
Http::fake();
|
|
$this->json('PUT', '/api/komuditi/update', ['norujukan' => 'SAG-001'])->seeStatusCode(409);
|
|
$this->json('PUT', '/api/komuditi/batal', ['norujukan' => 'SAG-001'])->seeStatusCode(409);
|
|
Http::assertNothingSent();
|
|
}
|
|
}
|