fix parent, teacher and admin pages

This commit is contained in:
root
2026-04-25 00:00:23 -04:00
parent 4cd98f1d30
commit eafe4eb134
30 changed files with 1566 additions and 105 deletions
@@ -2,6 +2,7 @@
namespace Tests\Unit;
use App\Models\User;
use App\Services\Auth\ApiLoginSecurityService;
use PHPUnit\Framework\TestCase;
@@ -20,4 +21,58 @@ class ApiLoginSecurityServiceTest extends TestCase
$this->assertStringContainsString('"Teacher":true', $payload);
$this->assertStringContainsString('"Admin":true', $payload);
}
public function test_build_login_response_includes_teacher_class_context(): void
{
$service = new ApiLoginSecurityService();
$user = $this->getMockBuilder(User::class)
->onlyMethods(['roleNamesLikeCodeIgniter', 'teacherSessionContext'])
->getMock();
$user->id = 99;
$user->firstname = 'Amina';
$user->lastname = 'Teacher';
$user->method('roleNamesLikeCodeIgniter')->willReturn(['Teacher']);
$user->method('teacherSessionContext')->willReturn([
'class_section_id' => 42,
'class_section_name' => 'Grade 5 - A',
]);
$payload = $service->buildLoginResponse($user, 'jwt-token');
$this->assertTrue($payload['status']);
$this->assertSame('jwt-token', $payload['token']);
$this->assertSame(99, $payload['user']['id']);
$this->assertSame('Amina Teacher', $payload['user']['name']);
$this->assertSame(42, $payload['user']['class_section_id']);
$this->assertSame('Grade 5 - A', $payload['user']['class_section_name']);
$this->assertTrue($payload['user']['roles']->Teacher);
}
public function test_build_login_response_includes_teacher_assistant_class_context(): void
{
$service = new ApiLoginSecurityService();
$user = $this->getMockBuilder(User::class)
->onlyMethods(['roleNamesLikeCodeIgniter', 'teacherSessionContext'])
->getMock();
$user->id = 100;
$user->firstname = 'Samir';
$user->lastname = 'TA';
$user->method('roleNamesLikeCodeIgniter')->willReturn(['Teacher_Assistant']);
$user->method('teacherSessionContext')->willReturn([
'class_section_id' => 17,
'class_section_name' => 'Grade 3 - B',
]);
$payload = $service->buildLoginResponse($user, 'jwt-token');
$this->assertSame(17, $payload['user']['class_section_id']);
$this->assertSame('Grade 3 - B', $payload['user']['class_section_name']);
$this->assertTrue($payload['user']['roles']->Teacher_Assistant);
}
}
@@ -14,6 +14,7 @@ class SchoolCalendarEventResourceTest extends TestCase
'title' => 'Event',
'start' => '2026-01-01',
'description' => 'Desc',
'backgroundColor' => '#28a745',
'extendedProps' => ['no_school' => 0],
]);
@@ -23,6 +24,8 @@ class SchoolCalendarEventResourceTest extends TestCase
$this->assertArrayHasKey('title', $payload);
$this->assertArrayHasKey('start', $payload);
$this->assertArrayHasKey('description', $payload);
$this->assertArrayHasKey('backgroundColor', $payload);
$this->assertArrayHasKey('extendedProps', $payload);
$this->assertSame('#28a745', $payload['backgroundColor']);
}
}
@@ -20,7 +20,24 @@ class SchoolCalendarFormatterServiceTest extends TestCase
'notify_admin' => 0,
], 'parent');
$this->assertSame('#ffc107', $formatted['backgroundColor']);
$this->assertSame('#ffc107', $formatted['extendedProps']['backgroundColor']);
$this->assertSame('No School Day', $formatted['title']);
}
public function test_format_event_normalizes_iso_dates_to_plain_calendar_date(): void
{
$service = new SchoolCalendarFormatterService();
$formatted = $service->formatEvent([
'id' => 2,
'title' => 'First Day of School',
'date' => '2025-09-21T00:00:00.000000Z',
'no_school' => 0,
'notify_parent' => 0,
'notify_teacher' => 0,
'notify_admin' => 0,
], 'teacher');
$this->assertSame('2025-09-21', $formatted['start']);
}
}
@@ -24,6 +24,7 @@ class TeacherDashboardServiceTest extends TestCase
$data = $service->classView($teacherId, $classSectionId);
$this->assertSame($classSectionId, $data['active_class_section_id']);
$this->assertSame('1A', $data['class_section_name']);
$this->assertNotEmpty($data['classes']);
$this->assertNotEmpty($data['students']);
}