.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TranslationApiTest extends TestCase
|
||||
{
|
||||
public function test_it_lists_languages_from_the_configured_engine(): void
|
||||
{
|
||||
config(['services.translation.url' => 'http://translator.test']);
|
||||
Http::fake(['translator.test/languages' => Http::response([['code' => 'pt', 'name' => 'Portuguese', 'targets' => ['en']]])]);
|
||||
|
||||
$this->getJson('/api/translate/languages')->assertOk()->assertJsonPath('0.targets.0', 'en');
|
||||
}
|
||||
|
||||
public function test_it_translates_and_reports_engine_failures(): void
|
||||
{
|
||||
config(['services.translation.url' => 'http://translator.test']);
|
||||
Http::fake(['translator.test/translate' => Http::sequence()->push(['translatedText' => 'Hello'])->push([], 500)]);
|
||||
$input = ['text' => 'Olá', 'source_lang' => 'pt', 'target_lang' => 'en'];
|
||||
|
||||
$this->postJson('/api/translate', $input)->assertOk()->assertJsonPath('translated_text', 'Hello');
|
||||
$this->postJson('/api/translate', $input)->assertStatus(503);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user