Deploy Ladill Transfer / deploy (push) Successful in 39s
Large files upload in 5 MB chunks (hosting file manager pattern) for the transfer UI and Ladill Mail S2S API, with no app-level file size cap when TRANSFER_MAX_FILE_BYTES=0. Co-authored-by: Cursor <cursoragent@cursor.com>
107 lines
3.6 KiB
PHP
107 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
class TransferApiTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Storage::fake('qr');
|
|
config([
|
|
'transfer.service_api_keys' => ['webmail' => 'test-webmail-key'],
|
|
'identity.api_url' => 'https://ladill.com/api',
|
|
'identity.api_key' => 'test-identity-key',
|
|
]);
|
|
}
|
|
|
|
public function test_webmail_service_can_create_transfer_for_mailbox(): void
|
|
{
|
|
Http::fake([
|
|
rtrim((string) config('identity.api_url'), '/').'/identity/profile*' => Http::response([
|
|
'data' => [
|
|
'public_id' => (string) Str::uuid(),
|
|
'name' => 'Mail User',
|
|
'email' => 'sender@acme.com',
|
|
'picture' => null,
|
|
],
|
|
]),
|
|
]);
|
|
|
|
$file = UploadedFile::fake()->create('large.zip', 30000, 'application/zip');
|
|
|
|
$this->withToken('test-webmail-key')
|
|
->post('/api/v1/transfers', [
|
|
'mailbox' => 'sender@acme.com',
|
|
'title' => 'Email: Quarterly report',
|
|
'files' => [$file],
|
|
])
|
|
->assertCreated()
|
|
->assertJsonPath('data.title', 'Email: Quarterly report')
|
|
->assertJsonStructure(['data' => ['public_url', 'files']]);
|
|
|
|
$this->assertDatabaseHas('users', ['email' => 'sender@acme.com']);
|
|
$this->assertDatabaseCount('transfers', 1);
|
|
}
|
|
|
|
public function test_transfer_api_rejects_unauthorized_callers(): void
|
|
{
|
|
$this->post('/api/v1/transfers', ['mailbox' => 'x@y.com'])
|
|
->assertUnauthorized();
|
|
}
|
|
|
|
public function test_webmail_service_can_finalize_chunked_upload(): void
|
|
{
|
|
Http::fake([
|
|
rtrim((string) config('identity.api_url'), '/').'/identity/profile*' => Http::response([
|
|
'data' => [
|
|
'public_id' => (string) Str::uuid(),
|
|
'name' => 'Mail User',
|
|
'email' => 'chunked@acme.com',
|
|
'picture' => null,
|
|
],
|
|
]),
|
|
]);
|
|
|
|
$init = $this->withToken('test-webmail-key')->postJson('/api/v1/transfers/upload/init', [
|
|
'mailbox' => 'chunked@acme.com',
|
|
'filename' => 'archive.zip',
|
|
'filesize' => 12,
|
|
])->assertOk()->json();
|
|
|
|
$uploadId = (string) ($init['upload_id'] ?? '');
|
|
$this->assertNotSame('', $uploadId);
|
|
|
|
$chunk = UploadedFile::fake()->createWithContent('chunk_0', str_repeat('a', 12));
|
|
$this->withToken('test-webmail-key')->post('/api/v1/transfers/upload/chunk', [
|
|
'mailbox' => 'chunked@acme.com',
|
|
'upload_id' => $uploadId,
|
|
'chunk_index' => 0,
|
|
'chunk_size' => 12,
|
|
'chunk' => $chunk,
|
|
])->assertOk();
|
|
|
|
$this->withToken('test-webmail-key')->postJson('/api/v1/transfers/upload/finalize', [
|
|
'mailbox' => 'chunked@acme.com',
|
|
'upload_id' => $uploadId,
|
|
'total_chunks' => 1,
|
|
'title' => 'Email: Big file',
|
|
])
|
|
->assertCreated()
|
|
->assertJsonPath('data.title', 'Email: Big file')
|
|
->assertJsonStructure(['data' => ['public_url', 'files']]);
|
|
|
|
$this->assertDatabaseCount('transfers', 1);
|
|
}
|
|
}
|