Files
AFC-Demo/tests/Feature/CompanySearchTest.php
T
cbazza 1cb38d7080 chore: major project cleanup and restructuring
## Dokumentation
- Entfernt AGENTS.md (redundant zu CLAUDE.md)
- Verschoben: 3 Dokumentationen von root → docs/
- Gelöscht: 8 historische Migrations-Pläne aus docs/archive/
- Entfernt: misc/ Ordner komplett (43 Dateien)

## Struktur
- Erstellt: database/queries/ für SQL Test-Queries (4 Dateien)
- Erstellt: database/schemas/ für Schema-Dokumentation (17 Dateien)
  - output_keys_mapping/ (8 CSV-Mappings)
  - migration-diagrams/ (4 Diagramme)

## Code-Qualität
- Formatiert: 7 Style-Issues in 74 Dateien mit Laravel Pint
- Gefixed: Migration für PostgreSQL/SQLite Kompatibilität
- Gefixed: 2 fehlgeschlagene Tests (CSRF + Text-Assertion)

## Tests
- Alle 73 Tests bestehen jetzt (100% Success Rate)
- AuthenticationTest: CSRF-Token Fix für Logout-Test
- CompanySearchTest: Text-Assertion aktualisiert

## Ergebnis
- Root ist sauber (nur CLAUDE.md)
- Dokumentation strukturiert in docs/
- Database-Dateien organisiert in database/
- Code entspricht Style-Guide
- Alle Tests bestehen
2025-11-21 10:00:32 +01:00

101 lines
3.3 KiB
PHP

<?php
use App\Models\Company;
use App\Models\Transaction;
use App\Models\User;
use Illuminate\Support\Carbon;
use Livewire\Volt\Volt;
test('guests are redirected to the login page', function () {
$response = $this->get(route('company-search'));
$response->assertRedirect(route('login'));
});
test('authenticated users can visit the company search page', function () {
$this->actingAs(User::factory()->create());
$this->get(route('company-search'))->assertOk();
});
test('company search page displays correctly', function () {
$this->actingAs(User::factory()->create());
$response = $this->get(route('company-search'));
$response->assertSee('Unternehmensauskunft');
$response->assertSee('Einfache Suche für Unternehmensdaten und historische Cases');
});
test('search input is wired to component', function () {
$this->actingAs(User::factory()->create());
Volt::test('company-search')
->assertSet('search', '')
->set('search', 'Test Firma')
->assertSet('search', 'Test Firma');
});
test('overview aggregates open alert metrics', function () {
$this->actingAs(User::factory()->create());
$acme = Company::factory()->create(['legal_name' => 'Acme Investigations AG']);
$globex = Company::factory()->create(['legal_name' => 'Globex Risk GmbH']);
Transaction::factory()->for($acme)->requiresReview()->status(Transaction::STATUS_TRUE_POSITIVE)->create([
'amount' => 120000,
'risk_score' => 90,
'executed_at' => Carbon::parse('2024-01-10 09:00:00'),
'signals' => ['Sanktionsliste'],
]);
Transaction::factory()->for($globex)->requiresReview()->status(Transaction::STATUS_FALSE_POSITIVE)->create([
'amount' => 45000,
'risk_score' => 60,
'executed_at' => Carbon::parse('2024-01-11 12:30:00'),
]);
Transaction::factory()->for($acme)->requiresReview(false)->status(Transaction::STATUS_FALSE_POSITIVE)->create([
'amount' => 8000,
'risk_score' => 20,
'executed_at' => Carbon::parse('2024-01-09 08:15:00'),
]);
$component = Volt::test('company-search');
$overview = $component->get('overview');
expect($overview['companies'])->toBe(2)
->and($overview['open_alerts'])->toBe(2)
->and($overview['open_volume'])->toEqualWithDelta(165000, 0.001)
->and($overview['avg_risk'])->toEqualWithDelta(75, 0.001)
->and($overview['watchlist_hits'])->toBe(1)
->and($overview['automation_share'])->toBe(68);
});
test('search filters companies by ticker and name', function () {
$this->actingAs(User::factory()->create());
$match = Company::factory()->create([
'name' => 'Fintrac Labs',
'legal_name' => 'Fintrac Labs AG',
'ticker' => 'FTR',
]);
$other = Company::factory()->create([
'name' => 'Velocity Partners',
'ticker' => 'VLP',
]);
Transaction::factory()->for($match)->requiresReview()->create(['amount' => 250000]);
Transaction::factory()->for($other)->requiresReview()->create(['amount' => 125000]);
$component = Volt::test('company-search');
$component->set('search', 'FTR');
$companies = $component->get('companies');
expect($companies)->toHaveCount(1)
->and($companies->first()->id)->toBe($match->id);
});