add refund logic and fix books inventory logic
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 47s
Tests / PHPUnit (push) Failing after 1m20s

This commit is contained in:
root
2026-08-22 13:44:25 -04:00
parent 23d1cbb64c
commit d906a915d6
45 changed files with 4711 additions and 442 deletions
@@ -5,8 +5,51 @@ namespace Tests\App\Services;
use App\Services\FeeCalculationService;
use CodeIgniter\Test\CIUnitTestCase;
class FeeCalculationServiceRefundAdapterHarness extends FeeCalculationService
{
public array $previewedEnrollmentIds = [];
public function __construct(private array $latestByEnrollment, private array $previewByEnrollment)
{
}
protected function latestWithdrawalCalculation(int $enrollmentId): ?array
{
return $this->latestByEnrollment[$enrollmentId] ?? null;
}
protected function previewWithdrawalCalculation(int $enrollmentId): array
{
$this->previewedEnrollmentIds[] = $enrollmentId;
return $this->previewByEnrollment[$enrollmentId] ?? ['new_refund_request_cents' => 0];
}
}
class FeeCalculationServiceTest extends CIUnitTestCase
{
public function testRefundAdapterUsesWithdrawalFinancialPreviewAmounts(): void
{
$service = new FeeCalculationServiceRefundAdapterHarness(
latestByEnrollment: [
10 => ['status' => 'preview', 'new_refund_request_cents' => 12345],
11 => ['status' => 'superseded', 'new_refund_request_cents' => 99999],
],
previewByEnrollment: [
11 => ['status' => 'preview', 'new_refund_request_cents' => 500],
]
);
$refund = $service->calculateRefund([
['id' => 10, 'parent_id' => 8, 'enrollment_status' => 'withdraw under review'],
['id' => 11, 'parent_id' => 8, 'enrollment_status' => 'refund pending'],
['id' => 12, 'parent_id' => 8, 'enrollment_status' => 'enrolled'],
['id' => 13, 'parent_id' => 9, 'enrollment_status' => 'refund pending'],
], 8);
$this->assertSame(128.45, $refund);
$this->assertSame([11], $service->previewedEnrollmentIds);
}
public function testRefundReversesLatestTuitionTierFirst(): void
{
$fees = $this->refundFeeStack(3, 2, 380.0, 280.0);