Replace controller-driven Blade views with full-page Livewire index/show/create flows so Flux tables, toasts, and uploads work natively.
116 lines
3.7 KiB
PHP
116 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Recording;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\TestCase;
|
|
|
|
class RecordingAudioStreamTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_owner_can_stream_recording_audio(): void
|
|
{
|
|
Storage::fake('local');
|
|
Storage::disk('local')->put('recordings/note.mp3', 'fake-audio-bytes');
|
|
|
|
$user = User::factory()->create();
|
|
$recording = Recording::query()->create([
|
|
'user_id' => $user->id,
|
|
'title' => 'Note',
|
|
'original_filename' => 'note.mp3',
|
|
'file_path' => 'recordings/note.mp3',
|
|
'file_size_bytes' => 16,
|
|
'transcription_status' => 'pending',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('recordings.audio', $recording))
|
|
->assertOk()
|
|
->assertHeader('content-type', 'audio/mpeg')
|
|
->assertHeader('content-disposition', 'inline; filename=note.mp3');
|
|
}
|
|
|
|
public function test_show_page_includes_audio_player(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$recording = Recording::query()->create([
|
|
'user_id' => $user->id,
|
|
'title' => 'Playable',
|
|
'original_filename' => 'playable.mp3',
|
|
'file_path' => 'recordings/playable.mp3',
|
|
'file_size_bytes' => 10,
|
|
'transcription_status' => 'pending',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('recordings.show', $recording))
|
|
->assertOk()
|
|
->assertSee('Play', false)
|
|
->assertSee(route('recordings.audio', $recording), false)
|
|
->assertSee('<audio', false);
|
|
}
|
|
|
|
public function test_index_page_links_to_recording_show(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$recording = Recording::query()->create([
|
|
'user_id' => $user->id,
|
|
'title' => 'List playable',
|
|
'original_filename' => 'list.mp3',
|
|
'file_path' => 'recordings/list.mp3',
|
|
'file_size_bytes' => 10,
|
|
'transcription_status' => 'pending',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('recordings.index'))
|
|
->assertOk()
|
|
->assertSee('List playable')
|
|
->assertSee(route('recordings.show', $recording), false);
|
|
}
|
|
|
|
public function test_other_user_cannot_stream_recording_audio(): void
|
|
{
|
|
Storage::fake('local');
|
|
Storage::disk('local')->put('recordings/secret.mp3', 'fake-audio-bytes');
|
|
|
|
$owner = User::factory()->create();
|
|
$intruder = User::factory()->create();
|
|
$recording = Recording::query()->create([
|
|
'user_id' => $owner->id,
|
|
'title' => 'Secret',
|
|
'original_filename' => 'secret.mp3',
|
|
'file_path' => 'recordings/secret.mp3',
|
|
'file_size_bytes' => 16,
|
|
'transcription_status' => 'pending',
|
|
]);
|
|
|
|
$this->actingAs($intruder)
|
|
->get(route('recordings.audio', $recording))
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function test_missing_audio_file_returns_not_found(): void
|
|
{
|
|
Storage::fake('local');
|
|
|
|
$user = User::factory()->create();
|
|
$recording = Recording::query()->create([
|
|
'user_id' => $user->id,
|
|
'title' => 'Gone',
|
|
'original_filename' => 'gone.mp3',
|
|
'file_path' => 'recordings/gone.mp3',
|
|
'file_size_bytes' => 10,
|
|
'transcription_status' => 'pending',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('recordings.audio', $recording))
|
|
->assertNotFound();
|
|
}
|
|
}
|