Files
alrahma_sunday_school_api/tests/Unit/Services/ClassProgress/ClassProgressQueryServiceTest.php
T
root 02ba2fe6b6
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
fix parent pages and teachers and admin
2026-07-09 13:56:22 -04:00

149 lines
4.9 KiB
PHP

<?php
namespace Tests\Unit\Services\ClassProgress;
use App\Models\ClassProgressReport;
use App\Models\User;
use App\Services\ClassProgress\ClassProgressQueryService;
use App\Services\ClassProgress\ClassProgressRuleService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ClassProgressQueryServiceTest extends TestCase
{
use RefreshDatabase;
public function test_list_reports_filters_by_class_section(): void
{
$user = $this->createUser();
ClassProgressReport::factory()->create([
'teacher_id' => $user->id,
'class_section_id' => 101,
]);
ClassProgressReport::factory()->create([
'teacher_id' => $user->id,
'class_section_id' => 202,
]);
DB::table('classSection')->insert([
'id' => 1,
'class_id' => 1,
'class_section_id' => 101,
'class_section_name' => '1-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('teacher_class')->insert([
'class_section_id' => 1,
'teacher_id' => $user->id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
]);
$service = new ClassProgressQueryService(new ClassProgressRuleService);
$results = $service->listReports($user, ['class_section_id' => 101]);
$this->assertSame(1, $results->total());
}
public function test_list_reports_filters_by_equivalent_legacy_section_ids(): void
{
$user = $this->createUser();
DB::table('classSection')->insert([
'id' => 1,
'class_id' => 1,
'class_section_id' => 101,
'class_section_name' => '1-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('teacher_class')->insert([
'class_section_id' => 101,
'teacher_id' => $user->id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
]);
$report = ClassProgressReport::factory()->create([
'teacher_id' => 999,
'class_section_id' => 1,
'school_year' => '2025-2026',
]);
$service = new ClassProgressQueryService(new ClassProgressRuleService);
$results = $service->listReports($user, ['class_section_id' => 101]);
$this->assertSame(1, $results->total());
$this->assertSame($report->id, $results->items()[0]->id);
}
public function test_teacher_assignments_prefer_section_code_over_colliding_primary_key(): void
{
$user = $this->createUser();
DB::table('classSection')->insert([
[
'id' => 1,
'class_id' => 1,
'class_section_id' => 10,
'class_section_name' => '1',
'semester' => 'Fall',
'school_year' => '2025-2026',
],
[
'id' => 10,
'class_id' => 3,
'class_section_id' => 31,
'class_section_name' => '3-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
DB::table('teacher_class')->insert([
'class_section_id' => 10,
'teacher_id' => $user->id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
]);
$service = new ClassProgressQueryService(new ClassProgressRuleService);
$assignments = $service->teacherAssignments($user, '2025-2026', 'Fall');
$this->assertCount(1, $assignments);
$this->assertSame(10, $assignments[0]['class_section_id']);
$this->assertSame('1', $assignments[0]['class_section_name']);
}
private function createUser(): User
{
DB::table('users')->insert([
'school_id' => 1,
'firstname' => 'Teacher',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'teacher@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
return User::query()->where('email', 'teacher@example.com')->firstOrFail();
}
}