add school calendar logic
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Resources\Settings;
|
||||
|
||||
use App\Http\Resources\Settings\SchoolCalendarEventResource;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchoolCalendarEventResourceTest extends TestCase
|
||||
{
|
||||
public function test_resource_returns_expected_shape(): void
|
||||
{
|
||||
$resource = new SchoolCalendarEventResource([
|
||||
'id' => 1,
|
||||
'title' => 'Event',
|
||||
'start' => '2026-01-01',
|
||||
'description' => 'Desc',
|
||||
'extendedProps' => ['no_school' => 0],
|
||||
]);
|
||||
|
||||
$payload = $resource->toArray(request());
|
||||
|
||||
$this->assertArrayHasKey('id', $payload);
|
||||
$this->assertArrayHasKey('title', $payload);
|
||||
$this->assertArrayHasKey('start', $payload);
|
||||
$this->assertArrayHasKey('description', $payload);
|
||||
$this->assertArrayHasKey('extendedProps', $payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Settings\SchoolCalendar;
|
||||
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarContextService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchoolCalendarContextServiceTest extends TestCase
|
||||
{
|
||||
public function test_event_types_returns_list(): void
|
||||
{
|
||||
$service = new SchoolCalendarContextService();
|
||||
$types = $service->eventTypes();
|
||||
|
||||
$this->assertNotEmpty($types);
|
||||
$this->assertContains('Event', $types);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Settings\SchoolCalendar;
|
||||
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarFormatterService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchoolCalendarFormatterServiceTest extends TestCase
|
||||
{
|
||||
public function test_format_event_sets_background_for_no_school(): void
|
||||
{
|
||||
$service = new SchoolCalendarFormatterService();
|
||||
$formatted = $service->formatEvent([
|
||||
'id' => 1,
|
||||
'title' => 'No School Day',
|
||||
'date' => '2026-01-01',
|
||||
'no_school' => 1,
|
||||
'notify_parent' => 0,
|
||||
'notify_teacher' => 0,
|
||||
'notify_admin' => 0,
|
||||
], 'parent');
|
||||
|
||||
$this->assertSame('#ffc107', $formatted['extendedProps']['backgroundColor']);
|
||||
$this->assertSame('No School Day', $formatted['title']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Settings\SchoolCalendar;
|
||||
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarMeetingService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchoolCalendarMeetingServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_meetings_filters_for_parent(): void
|
||||
{
|
||||
DB::table('parent_meeting_schedules')->insert([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'parent_user_id' => 10,
|
||||
'parent_name' => 'Parent',
|
||||
'student_name' => 'Student',
|
||||
'class_section_name' => 'Grade 1',
|
||||
'date' => '2026-01-02',
|
||||
'time' => '10:00:00',
|
||||
'notes' => 'Notes',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'scheduled',
|
||||
'created_by' => null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'student_id' => 2,
|
||||
'parent_user_id' => 11,
|
||||
'parent_name' => 'Other Parent',
|
||||
'student_name' => 'Other Student',
|
||||
'class_section_name' => 'Grade 2',
|
||||
'date' => '2026-01-03',
|
||||
'time' => '11:00:00',
|
||||
'notes' => 'Notes',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'scheduled',
|
||||
'created_by' => null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
|
||||
$service = new SchoolCalendarMeetingService();
|
||||
$rows = $service->listMeetings('2025-2026', 'parent', 10);
|
||||
|
||||
$this->assertCount(1, $rows);
|
||||
$this->assertSame(10, $rows[0]['parent_user_id']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Settings\SchoolCalendar;
|
||||
|
||||
use App\Models\CalendarEvent;
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarContextService;
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarMutationService;
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarNotificationService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchoolCalendarMutationServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_persists_event(): void
|
||||
{
|
||||
$context = new SchoolCalendarContextService();
|
||||
$notifier = Mockery::mock(SchoolCalendarNotificationService::class);
|
||||
$notifier->shouldReceive('notify')->andReturn([]);
|
||||
|
||||
$service = new SchoolCalendarMutationService($context, $notifier);
|
||||
$result = $service->create([
|
||||
'title' => 'New Event',
|
||||
'date' => '2026-01-05',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
], []);
|
||||
|
||||
$this->assertInstanceOf(CalendarEvent::class, $result['event']);
|
||||
$this->assertDatabaseHas('calendar_events', ['title' => 'New Event']);
|
||||
}
|
||||
|
||||
public function test_update_persists_changes(): void
|
||||
{
|
||||
$event = CalendarEvent::query()->create([
|
||||
'title' => 'Old Event',
|
||||
'date' => '2026-01-01',
|
||||
'description' => '',
|
||||
'notify_parent' => 0,
|
||||
'notify_admin' => 0,
|
||||
'notify_teacher' => 0,
|
||||
'no_school' => 0,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'notification_sent' => 0,
|
||||
]);
|
||||
|
||||
$context = new SchoolCalendarContextService();
|
||||
$notifier = Mockery::mock(SchoolCalendarNotificationService::class);
|
||||
$notifier->shouldReceive('notify')->andReturn([]);
|
||||
|
||||
$service = new SchoolCalendarMutationService($context, $notifier);
|
||||
$service->update($event, ['title' => 'Updated Event'], []);
|
||||
|
||||
$this->assertDatabaseHas('calendar_events', [
|
||||
'id' => $event->id,
|
||||
'title' => 'Updated Event',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Settings\SchoolCalendar;
|
||||
|
||||
use App\Services\EmailService;
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarNotificationService;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchoolCalendarNotificationServiceTest extends TestCase
|
||||
{
|
||||
public function test_notify_returns_empty_when_no_targets(): void
|
||||
{
|
||||
$emailService = Mockery::mock(EmailService::class);
|
||||
$service = new SchoolCalendarNotificationService($emailService);
|
||||
|
||||
$result = $service->notify(['title' => 'Event'], []);
|
||||
|
||||
$this->assertSame([], $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Settings\SchoolCalendar;
|
||||
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarQueryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchoolCalendarQueryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_events_filters_by_school_year(): void
|
||||
{
|
||||
DB::table('calendar_events')->insert([
|
||||
[
|
||||
'title' => 'Event A',
|
||||
'date' => '2026-01-01',
|
||||
'description' => '',
|
||||
'notify_parent' => 1,
|
||||
'notify_admin' => 0,
|
||||
'notify_teacher' => 0,
|
||||
'no_school' => 0,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'notification_sent' => 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'title' => 'Event B',
|
||||
'date' => '2026-01-02',
|
||||
'description' => '',
|
||||
'notify_parent' => 1,
|
||||
'notify_admin' => 0,
|
||||
'notify_teacher' => 0,
|
||||
'no_school' => 0,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2026-2027',
|
||||
'notification_sent' => 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
|
||||
$service = new SchoolCalendarQueryService();
|
||||
$events = $service->listEvents(['school_year' => '2025-2026']);
|
||||
|
||||
$this->assertCount(1, $events);
|
||||
$this->assertSame('Event A', $events->first()->title);
|
||||
}
|
||||
|
||||
public function test_filter_events_for_audience_limits_visibility(): void
|
||||
{
|
||||
DB::table('calendar_events')->insert([
|
||||
[
|
||||
'title' => 'Parent Event',
|
||||
'date' => '2026-01-01',
|
||||
'description' => '',
|
||||
'notify_parent' => 1,
|
||||
'notify_admin' => 0,
|
||||
'notify_teacher' => 0,
|
||||
'no_school' => 0,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'notification_sent' => 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'title' => 'Teacher Event',
|
||||
'date' => '2026-01-02',
|
||||
'description' => '',
|
||||
'notify_parent' => 0,
|
||||
'notify_admin' => 0,
|
||||
'notify_teacher' => 1,
|
||||
'no_school' => 0,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'notification_sent' => 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
|
||||
$service = new SchoolCalendarQueryService();
|
||||
$events = $service->listEvents(['school_year' => '2025-2026']);
|
||||
$filtered = $service->filterEventsForAudience($events, 'parent');
|
||||
|
||||
$this->assertCount(1, $filtered);
|
||||
$this->assertSame('Parent Event', $filtered->first()->title);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user