304fa6bfd0
API CI/CD / Validate (composer + pint) (push) Successful in 3m5s
API CI/CD / Test (PHPUnit) (push) Failing after 7m12s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 49s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
130 lines
4.0 KiB
PHP
130 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\ClassProgress;
|
|
|
|
use App\Models\ClassProgressReport;
|
|
use App\Models\User;
|
|
use App\Services\ClassProgress\ClassProgressAttachmentService;
|
|
use App\Services\ClassProgress\ClassProgressMutationService;
|
|
use App\Services\ClassProgress\ClassProgressQueryService;
|
|
use App\Services\ClassProgress\ClassProgressRuleService;
|
|
use App\Services\SchoolYears\SchoolYearContextService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
class ClassProgressMutationServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_create_reports_persists_multiple_subjects(): void
|
|
{
|
|
$user = $this->createUser();
|
|
$this->seedClassSection();
|
|
$this->assignTeacher($user->id, 101);
|
|
|
|
$service = new ClassProgressMutationService(
|
|
new ClassProgressRuleService,
|
|
new ClassProgressAttachmentService,
|
|
app(ClassProgressQueryService::class),
|
|
app(SchoolYearContextService::class),
|
|
);
|
|
|
|
$payload = [
|
|
'class_section_id' => 101,
|
|
'week_start' => '2025-09-07',
|
|
'week_end' => '2025-09-13',
|
|
'covered_islamic' => 'Lesson A',
|
|
'covered_quran' => 'Lesson B',
|
|
];
|
|
|
|
$reports = $service->createReports($user, $payload, []);
|
|
|
|
$this->assertCount(2, $reports);
|
|
$this->assertDatabaseCount('class_progress_reports', 2);
|
|
}
|
|
|
|
public function test_update_report_changes_status(): void
|
|
{
|
|
$report = ClassProgressReport::factory()->create([
|
|
'status' => 'on_track',
|
|
]);
|
|
|
|
$service = new ClassProgressMutationService(
|
|
new ClassProgressRuleService,
|
|
new ClassProgressAttachmentService,
|
|
app(ClassProgressQueryService::class),
|
|
app(SchoolYearContextService::class),
|
|
);
|
|
|
|
$updated = $service->updateReport($report, ['status' => 'behind'], []);
|
|
|
|
$this->assertSame('behind', $updated->status);
|
|
}
|
|
|
|
public function test_delete_report_removes_record(): void
|
|
{
|
|
$report = ClassProgressReport::factory()->create();
|
|
$service = new ClassProgressMutationService(
|
|
new ClassProgressRuleService,
|
|
new ClassProgressAttachmentService,
|
|
app(ClassProgressQueryService::class),
|
|
app(SchoolYearContextService::class),
|
|
);
|
|
|
|
$service->deleteReport($report);
|
|
|
|
$this->assertDatabaseMissing('class_progress_reports', ['id' => $report->id]);
|
|
}
|
|
|
|
private function seedClassSection(): void
|
|
{
|
|
DB::table('classSection')->insert([
|
|
'id' => 1,
|
|
'class_id' => 1,
|
|
'class_section_id' => 101,
|
|
'class_section_name' => '1-A',
|
|
'semester' => 'Fall',
|
|
'school_year' => '2025-2026',
|
|
]);
|
|
}
|
|
|
|
private function assignTeacher(int $teacherId, int $classSectionId): void
|
|
{
|
|
DB::table('teacher_class')->insert([
|
|
'class_section_id' => $classSectionId,
|
|
'teacher_id' => $teacherId,
|
|
'position' => 'main',
|
|
'semester' => 'Fall',
|
|
'school_year' => '2025-2026',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|