<?php

use App\Models\Document;
use App\Models\Project;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;

class DocumentUploadTest extends TestCase
{
    use RefreshDatabase;

    public function test_user_can_upload_document()
    {
        $user = User::factory()->create()->assignRole('project-manager');
        $project = Project::factory()->create();
        
        Storage::fake('documents');
        
        $response = $this->actingAs($user)
            ->post(route('documents.store'), [
                'files' => [
                    UploadedFile::fake()->create('document.pdf', 1024),
                ],
                'project_id' => $project->id
            ]);
        
        $response->assertRedirect();
        $this->assertCount(1, Document::all());
        Storage::disk('documents')->assertExists('projects/1/documents/document.pdf');
    }
}
