Files

51 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
use App\Models\User;
use App\Models\VideoProject;
use App\Support\AssetStorage\AssetStorage;
use Illuminate\Support\Facades\Storage;
beforeEach(function () {
Storage::fake();
});
test('it streams an asset belonging to the project with its mime type', function () {
$project = VideoProject::factory()->create();
$asset = (new AssetStorage)->store($project, 'script', 'hello world', 'txt', mimeType: 'text/plain');
$response = $this->actingAs(User::factory()->create())
->get(route('video-projects.assets.show', [$project, $asset]));
$response->assertOk();
expect($response->headers->get('Content-Type'))->toStartWith('text/plain');
expect($response->streamedContent())->toBe('hello world');
});
test('it 404s when the asset does not belong to the given project', function () {
$project = VideoProject::factory()->create();
$otherProject = VideoProject::factory()->create();
$asset = (new AssetStorage)->store($otherProject, 'script', 'hello', 'txt');
$this->actingAs(User::factory()->create())
->get(route('video-projects.assets.show', [$project, $asset]))
->assertNotFound();
});
test('it 404s when the underlying file is missing', function () {
$project = VideoProject::factory()->create();
$asset = (new AssetStorage)->store($project, 'script', 'hello', 'txt');
Storage::delete($asset->disk_path);
$this->actingAs(User::factory()->create())
->get(route('video-projects.assets.show', [$project, $asset]))
->assertNotFound();
});
test('guests cannot view an asset', function () {
$project = VideoProject::factory()->create();
$asset = (new AssetStorage)->store($project, 'script', 'hello', 'txt');
$this->get(route('video-projects.assets.show', [$project, $asset]))
->assertRedirect(route('login'));
});