add refund and event logic

This commit is contained in:
root
2026-03-10 23:12:49 -04:00
parent ba1206e314
commit f6be51576c
67 changed files with 4808 additions and 1000 deletions
@@ -3,6 +3,8 @@
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use App\Services\Fees\FeeRefundCalculatorService;
use App\Services\Fees\FeeStudentFeeService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
@@ -63,6 +65,17 @@ class FeeCalculationControllerTest extends TestCase
$response->assertOk();
$response->assertJsonPath('ok', true);
$response->assertJsonStructure([
'ok',
'refund' => [
'refund_amount',
'total_paid',
'refund_deadline',
'school_end_date',
'weeks_of_study',
'withdrawn_students',
],
]);
$this->assertGreaterThan(0, (float) $response->json('refund.refund_amount'));
}
@@ -83,9 +96,110 @@ class FeeCalculationControllerTest extends TestCase
$response->assertOk();
$response->assertJsonPath('ok', true);
$response->assertJsonStructure([
'ok',
'tuition' => [
'total_tuition',
],
]);
$this->assertGreaterThan(0, (float) $response->json('tuition.total_tuition'));
}
public function test_refund_endpoint_requires_authentication(): void
{
$response = $this->postJson('/api/v1/finance/fees/refund', [
'parent_id' => 10,
'students' => [],
]);
$response->assertStatus(401);
}
public function test_tuition_total_endpoint_requires_authentication(): void
{
$response = $this->postJson('/api/v1/finance/fees/tuition-total', [
'students' => [],
]);
$response->assertStatus(401);
}
public function test_refund_endpoint_validates_payload(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->postJson('/api/v1/finance/fees/refund', [
'parent_id' => 0,
'students' => [
['class_section_id' => null],
],
]);
$response->assertStatus(422);
$response->assertJsonStructure(['message', 'errors']);
}
public function test_tuition_total_endpoint_validates_payload(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->postJson('/api/v1/finance/fees/tuition-total', [
'students' => [
['class_section_id' => null],
],
]);
$response->assertStatus(422);
$response->assertJsonStructure(['message', 'errors']);
}
public function test_refund_endpoint_handles_service_failure(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
$this->mock(FeeRefundCalculatorService::class, function ($mock) {
$mock->shouldReceive('calculateRefund')->andThrow(new \RuntimeException('boom'));
});
$response = $this->postJson('/api/v1/finance/fees/refund', [
'parent_id' => 10,
'students' => [
[
'student_id' => 1,
'class_section_id' => 101,
'enrollment_status' => 'withdrawn',
'admission_status' => 'accepted',
'withdrawal_date' => '2025-01-15',
],
],
]);
$response->assertStatus(500);
$response->assertJsonPath('ok', false);
}
public function test_tuition_total_endpoint_handles_service_failure(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
$this->mock(FeeStudentFeeService::class, function ($mock) {
$mock->shouldReceive('totalTuitionFee')->andThrow(new \RuntimeException('boom'));
});
$response = $this->postJson('/api/v1/finance/fees/tuition-total', [
'students' => [
['class_section_id' => 101],
],
]);
$response->assertStatus(500);
$response->assertJsonPath('ok', false);
}
private function seedConfig(): void
{
DB::table('configuration')->insert([