fakeTransferBillingApi(); 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); } }