Files
HRM-System/tests/Feature/ApiProfileAvatarTest.php

49 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class ApiProfileAvatarTest extends TestCase
{
use RefreshDatabase;
public function test_user_profile_avatar_url_resolution()
{
Storage::fake('public');
$user = User::factory()->create([
'avatar' => 'avatars/test-avatar.jpg',
]);
$response = $this->actingAs($user, 'sanctum')
->getJson('/api/profile');
$response->assertStatus(200);
$avatarUrl = get_file($user->avatar);
$this->assertStringContainsString('media/avatars/test-avatar.jpg', $avatarUrl);
}
public function test_avatar_upload_returns_valid_storage_path()
{
Storage::fake('public');
$user = User::factory()->create();
$file = UploadedFile::fake()->image('profile.jpg');
$response = $this->actingAs($user, 'sanctum')
->postJson('/api/profile', [
'avatar' => $file,
]);
$response->assertStatus(200);
$this->assertNotNull($user->fresh()->avatar);
$this->assertStringStartsWith('avatars/', $user->fresh()->avatar);
}
}