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,124 +2,37 @@
namespace Tests\Unit\Services\AttendanceTracking;
use App\Models\AttendanceEmailTemplate;
use App\Services\AttendanceEmailComposerService;
use Mockery;
use App\Services\AttendanceTracking\AttendanceEmailComposerService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class AttendanceEmailComposerServiceTest extends TestCase
{
protected function tearDown(): void
use RefreshDatabase;
public function test_render_template_replaces_tokens(): void
{
Mockery::close();
parent::tearDown();
}
public function test_build_template_context_returns_expected_placeholders(): void
{
$model = Mockery::mock(AttendanceEmailTemplate::class);
$service = new AttendanceEmailComposerService($model);
$context = $service->buildTemplateContext(
[
'name' => 'John Doe',
'last_date' => '2026-03-01',
],
[
'parent_name' => 'Jane Doe',
'phone' => '555-1212',
]
);
$this->assertSame('Jane Doe', $context['{{parent_name}}']);
$this->assertSame('John Doe', $context['{{student_name}}']);
$this->assertSame('2026-03-01', $context['{{incident_date}}']);
$this->assertSame('555-1212', $context['{{voicemail_phone}}']);
}
public function test_render_template_uses_model_get_template(): void
{
$model = Mockery::mock(AttendanceEmailTemplate::class);
$model->shouldReceive('getTemplate')
->once()
->with('ABS_1', 'default')
->andReturn([
'subject' => 'Notice for {{student_name}}',
'body_html' => '<p>Date: {{incident_date}}</p>',
]);
$service = new AttendanceEmailComposerService($model);
$rendered = $service->renderTemplate('ABS_1', 'default', [
'{{student_name}}' => 'John Doe',
'{{incident_date}}' => '2026-03-01',
DB::table('email_templates')->insert([
'code' => 'ABS_1',
'variant' => 'default',
'subject' => 'Notice for {{student_name}}',
'body_html' => '<p>{{parent_name}}</p>',
'is_active' => 1,
]);
$this->assertSame(
['Notice for John Doe', '<p>Date: 2026-03-01</p>'],
$rendered
);
$service = new AttendanceEmailComposerService(new \App\Models\AttendanceEmailTemplate());
$context = ['{{student_name}}' => 'Student A', '{{parent_name}}' => 'Parent A'];
$rendered = $service->renderTemplate('ABS_1', 'default', $context);
$this->assertSame('Notice for Student A', $rendered[0]);
$this->assertSame('<p>Parent A</p>', $rendered[1]);
}
public function test_pick_variant_returns_override_when_present(): void
public function test_pick_variant_fallback(): void
{
$model = Mockery::mock(AttendanceEmailTemplate::class);
$service = new AttendanceEmailComposerService($model);
$this->assertSame('custom_variant', $service->pickVariant('ABS_2', 'custom_variant'));
}
public function test_pick_variant_returns_no_answer_for_abs_2(): void
{
$model = Mockery::mock(AttendanceEmailTemplate::class);
$service = new AttendanceEmailComposerService($model);
$service = new AttendanceEmailComposerService(new \App\Models\AttendanceEmailTemplate());
$this->assertSame('no_answer', $service->pickVariant('ABS_2'));
}
public function test_pick_variant_returns_default_for_other_codes(): void
{
$model = Mockery::mock(AttendanceEmailTemplate::class);
$service = new AttendanceEmailComposerService($model);
$this->assertSame('default', $service->pickVariant('ABS_1'));
}
public function test_normalize_body_to_html_keeps_html_when_tags_present(): void
{
$model = Mockery::mock(AttendanceEmailTemplate::class);
$service = new AttendanceEmailComposerService($model);
$body = '<p>Hello</p>';
$this->assertSame($body, $service->normalizeBodyToHtml($body));
}
public function test_normalize_body_to_html_converts_plain_text_to_br_html(): void
{
$model = Mockery::mock(AttendanceEmailTemplate::class);
$service = new AttendanceEmailComposerService($model);
$result = $service->normalizeBodyToHtml("Hello\nWorld");
$this->assertStringContainsString('Hello', $result);
$this->assertStringContainsString('<br', $result);
$this->assertStringContainsString('World', $result);
}
public function test_build_fallback_auto_email_returns_subject_and_body(): void
{
$model = Mockery::mock(AttendanceEmailTemplate::class);
$service = new AttendanceEmailComposerService($model);
[$subject, $body] = $service->buildFallbackAutoEmail('ABS_1', [
'name' => 'John Doe',
'violation' => '1 Unreported Absence',
'last_date' => '2026-03-01',
], 'Jane Doe');
$this->assertSame('Attendance Notice: Unreported Absence', $subject);
$this->assertStringContainsString('John Doe', $body);
$this->assertStringContainsString('2026-03-01', $body);
$this->assertStringContainsString('Jane Doe', $body);
}
}
}