<?php

namespace Tests\Feature;

use App\Http\Controllers\MediaController;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;

class MediaControllerTest extends TestCase
{
    public function test_media_controller_serves_public_disk_files(): void
    {
        $path = 'test-media/test-image.jpg';
        Storage::disk('public')->put($path, 'fake-image');

        try {
            $response = app(MediaController::class)->show($path);

            $this->assertSame(200, $response->getStatusCode());
            $this->assertSame('fake-image', file_get_contents($response->getFile()->getPathname()));
        } finally {
            Storage::disk('public')->delete($path);
        }
    }

    public function test_media_route_is_registered(): void
    {
        $route = app('router')->getRoutes()->getByName('media.show');

        $this->assertNotNull($route);
        $this->assertSame('media/{path}', $route->uri());
    }
}
