Files
ladill-transfer/tests/Feature/TransferTest.php
T
isaaccladandCursor 6cd2a75498
Deploy Ladill Transfer / deploy (push) Successful in 31s
Fix transfer create uploads getting stuck and failing on submit.
All files now upload through chunked sessions only, the file picker no longer
rewrites the queue on change, and create submits upload_ids instead of a broken
multipart files field.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-08 13:36:27 +00:00

97 lines
3.2 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Transfer;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Tests\Concerns\FakesTransferBilling;
use Tests\TestCase;
class TransferTest extends TestCase
{
use FakesTransferBilling;
use RefreshDatabase;
public function test_authenticated_user_can_create_transfer_with_files(): void
{
Storage::fake('qr');
$this->fakeTransferBillingApi();
$user = User::create([
'public_id' => (string) Str::uuid(),
'name' => 'Test User',
'email' => 'transfer+'.uniqid().'@example.com',
]);
$response = $this->actingAs($user)->post(route('transfer.transfers.store'), [
'title' => 'Project assets',
'message' => 'Here are the files.',
'files' => [
UploadedFile::fake()->create('brief.pdf', 100, 'application/pdf'),
UploadedFile::fake()->create('photo.jpg', 50, 'image/jpeg'),
],
]);
$response->assertRedirect();
$this->assertDatabaseCount('transfers', 1);
$this->assertDatabaseCount('transfer_files', 2);
$this->assertDatabaseHas('qr_codes', ['type' => 'transfer', 'label' => 'Project assets']);
$transfer = Transfer::first();
$this->assertNotNull($transfer->qr_code_id);
$this->assertNotNull($transfer->paid_until);
$this->assertTrue($transfer->paid_until->isFuture());
}
public function test_authenticated_user_can_create_transfer_from_chunked_upload_ids(): void
{
Storage::fake('qr');
$this->fakeTransferBillingApi();
$user = User::create([
'public_id' => (string) Str::uuid(),
'name' => 'Test User',
'email' => 'transfer+'.uniqid().'@example.com',
]);
$init = $this->actingAs($user)->postJson(route('transfer.transfers.upload.init'), [
'filename' => 'brief.pdf',
'filesize' => 12,
])->assertOk()->json();
$uploadId = (string) ($init['upload_id'] ?? '');
$this->assertNotSame('', $uploadId);
$chunk = UploadedFile::fake()->createWithContent('chunk_0', str_repeat('a', 12));
$this->actingAs($user)->post(route('transfer.transfers.upload.chunk'), [
'upload_id' => $uploadId,
'chunk_index' => 0,
'chunk_size' => 12,
'chunk' => $chunk,
])->assertOk();
$this->actingAs($user)->postJson(route('transfer.transfers.upload.finalize'), [
'upload_id' => $uploadId,
'total_chunks' => 1,
])->assertOk();
$this->actingAs($user)->post(route('transfer.transfers.store'), [
'title' => 'Chunked assets',
'upload_ids' => [$uploadId],
])->assertRedirect();
$this->assertDatabaseCount('transfers', 1);
$this->assertDatabaseCount('transfer_files', 1);
$this->assertDatabaseHas('transfer_files', ['original_name' => 'brief.pdf']);
}
public function test_dashboard_requires_auth(): void
{
$this->get(route('transfer.dashboard'))->assertRedirect();
}
}