Files
root 3fde161f29
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 6m55s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 50s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
fix failed tests
2026-07-07 04:12:02 -04:00

112 lines
3.4 KiB
PHP

<?php
namespace Tests\Unit\Services\Teachers;
use App\Services\ApplicationUrlService;
use App\Services\SemesterRangeService;
use App\Services\Semesters\SemesterConfigService;
use App\Services\Staff\StaffTimeOffLinkService;
use App\Services\Teachers\TeacherAbsenceService;
use App\Services\Teachers\TeacherConfigService;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class TeacherAbsenceServiceTest extends TestCase
{
use RefreshDatabase;
public function test_form_data_returns_available_dates(): void
{
Carbon::setTestNow(Carbon::parse('2025-10-01'));
$this->seedConfig();
$teacherId = $this->seedTeacherUser();
$service = new TeacherAbsenceService(
new TeacherConfigService,
new SemesterRangeService(new SemesterConfigService),
new StaffTimeOffLinkService,
new ApplicationUrlService
);
$data = $service->formData($teacherId);
$this->assertSame('Fall', $data['semester']);
$this->assertNotEmpty($data['available_dates']);
Carbon::setTestNow();
}
public function test_submit_creates_staff_attendance(): void
{
Carbon::setTestNow(Carbon::parse('2025-10-01'));
$this->seedConfig();
$teacherId = $this->seedTeacherUser();
$service = new TeacherAbsenceService(
new TeacherConfigService,
new SemesterRangeService(new SemesterConfigService),
new StaffTimeOffLinkService,
new ApplicationUrlService
);
$date = $service->formData($teacherId)['available_dates'][0];
$result = $service->submit($teacherId, [
'dates' => [$date],
'reason' => 'Family event',
'reason_type' => 'personal',
]);
$this->assertTrue($result['ok']);
$this->assertDatabaseHas('staff_attendance', [
'user_id' => $teacherId,
'date' => $date,
'status' => 'absent',
]);
Carbon::setTestNow();
}
private function seedConfig(): void
{
DB::table('configuration')->insert([
['config_key' => 'school_year', 'config_value' => '2025-2026'],
['config_key' => 'semester', 'config_value' => 'Fall'],
['config_key' => 'fall_semester_start', 'config_value' => '2025-09-01'],
['config_key' => 'spring_semester_start', 'config_value' => '2026-01-15'],
['config_key' => 'last_school_day', 'config_value' => '2026-06-15'],
]);
}
private function seedTeacherUser(): int
{
$roleId = DB::table('roles')->insertGetId([
'name' => 'teacher',
]);
$userId = DB::table('users')->insertGetId([
'firstname' => 'Nina',
'lastname' => 'Teacher',
'cellphone' => '3333333333',
'email' => 'teacher.absence@example.com',
'address_street' => '123 Street',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'password' => bcrypt('password'),
'user_type' => 'primary',
'semester' => 'Fall',
'school_year' => '2025-2026',
'status' => 'Active',
]);
DB::table('user_roles')->insert([
'user_id' => $userId,
'role_id' => $roleId,
]);
return $userId;
}
}