test: align loan workflow assertions with stage enums

This commit is contained in:
Meghdad committed 2026-07-23 00:11:17 +03:30
1 parent 6fdf4b63b9
commit d5c39a2bd7
1 file changed
+11 -10
+11 -10
View File
@@ -1,5 +1,6 @@
<?php <?php
use App\Domain\Loan\Enums\LoanStage;
use App\Models\Loan; use App\Models\Loan;
use Database\Seeders\BankFlowSeeder; use Database\Seeders\BankFlowSeeder;
@@ -21,9 +22,9 @@ it('approves a valid personal loan and records applicable stages', function () {
$loan = Loan::query()->where('public_id', $loanId)->firstOrFail(); $loan = Loan::query()->where('public_id', $loanId)->firstOrFail();
expect($loan->histories()->orderBy('id')->pluck('stage_code')->all())->toBe([ expect($loan->histories()->orderBy('id')->pluck('stage_code')->all())->toBe([
'VALIDATION', LoanStage::Validation,
'FRAUD_CHECK', LoanStage::FraudCheck,
'CREDIT_CHECK', LoanStage::CreditCheck,
]); ]);
}); });
@@ -55,14 +56,14 @@ it('approves a valid business loan with a guarantor', function () {
$loan = Loan::query()->where('public_id', $loanId)->firstOrFail(); $loan = Loan::query()->where('public_id', $loanId)->firstOrFail();
expect($loan->histories()->orderBy('id')->pluck('stage_code')->all())->toBe([ expect($loan->histories()->orderBy('id')->pluck('stage_code')->all())->toBe([
'VALIDATION', LoanStage::Validation,
'FRAUD_CHECK', LoanStage::FraudCheck,
'GUARANTOR_CHECK', LoanStage::GuarantorCheck,
'CREDIT_CHECK', LoanStage::CreditCheck,
]); ]);
}); });
it('stops for fraud and credit manual review decisions', function (array $overrides, string $stage) { it('stops for fraud and credit manual review decisions', function (array $overrides, LoanStage $stage) {
$loanId = $this->postJson('/api/v1/loans', validLoanPayload($overrides))->json('loanId'); $loanId = $this->postJson('/api/v1/loans', validLoanPayload($overrides))->json('loanId');
$this->postJson("/api/v1/loans/{$loanId}/process") $this->postJson("/api/v1/loans/{$loanId}/process")
@@ -74,8 +75,8 @@ it('stops for fraud and credit manual review decisions', function (array $overri
expect($loan->histories()->latest('id')->value('stage_code'))->toBe($stage); expect($loan->histories()->latest('id')->value('stage_code'))->toBe($stage);
})->with([ })->with([
'fraud review' => [['customerId' => 'REVIEW-1001'], 'FRAUD_CHECK'], 'fraud review' => [['customerId' => 'REVIEW-1001'], LoanStage::FraudCheck],
'credit review' => [['creditScore' => 600], 'CREDIT_CHECK'], 'credit review' => [['creditScore' => 600], LoanStage::CreditCheck],
]); ]);
it('executes manager approval only above its threshold', function ( it('executes manager approval only above its threshold', function (