add controllers, servoices
This commit is contained in:
+33
-54
@@ -2,67 +2,46 @@
|
||||
|
||||
namespace Tests\Unit\Services\AttendanceTracking;
|
||||
|
||||
use App\Models\AttendanceData;
|
||||
use App\Models\Student;
|
||||
use App\Models\StudentClass;
|
||||
use App\Services\AttendanceViolationStudentResolverService;
|
||||
use Mockery;
|
||||
use App\Services\AttendanceTracking\AttendanceViolationStudentResolverService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AttendanceViolationStudentResolverServiceTest extends TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_resolve_for_school_year_returns_students(): void
|
||||
{
|
||||
Mockery::close();
|
||||
parent::tearDown();
|
||||
}
|
||||
DB::table('students')->insert([
|
||||
'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',
|
||||
]);
|
||||
|
||||
public function test_ensure_attendance_student_exists_keeps_numeric_student(): void
|
||||
{
|
||||
$student = Mockery::mock(Student::class);
|
||||
$studentClass = Mockery::mock(StudentClass::class);
|
||||
$attendanceData = Mockery::mock(AttendanceData::class);
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 10,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new AttendanceViolationStudentResolverService($student, $studentClass, $attendanceData);
|
||||
|
||||
$students = [];
|
||||
$studentCodeToId = [];
|
||||
$existingIds = [];
|
||||
|
||||
$sid = $service->ensureAttendanceStudentExists(
|
||||
$students,
|
||||
$studentCodeToId,
|
||||
$existingIds,
|
||||
123
|
||||
$service = new AttendanceViolationStudentResolverService(
|
||||
new \App\Models\Student(),
|
||||
new \App\Models\StudentClass(),
|
||||
new \App\Models\AttendanceData()
|
||||
);
|
||||
|
||||
$this->assertSame(123, $sid);
|
||||
$this->assertCount(1, $students);
|
||||
$this->assertSame(123, $students[0]['id']);
|
||||
$result = $service->resolveForSchoolYear('2025-2026', 'Fall');
|
||||
|
||||
$this->assertContains(1, $result['student_ids']);
|
||||
$this->assertNotEmpty($result['students']);
|
||||
}
|
||||
|
||||
public function test_ensure_attendance_student_exists_creates_placeholder_for_code(): void
|
||||
{
|
||||
$student = Mockery::mock(Student::class);
|
||||
$studentClass = Mockery::mock(StudentClass::class);
|
||||
$attendanceData = Mockery::mock(AttendanceData::class);
|
||||
|
||||
$service = new AttendanceViolationStudentResolverService($student, $studentClass, $attendanceData);
|
||||
|
||||
$students = [];
|
||||
$studentCodeToId = [];
|
||||
$existingIds = [];
|
||||
|
||||
$sid = $service->ensureAttendanceStudentExists(
|
||||
$students,
|
||||
$studentCodeToId,
|
||||
$existingIds,
|
||||
'SCH-001'
|
||||
);
|
||||
|
||||
$this->assertNotNull($sid);
|
||||
$this->assertCount(1, $students);
|
||||
$this->assertSame('SCH-001', $students[0]['school_id']);
|
||||
$this->assertArrayHasKey('SCH-001', $studentCodeToId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user