add controllers, servoices

This commit is contained in:
root
2026-03-09 02:52:13 -04:00
parent c8de5f7edc
commit d76c871cb7
501 changed files with 34439 additions and 21843 deletions
@@ -2,114 +2,50 @@
namespace Tests\Unit\Services\AttendanceTracking;
use App\Models\AttendanceData;
use App\Models\AttendanceTracking;
use App\Models\Configuration;
use App\Models\Student;
use App\Models\StudentClass;
use App\Services\AttendanceEmailComposerService;
use App\Services\AttendanceMailerService;
use App\Services\AttendanceNotificationLogService;
use App\Services\AttendanceNotificationWorkflowService;
use App\Services\AttendanceParentLookupService;
use App\Services\ViolationRuleEngineService;
use App\Services\AttendanceTracking\AttendanceNotificationWorkflowService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Mockery;
use Tests\TestCase;
class AttendanceNotificationWorkflowServiceTest extends TestCase
{
protected function tearDown(): void
use RefreshDatabase;
public function test_record_requires_parent_email(): void
{
Mockery::close();
parent::tearDown();
}
protected function makeService(
?Student $student = null,
?StudentClass $studentClass = null,
?AttendanceData $attendanceData = null,
?AttendanceTracking $tracking = null,
?Configuration $config = null,
?AttendanceMailerService $mailer = null,
?ViolationRuleEngineService $rules = null,
?AttendanceParentLookupService $parents = null,
?AttendanceEmailComposerService $composer = null,
?AttendanceNotificationLogService $log = null
): AttendanceNotificationWorkflowService {
$student ??= Mockery::mock(Student::class);
$studentClass ??= Mockery::mock(StudentClass::class);
$attendanceData ??= Mockery::mock(AttendanceData::class);
$tracking ??= Mockery::mock(AttendanceTracking::class);
$config ??= Mockery::mock(Configuration::class);
$mailer ??= Mockery::mock(AttendanceMailerService::class);
$rules ??= Mockery::mock(ViolationRuleEngineService::class);
$parents ??= Mockery::mock(AttendanceParentLookupService::class);
$composer ??= Mockery::mock(AttendanceEmailComposerService::class);
$log ??= Mockery::mock(AttendanceNotificationLogService::class);
$config->shouldReceive('getConfig')->with('semester')->andReturn('Fall');
$config->shouldReceive('getConfig')->with('school_year')->andReturn('2025-2026');
return new AttendanceNotificationWorkflowService(
$student,
$studentClass,
$attendanceData,
$tracking,
$config,
$mailer,
$rules,
$parents,
$composer,
$log
);
}
public function test_send_auto_emails_returns_empty_summary_when_no_auto_email_violations(): void
{
$service = $this->makeService();
$result = $service->sendAutoEmails([
['action' => 'team_notify'],
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',
]);
$this->assertTrue($result['success']);
$this->assertSame(0, $result['sent']);
$this->assertSame(0, $result['skipped']);
$this->assertSame(0, $result['errors']);
}
public function test_send_email_manual_returns_failure_when_all_sends_fail(): void
{
$mailer = Mockery::mock(AttendanceMailerService::class);
$mailer->shouldReceive('send')->andReturn(false);
$parents = Mockery::mock(AttendanceParentLookupService::class);
$parents->shouldReceive('getSecondaryParentForStudent')->andReturn(null);
$composer = Mockery::mock(AttendanceEmailComposerService::class);
$composer->shouldReceive('normalizeBodyToHtml')->andReturn('<p>Hello</p>');
$composer->shouldReceive('renderWithEmailLayout')->andReturn('<html>Hello</html>');
$log = Mockery::mock(AttendanceNotificationLogService::class);
$log->shouldReceive('logNotification')->atLeast()->once();
$service = $this->makeService(
mailer: $mailer,
parents: $parents,
composer: $composer,
log: $log
$service = new AttendanceNotificationWorkflowService(
new \App\Models\Student(),
new \App\Models\StudentClass(),
new \App\Models\AttendanceData(),
new \App\Models\AttendanceTracking(),
new \App\Models\Configuration(),
Mockery::mock(\App\Services\AttendanceTracking\AttendanceMailerService::class),
Mockery::mock(\App\Services\AttendanceTracking\ViolationRuleEngineService::class),
Mockery::mock(\App\Services\AttendanceTracking\AttendanceParentLookupService::class),
Mockery::mock(\App\Services\AttendanceTracking\AttendanceEmailComposerService::class),
Mockery::mock(\App\Services\AttendanceTracking\AttendanceNotificationLogService::class)
);
$result = $service->sendEmailManual([
'student_id' => 10,
'to' => 'parent@example.com',
'subject' => 'Test',
'body_html' => 'Hello',
'code' => 'ABS_1',
'incident_date' => '2026-03-01',
], ['2026-03-01']);
$result = $service->record([
'student_id' => 1,
'date' => '2025-01-01',
]);
$this->assertFalse($result['success']);
$this->assertSame(500, $result['status']);
$this->assertSame(422, $result['status']);
}
}
}