add refund and event logic
This commit is contained in:
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user