Merge remote-tracking branch 'origin/main' into entrega/directiva-20261110
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-11 12:31:10 +02:00
6 changed files with 202 additions and 34 deletions
+26
View File
@@ -3,6 +3,7 @@
namespace Tests\Feature;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\Request as ClientRequest;
use Tests\TestCase;
class TranslationApiTest extends TestCase
@@ -24,4 +25,29 @@ class TranslationApiTest extends TestCase
$this->postJson('/api/translate', $input)->assertOk()->assertJsonPath('translated_text', 'Hello');
$this->postJson('/api/translate', $input)->assertStatus(503);
}
public function test_it_translates_text_batches_for_full_page_translation(): void
{
config(['services.translation.url' => 'http://translator.test']);
Http::fake(['translator.test/translate' => Http::response(['translatedText' => ['Home', 'About us']])]);
$this->postJson('/api/translate', [
'text' => ['Início', 'Sobre nós'],
'source_lang' => 'auto',
'target_lang' => 'en',
])->assertOk()
->assertJsonPath('translated_text.0', 'Home')
->assertJsonPath('translated_text.1', 'About us');
Http::assertSent(fn (ClientRequest $request) => $request['q'] === ['Início', 'Sobre nós']);
}
public function test_it_rejects_translation_batches_that_exceed_the_request_limit(): void
{
$this->postJson('/api/translate', [
'text' => array_fill(0, 9, 'Texto'),
'source_lang' => 'auto',
'target_lang' => 'en',
])->assertUnprocessable();
}
}