.
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-04 15:10:29 +02:00
40 changed files with 1873 additions and 1688 deletions
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace Tests\Feature;
use App\Http\Controllers\InvestmentPortfolioController;
use App\Services\FederatedSearch;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\DB;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
final class GlobalSearchTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->withoutVite();
}
public function test_empty_and_overlong_queries(): void
{
$this->get('/pesquisa')->assertOk()->assertInertia(fn (Assert $page) => $page->component('portal/search')->where('results.total', 0));
$this->get('/pesquisa?q='.str_repeat('a', 121))->assertSessionHasErrors('q');
}
public function test_source_failure_recalculates_the_page_without_hiding_the_other_results(): void
{
$sources = [
'Documentos' => fn () => ['count' => 1, 'fetch' => fn () => throw new QueryException('testing', 'select 1', [], new \RuntimeException('Source unavailable'))],
'Páginas' => fn () => ['count' => 1, 'fetch' => fn ($offset, $limit) => array_slice([['title' => 'Como investir', 'url' => '/como-investir']], $offset, $limit)],
];
$result = app(FederatedSearch::class)->page($sources, 1);
$this->assertSame(1, $result['total']);
$this->assertSame(['Documentos'], $result['unavailable']);
$this->assertSame('Como investir', $result['data'][0]['title']);
}
public function test_public_search_uses_the_existing_portfolio_visibility_scope(): void
{
if (getenv('GLOBAL_SEARCH_QA') !== '1') {
$this->markTestSkipped('A prova com dados exige a base QA explicitamente seleccionada.');
}
$identity = DB::selectOne('select current_database() as name, inet_server_port() as port');
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
$this->assertSame(55441, (int) $identity->port);
$record = InvestmentPortfolioController::visible()->first();
if (! $record) {
$this->markTestSkipped('No published portfolio records in isolated QA.');
}
$term = mb_substr($record->title, 0, 15);
$this->get('/pesquisa?q='.urlencode($term))->assertOk()->assertInertia(fn (Assert $page) => $page
->component('portal/search')->where('query', $term)
->where('results.total', fn ($total) => $total >= 1));
}
}
+27
View File
@@ -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);
}
}