Deploy Ladill Transfer / deploy (push) Successful in 29s
Transfers now lists all shares with filters and pagination; Files becomes a selectable cloud view with download, share, delete, move, and open-in-email actions. Co-authored-by: Cursor <cursoragent@cursor.com>
114 lines
3.4 KiB
PHP
114 lines
3.4 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 TransferFilesTest extends TestCase
|
|
{
|
|
use FakesTransferBilling;
|
|
use RefreshDatabase;
|
|
|
|
private function createTransfer(User $user, string $title, string $filename): Transfer
|
|
{
|
|
$this->actingAs($user)->post(route('transfer.transfers.store'), [
|
|
'title' => $title,
|
|
'files' => [UploadedFile::fake()->create($filename, 50, 'application/pdf')],
|
|
])->assertRedirect();
|
|
|
|
return Transfer::query()->where('title', $title)->firstOrFail();
|
|
}
|
|
|
|
public function test_owner_can_download_file(): void
|
|
{
|
|
Storage::fake('qr');
|
|
$this->fakeTransferBillingApi();
|
|
|
|
$user = User::create([
|
|
'public_id' => (string) Str::uuid(),
|
|
'name' => 'Test User',
|
|
'email' => 'transfer+'.uniqid().'@example.com',
|
|
]);
|
|
|
|
$transfer = $this->createTransfer($user, 'Docs', 'brief.pdf');
|
|
$file = $transfer->files()->first();
|
|
|
|
$this->actingAs($user)
|
|
->get(route('transfer.files.download', $file))
|
|
->assertOk();
|
|
}
|
|
|
|
public function test_owner_can_delete_file(): void
|
|
{
|
|
Storage::fake('qr');
|
|
$this->fakeTransferBillingApi();
|
|
|
|
$user = User::create([
|
|
'public_id' => (string) Str::uuid(),
|
|
'name' => 'Test User',
|
|
'email' => 'transfer+'.uniqid().'@example.com',
|
|
]);
|
|
|
|
$transfer = $this->createTransfer($user, 'Docs', 'brief.pdf');
|
|
$file = $transfer->files()->first();
|
|
|
|
$this->actingAs($user)
|
|
->delete(route('transfer.files.destroy', $file))
|
|
->assertRedirect();
|
|
|
|
$this->assertDatabaseMissing('transfer_files', ['id' => $file->id]);
|
|
}
|
|
|
|
public function test_owner_can_move_file_to_another_transfer(): void
|
|
{
|
|
Storage::fake('qr');
|
|
$this->fakeTransferBillingApi();
|
|
|
|
$user = User::create([
|
|
'public_id' => (string) Str::uuid(),
|
|
'name' => 'Test User',
|
|
'email' => 'transfer+'.uniqid().'@example.com',
|
|
]);
|
|
|
|
$source = $this->createTransfer($user, 'Source folder', 'one.pdf');
|
|
$destination = $this->createTransfer($user, 'Destination folder', 'two.pdf');
|
|
$file = $source->files()->first();
|
|
|
|
$this->actingAs($user)
|
|
->post(route('transfer.files.move'), [
|
|
'destination' => $destination->id,
|
|
'files' => [$file->id],
|
|
])
|
|
->assertRedirect(route('transfer.files.index', ['folder' => $destination->id]));
|
|
|
|
$this->assertSame($destination->id, $file->fresh()->transfer_id);
|
|
}
|
|
|
|
public function test_files_index_supports_folder_filter(): void
|
|
{
|
|
Storage::fake('qr');
|
|
$this->fakeTransferBillingApi();
|
|
|
|
$user = User::create([
|
|
'public_id' => (string) Str::uuid(),
|
|
'name' => 'Test User',
|
|
'email' => 'transfer+'.uniqid().'@example.com',
|
|
]);
|
|
|
|
$transfer = $this->createTransfer($user, 'BKC', 'cover.psd');
|
|
|
|
$this->actingAs($user)
|
|
->get(route('transfer.files.index', ['folder' => $transfer->id]))
|
|
->assertOk()
|
|
->assertSee('cover.psd')
|
|
->assertSee('BKC');
|
|
}
|
|
}
|