Add first edition of AndyTranscribe.
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\TranscribeRecording;
|
||||
use App\Models\Recording;
|
||||
use App\Services\TranscriptionService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Laravel\Ai\Transcription;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RecordingUploadTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_shows_recordings(): void
|
||||
{
|
||||
Recording::query()->create([
|
||||
'title' => 'Pocket note',
|
||||
'original_filename' => 'note.mp3',
|
||||
'file_path' => 'recordings/note.mp3',
|
||||
'file_size_bytes' => 1024,
|
||||
'transcription_status' => 'pending',
|
||||
]);
|
||||
|
||||
$this->get(route('recordings.index'))
|
||||
->assertOk()
|
||||
->assertSee('Pocket note');
|
||||
}
|
||||
|
||||
public function test_user_can_upload_an_mp3(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
$file = UploadedFile::fake()->create('meeting.mp3', 500, 'audio/mpeg');
|
||||
|
||||
$response = $this->post(route('recordings.store'), [
|
||||
'audio' => $file,
|
||||
'title' => 'Team meeting',
|
||||
]);
|
||||
|
||||
$recording = Recording::query()->first();
|
||||
|
||||
$this->assertNotNull($recording);
|
||||
$response->assertRedirect(route('recordings.show', $recording));
|
||||
$this->assertSame('Team meeting', $recording->title);
|
||||
$this->assertSame('pending', $recording->transcription_status);
|
||||
Storage::disk('local')->assertExists($recording->file_path);
|
||||
}
|
||||
|
||||
public function test_user_can_queue_cloud_transcription(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$recording = Recording::query()->create([
|
||||
'title' => 'Dictation',
|
||||
'original_filename' => 'dictation.mp3',
|
||||
'file_path' => 'recordings/dictation.mp3',
|
||||
'file_size_bytes' => 2048,
|
||||
'transcription_status' => 'pending',
|
||||
]);
|
||||
|
||||
$this->post(route('recordings.transcribe', $recording), [
|
||||
'driver' => 'cloud',
|
||||
])->assertRedirect();
|
||||
|
||||
Queue::assertPushed(TranscribeRecording::class);
|
||||
|
||||
$recording->refresh();
|
||||
$this->assertSame('cloud', $recording->transcription_driver);
|
||||
}
|
||||
|
||||
public function test_ollama_driver_requires_url(): void
|
||||
{
|
||||
$recording = Recording::query()->create([
|
||||
'title' => 'Secret call',
|
||||
'original_filename' => 'call.mp3',
|
||||
'file_path' => 'recordings/call.mp3',
|
||||
'file_size_bytes' => 2048,
|
||||
'transcription_status' => 'pending',
|
||||
]);
|
||||
|
||||
$this->from(route('recordings.show', $recording))
|
||||
->post(route('recordings.transcribe', $recording), [
|
||||
'driver' => 'ollama',
|
||||
])
|
||||
->assertSessionHasErrors('ollama_url');
|
||||
}
|
||||
|
||||
public function test_transcription_job_stores_transcript(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
Storage::disk('local')->put('recordings/sample.mp3', 'fake-audio-bytes');
|
||||
|
||||
Transcription::fake(['Hello from the recorder.']);
|
||||
|
||||
$recording = Recording::query()->create([
|
||||
'title' => 'Sample',
|
||||
'original_filename' => 'sample.mp3',
|
||||
'file_path' => 'recordings/sample.mp3',
|
||||
'file_size_bytes' => 12,
|
||||
'transcription_status' => 'pending',
|
||||
'transcription_driver' => 'cloud',
|
||||
]);
|
||||
|
||||
(new TranscribeRecording($recording))->handle(app(TranscriptionService::class));
|
||||
|
||||
$recording->refresh();
|
||||
$this->assertSame('done', $recording->transcription_status);
|
||||
$this->assertSame('Hello from the recorder.', $recording->transcript);
|
||||
$this->assertNotNull($recording->transcribed_at);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user