<?php

namespace Tests\Feature;

use App\Models\User;
use Illuminate\Encryption\Encrypter;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class TeacherAbsenceVacationRouteTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();

        $key = 'base64:'.base64_encode(random_bytes(32));
        config([
            'app.key' => $key,
            'app.cipher' => 'aes-256-cbc',
        ]);

        $rawKey = base64_decode(substr($key, 7), true);
        $this->app->instance('encrypter', new Encrypter($rawKey, 'aes-256-cbc'));
    }

    public function test_authenticated_teacher_absence_vacation_route_redirects_to_spa_page(): void
    {
        $user = User::factory()->create();

        $response = $this->actingAs($user)->get('/teacher/absence-vacation');

        $response->assertRedirect('/app/teacher/absence-vacation');
    }

    public function test_authenticated_legacy_teacher_absence_vacation_route_redirects_to_spa_page(): void
    {
        $user = User::factory()->create();

        $response = $this->actingAs($user)->get('/teacher/absence_vacation');

        $response->assertRedirect('/app/teacher/absence-vacation');
    }
}
