add more controller

This commit is contained in:
root
2026-03-10 00:48:32 -04:00
parent 5eeaec0257
commit 20ee70d153
151 changed files with 9481 additions and 8407 deletions
@@ -0,0 +1,85 @@
<?php
namespace Tests\Unit\Services\Parents;
use App\Services\Parents\ParentAttendanceReportCalendarService;
use App\Services\Parents\ParentAttendanceReportService;
use App\Services\Parents\ParentConfigService;
use App\Services\SemesterRangeService;
use App\Services\Semesters\SemesterConfigService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ParentAttendanceReportServiceTest extends TestCase
{
use RefreshDatabase;
public function test_form_data_returns_students(): void
{
$this->seedConfig();
$parentId = $this->seedParent();
$this->seedStudent($parentId);
$service = new ParentAttendanceReportService(
new ParentConfigService(),
new ParentAttendanceReportCalendarService(new ParentConfigService()),
new SemesterRangeService(new SemesterConfigService())
);
$data = $service->formData($parentId);
$this->assertSame($parentId, $data['students'][0]['parent_id']);
$this->assertNotEmpty($data['sundays']);
}
private function seedParent(): int
{
return DB::table('users')->insertGetId([
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '1234567890',
'email' => 'parent.report.service@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 seedStudent(int $parentId): void
{
DB::table('students')->insert([
'school_id' => 'S-400',
'firstname' => 'Casey',
'lastname' => 'Parent',
'dob' => '2014-09-01',
'age' => 11,
'gender' => 'Female',
'photo_consent' => 1,
'parent_id' => $parentId,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
}
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' => 'parent_report_cutoff', 'config_value' => '23:59'],
['config_key' => 'fall_semester_start', 'config_value' => '2025-09-01'],
['config_key' => 'spring_semester_start', 'config_value' => '2026-01-15'],
['config_key' => 'last_school_day', 'config_value' => '2026-06-15'],
]);
}
}
@@ -0,0 +1,74 @@
<?php
namespace Tests\Unit\Services\Parents;
use App\Models\User;
use App\Services\Parents\ParentAttendanceService;
use App\Services\Parents\ParentConfigService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ParentAttendanceServiceTest extends TestCase
{
use RefreshDatabase;
public function test_list_attendance_returns_rows(): 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'],
]);
$parentId = DB::table('users')->insertGetId([
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '1234567890',
'email' => 'parent2@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',
]);
$studentId = DB::table('students')->insertGetId([
'school_id' => 'S-101',
'firstname' => 'Maya',
'lastname' => 'Parent',
'dob' => '2014-09-01',
'age' => 11,
'gender' => 'Female',
'photo_consent' => 1,
'parent_id' => $parentId,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
DB::table('attendance_data')->insert([
'class_id' => 1,
'class_section_id' => 1,
'student_id' => $studentId,
'school_id' => '1',
'date' => '2025-10-02',
'status' => 'late',
'reason' => 'Traffic',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$service = new ParentAttendanceService(new ParentConfigService());
$result = $service->listAttendance($parentId, '2025-2026');
$this->assertSame('2025-2026', $result['selectedYear']);
$this->assertCount(1, $result['attendance']);
$this->assertSame('late', $result['attendance'][0]['status']);
}
}
@@ -0,0 +1,35 @@
<?php
namespace Tests\Unit\Services\Parents;
use App\Services\Parents\ParentConfigService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ParentConfigServiceTest extends TestCase
{
use RefreshDatabase;
public function test_context_returns_config_values(): 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' => 'max_kids', 'config_value' => '4'],
['config_key' => 'max_emergency', 'config_value' => '2'],
['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'],
]);
$service = new ParentConfigService();
$context = $service->context();
$this->assertSame('2025-2026', $context['school_year']);
$this->assertSame('Fall', $context['semester']);
$this->assertSame(4, $context['max_kids']);
$this->assertSame(2, $context['max_emergency']);
}
}
@@ -0,0 +1,60 @@
<?php
namespace Tests\Unit\Services\Parents;
use App\Services\Parents\ParentConfigService;
use App\Services\Parents\ParentEmergencyContactService;
use App\Services\PhoneFormatterService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ParentEmergencyContactServiceTest extends TestCase
{
use RefreshDatabase;
public function test_store_creates_contact(): void
{
$this->seedConfig();
$parentId = $this->seedParent();
$service = new ParentEmergencyContactService(new ParentConfigService(), new PhoneFormatterService());
$contact = $service->store($parentId, [
'name' => 'Sam Contact',
'cellphone' => '1234567890',
'email' => 'sam@example.com',
'relation' => 'Uncle',
]);
$this->assertSame('Sam Contact', $contact['emergency_contact_name']);
$this->assertDatabaseHas('emergency_contacts', ['parent_id' => $parentId, 'emergency_contact_name' => 'Sam Contact']);
}
private function seedParent(): int
{
return DB::table('users')->insertGetId([
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '1234567890',
'email' => 'parent5@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'],
]);
}
}
@@ -0,0 +1,84 @@
<?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']);
}
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'],
]);
}
}
@@ -0,0 +1,63 @@
<?php
namespace Tests\Unit\Services\Parents;
use App\Services\Parents\ParentInvoiceService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ParentInvoiceServiceTest extends TestCase
{
use RefreshDatabase;
public function test_list_invoices_filters_by_parent(): void
{
$parentId = $this->seedParent();
$otherParentId = $this->seedParent('other@example.com');
DB::table('invoices')->insert([
'parent_id' => $parentId,
'invoice_number' => 'INV-1',
'total_amount' => 100,
'paid_amount' => 0,
'balance' => 100,
'issue_date' => '2025-09-01',
]);
DB::table('invoices')->insert([
'parent_id' => $otherParentId,
'invoice_number' => 'INV-2',
'total_amount' => 50,
'paid_amount' => 0,
'balance' => 50,
'issue_date' => '2025-09-02',
]);
$service = new ParentInvoiceService();
$rows = $service->listInvoices($parentId);
$this->assertCount(1, $rows);
$this->assertSame('INV-1', $rows[0]['invoice_number']);
}
private function seedParent(string $email = 'parent@example.com'): int
{
return DB::table('users')->insertGetId([
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '1234567890',
'email' => $email,
'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',
]);
}
}
@@ -0,0 +1,78 @@
<?php
namespace Tests\Unit\Services\Parents;
use App\Services\Parents\ParentConfigService;
use App\Services\Parents\ParentRegistrationService;
use App\Services\SchoolIdService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ParentRegistrationServiceTest extends TestCase
{
use RefreshDatabase;
public function test_register_creates_student_and_contact(): void
{
$this->seedConfig();
$parentId = $this->seedParent();
$service = new ParentRegistrationService(new ParentConfigService(), new SchoolIdService());
$result = $service->register($parentId, [
[
'firstname' => 'Omar',
'lastname' => 'Parent',
'dob' => '2015-06-01',
'gender' => 'Male',
'registration_grade' => '3',
'photo_consent' => true,
'is_new' => true,
'allergies' => ['Eggs'],
'medical_conditions' => ['Asthma'],
],
], [
[
'name' => 'Nora Parent',
'cellphone' => '1234567890',
'email' => 'nora@example.com',
'relation' => 'Mother',
],
]);
$this->assertNotEmpty($result['created_student_ids']);
$this->assertDatabaseHas('students', ['firstname' => 'Omar', 'parent_id' => $parentId]);
$this->assertDatabaseHas('emergency_contacts', ['parent_id' => $parentId, 'emergency_contact_name' => 'Nora Parent']);
}
private function seedParent(): int
{
return DB::table('users')->insertGetId([
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '1234567890',
'email' => 'parent4@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' => 'max_kids', 'config_value' => '5'],
['config_key' => 'max_emergency', 'config_value' => '5'],
]);
}
}