96 lines
3.2 KiB
PHP
96 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\AttendanceTracking;
|
|
|
|
use App\Services\AttendanceParentLookupService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
class AttendanceParentLookupServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_get_primary_parent_for_student_returns_parent_info(): void
|
|
{
|
|
DB::table('users')->insert([
|
|
'id' => 100,
|
|
'firstname' => 'Jane',
|
|
'lastname' => 'Doe',
|
|
'email' => 'jane@example.com',
|
|
'cellphone' => '555-1111',
|
|
]);
|
|
|
|
DB::table('students')->insert([
|
|
'id' => 200,
|
|
'parent_id' => 100,
|
|
]);
|
|
|
|
$service = new AttendanceParentLookupService();
|
|
|
|
$result = $service->getPrimaryParentForStudent(200);
|
|
|
|
$this->assertNotNull($result);
|
|
$this->assertSame(100, $result['user_id']);
|
|
$this->assertSame('jane@example.com', $result['email']);
|
|
$this->assertSame('Jane Doe', $result['parent_name']);
|
|
}
|
|
|
|
public function test_get_secondary_parent_for_student_returns_secondary_user_when_present(): void
|
|
{
|
|
DB::table('users')->insert([
|
|
['id' => 100, 'firstname' => 'Jane', 'lastname' => 'Doe', 'email' => 'jane@example.com', 'cellphone' => '555-1111'],
|
|
['id' => 101, 'firstname' => 'John', 'lastname' => 'Doe', 'email' => 'john@example.com', 'cellphone' => '555-2222'],
|
|
]);
|
|
|
|
DB::table('students')->insert([
|
|
'id' => 200,
|
|
'parent_id' => 100,
|
|
'school_year' => '2025-2026',
|
|
]);
|
|
|
|
DB::table('parents')->insert([
|
|
'firstparent_id' => 100,
|
|
'secondparent_id' => 101,
|
|
'school_year' => '2025-2026',
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$service = new AttendanceParentLookupService();
|
|
|
|
$result = $service->getSecondaryParentForStudent(200, '2025-2026');
|
|
|
|
$this->assertNotNull($result);
|
|
$this->assertSame(101, $result['user_id']);
|
|
$this->assertSame('john@example.com', $result['email']);
|
|
}
|
|
|
|
public function test_parents_info_returns_primary_and_secondary_data(): void
|
|
{
|
|
DB::table('users')->insert([
|
|
['id' => 100, 'firstname' => 'Jane', 'lastname' => 'Doe', 'email' => 'jane@example.com', 'cellphone' => '555-1111'],
|
|
['id' => 101, 'firstname' => 'John', 'lastname' => 'Doe', 'email' => 'john@example.com', 'cellphone' => '555-2222'],
|
|
]);
|
|
|
|
DB::table('students')->insert([
|
|
'id' => 200,
|
|
'parent_id' => 100,
|
|
'school_year' => '2025-2026',
|
|
]);
|
|
|
|
DB::table('parents')->insert([
|
|
'firstparent_id' => 100,
|
|
'secondparent_id' => 101,
|
|
'school_year' => '2025-2026',
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$service = new AttendanceParentLookupService();
|
|
|
|
$result = $service->parentsInfo(200, '2025-2026');
|
|
|
|
$this->assertTrue($result['success']);
|
|
$this->assertSame('jane@example.com', $result['data']['primary']['email']);
|
|
$this->assertSame('john@example.com', $result['data']['secondary']['email']);
|
|
}
|
|
} |