<?php

use App\Models\User;
use App\Enums\UserType;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;

test('employee can update profile image', function () {
    Storage::fake('public');
    $user = User::factory()->create(['type' => UserType::EMPLOYEE]);
    $file = UploadedFile::fake()->image('avatar.jpg');

    $response = $this->actingAs($user)
        ->put(route('employee.profile.update_image'), [
            'profile_image' => $file,
        ]);

    $response->assertRedirect();
    $user->refresh();
    expect($user->profile_image)->not->toBeNull();
    Storage::disk('public')->assertExists($user->profile_image);
});

test('employee can update password', function () {
    $user = User::factory()->create([
        'type' => UserType::EMPLOYEE,
        'password' => Hash::make('old-password'),
    ]);

    $response = $this->actingAs($user)
        ->put(route('employee.profile.update_password'), [
            'current_password' => 'old-password',
            'password' => 'new-password',
            'password_confirmation' => 'new-password',
        ]);

    $response->assertRedirect();
    $user->refresh();
    expect(Hash::check('new-password', $user->password))->toBeTrue();
});

test('employee can update profile info', function () {
    $user = User::factory()->create(['type' => UserType::EMPLOYEE]);

    $response = $this->actingAs($user)
        ->put(route('employee.profile.update_info'));

    $response->assertRedirect();
});

