add controllers, servoices
This commit is contained in:
+40
-50
@@ -2,72 +2,62 @@
|
||||
|
||||
namespace Tests\Unit\Services\AttendanceTracking;
|
||||
|
||||
use App\Models\AttendanceData;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\Student;
|
||||
use App\Services\AttendanceCommunicationSupportService;
|
||||
use App\Services\AttendanceEmailComposerService;
|
||||
use App\Services\AttendanceParentLookupService;
|
||||
use App\Services\AttendanceTracking\AttendanceCommunicationSupportService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AttendanceCommunicationSupportServiceTest extends TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
parent::tearDown();
|
||||
}
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function makeService(
|
||||
?Student $student = null,
|
||||
?AttendanceData $attendanceData = null,
|
||||
?Configuration $config = null,
|
||||
?AttendanceParentLookupService $parents = null,
|
||||
?AttendanceEmailComposerService $composer = null
|
||||
): AttendanceCommunicationSupportService {
|
||||
$student ??= Mockery::mock(Student::class);
|
||||
$attendanceData ??= Mockery::mock(AttendanceData::class);
|
||||
$config ??= Mockery::mock(Configuration::class);
|
||||
$parents ??= Mockery::mock(AttendanceParentLookupService::class);
|
||||
$composer ??= Mockery::mock(AttendanceEmailComposerService::class);
|
||||
|
||||
$config->shouldReceive('getConfig')->with('semester')->andReturn('Fall');
|
||||
$config->shouldReceive('getConfig')->with('school_year')->andReturn('2025-2026');
|
||||
|
||||
return new AttendanceCommunicationSupportService(
|
||||
$student,
|
||||
$attendanceData,
|
||||
$config,
|
||||
$parents,
|
||||
$composer
|
||||
);
|
||||
}
|
||||
|
||||
public function test_compose_returns_422_when_student_id_missing(): void
|
||||
public function test_compose_requires_student_id(): void
|
||||
{
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->compose(0);
|
||||
|
||||
$this->assertFalse($result['success']);
|
||||
$this->assertSame(422, $result['status']);
|
||||
}
|
||||
|
||||
public function test_parents_info_delegates_to_parent_lookup_service(): void
|
||||
public function test_get_violation_dates_for_student(): void
|
||||
{
|
||||
$parents = Mockery::mock(AttendanceParentLookupService::class);
|
||||
$parents->shouldReceive('parentsInfo')
|
||||
->once()
|
||||
->with(20, '2025-2026')
|
||||
->andReturn(['success' => true, 'data' => ['primary' => [], 'secondary' => []]]);
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
]);
|
||||
|
||||
$service = $this->makeService(
|
||||
parents: $parents
|
||||
);
|
||||
DB::table('attendance_data')->insert([
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 1,
|
||||
'student_id' => 1,
|
||||
'school_id' => 'S1',
|
||||
'date' => '2025-01-01',
|
||||
'status' => 'absent',
|
||||
'is_reported' => 'no',
|
||||
'is_notified' => 'no',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$result = $service->parentsInfo(20);
|
||||
$service = $this->makeService();
|
||||
$dates = $service->getViolationDatesForStudent(1, 'ABS_1');
|
||||
|
||||
$this->assertTrue($result['success']);
|
||||
$this->assertSame(['2025-01-01'], $dates);
|
||||
}
|
||||
}
|
||||
|
||||
private function makeService(): AttendanceCommunicationSupportService
|
||||
{
|
||||
$parentLookup = Mockery::mock(\App\Services\AttendanceTracking\AttendanceParentLookupService::class);
|
||||
$emailComposer = Mockery::mock(\App\Services\AttendanceTracking\AttendanceEmailComposerService::class);
|
||||
|
||||
return new AttendanceCommunicationSupportService(
|
||||
new \App\Models\Student(),
|
||||
new \App\Models\AttendanceData(),
|
||||
new \App\Models\Configuration(),
|
||||
$parentLookup,
|
||||
$emailComposer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user