add controllers, servoices
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Tests\Unit\Services\AttendanceTracking;
|
||||
|
||||
use App\Services\AttendanceParentLookupService;
|
||||
use App\Services\AttendanceTracking\AttendanceParentLookupService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
@@ -11,86 +11,78 @@ class AttendanceParentLookupServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_get_primary_parent_for_student_returns_parent_info(): void
|
||||
public function test_get_primary_parent_for_student(): void
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 100,
|
||||
'firstname' => 'Jane',
|
||||
'lastname' => 'Doe',
|
||||
'email' => 'jane@example.com',
|
||||
'cellphone' => '555-1111',
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'One',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 200,
|
||||
'parent_id' => 100,
|
||||
'id' => 1,
|
||||
'school_id' => 'S1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new AttendanceParentLookupService();
|
||||
$parent = $service->getPrimaryParentForStudent(1);
|
||||
|
||||
$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']);
|
||||
$this->assertSame('parent@example.com', $parent['email']);
|
||||
}
|
||||
|
||||
public function test_get_secondary_parent_for_student_returns_secondary_user_when_present(): void
|
||||
public function test_get_secondary_parent_falls_back_to_parent_row(): 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,
|
||||
'id' => 1,
|
||||
'school_id' => 'S1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 11,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('parents')->insert([
|
||||
'firstparent_id' => 100,
|
||||
'secondparent_id' => 101,
|
||||
'secondparent_firstname' => 'Second',
|
||||
'secondparent_lastname' => 'Parent',
|
||||
'secondparent_gender' => 'Female',
|
||||
'secondparent_email' => 'second@example.com',
|
||||
'secondparent_phone' => '5551112222',
|
||||
'firstparent_id' => 11,
|
||||
'secondparent_id' => 0,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$service = new AttendanceParentLookupService();
|
||||
$parent = $service->getSecondaryParentForStudent(1, '2025-2026');
|
||||
|
||||
$result = $service->getSecondaryParentForStudent(200, '2025-2026');
|
||||
|
||||
$this->assertNotNull($result);
|
||||
$this->assertSame(101, $result['user_id']);
|
||||
$this->assertSame('john@example.com', $result['email']);
|
||||
$this->assertSame('second@example.com', $parent['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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user