Files
root 02ba2fe6b6
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
fix parent pages and teachers and admin
2026-07-09 13:56:22 -04:00

146 lines
4.9 KiB
PHP

<?php
namespace Tests\Unit\Services\Parents;
use App\Services\Parents\ParentConfigService;
use App\Services\Parents\ParentEnrollmentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ParentEnrollmentServiceTest extends TestCase
{
use RefreshDatabase;
public function test_overview_returns_students(): void
{
$this->seedConfig();
$parentId = $this->seedParent();
$studentId = DB::table('students')->insertGetId([
'school_id' => 'S-200',
'firstname' => 'Lana',
'lastname' => 'Parent',
'dob' => '2013-09-01',
'age' => 12,
'gender' => 'Female',
'photo_consent' => 1,
'parent_id' => $parentId,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
DB::table('enrollments')->insert([
'student_id' => $studentId,
'parent_id' => $parentId,
'school_year' => '2025-2026',
'semester' => 'Fall',
'enrollment_date' => '2025-09-01',
'enrollment_status' => 'enrolled',
'admission_status' => 'accepted',
'is_withdrawn' => 0,
]);
$service = new ParentEnrollmentService(new ParentConfigService);
$result = $service->overview($parentId, '2025-2026');
$this->assertSame('2025-2026', $result['selectedYear']);
$this->assertCount(1, $result['students']);
$this->assertSame('enrolled', $result['students'][0]['enrollment_status']);
}
public function test_withdrawal_request_creates_pending_zero_amount_refund(): void
{
$this->seedConfig();
$parentId = $this->seedParent();
$studentId = DB::table('students')->insertGetId([
'school_id' => 'S-201',
'firstname' => 'Omar',
'lastname' => 'Parent',
'dob' => '2014-09-01',
'age' => 11,
'gender' => 'Male',
'photo_consent' => 1,
'parent_id' => $parentId,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
DB::table('enrollments')->insert([
'student_id' => $studentId,
'parent_id' => $parentId,
'school_year' => '2025-2026',
'semester' => 'Fall',
'enrollment_date' => '2025-09-01',
'enrollment_status' => 'enrolled',
'admission_status' => 'accepted',
'is_withdrawn' => 0,
]);
$invoiceId = DB::table('invoices')->insertGetId([
'parent_id' => $parentId,
'invoice_number' => 'INV-201',
'total_amount' => 100,
'paid_amount' => 100,
'balance' => 0,
'issue_date' => now(),
'due_date' => now()->addWeek(),
'status' => 'paid',
'description' => 'Tuition',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
$service = new ParentEnrollmentService(new ParentConfigService);
$result = $service->updateEnrollment($parentId, [], [$studentId]);
$this->assertSame([$studentId], $result['withdrawn']);
$this->assertDatabaseHas('refunds', [
'parent_id' => $parentId,
'invoice_id' => $invoiceId,
'school_year' => '2025-2026',
'semester' => 'Fall',
'status' => 'Pending',
'refund_amount' => 0,
'refund_paid_amount' => 0,
]);
}
private function seedParent(): int
{
return DB::table('users')->insertGetId([
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '1234567890',
'email' => 'parent3@example.com',
'address_street' => '123 Street',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'password' => bcrypt('password'),
'user_type' => 'primary',
'semester' => 'Fall',
'school_year' => '2025-2026',
'status' => 'Active',
]);
}
private function seedConfig(): void
{
DB::table('configuration')->insert([
['config_key' => 'school_year', 'config_value' => '2025-2026'],
['config_key' => 'semester', 'config_value' => 'Fall'],
['config_key' => 'date_age_reference', 'config_value' => '2025-12-31'],
['config_key' => 'enrollment_deadline', 'config_value' => '2025-09-01'],
['config_key' => 'refund_deadline', 'config_value' => '2025-09-15'],
['config_key' => 'fall_semester_start', 'config_value' => '2025-09-05'],
]);
}
}