presseportale/tests/Feature/Admin/AdminLegacyInvoiceArchiveTest.php
Kevin Adametz 2cde7284a1 livewire: Volt entfernt — Komponenten als Livewire-4-Single-File-Components, Route::livewire(), Livewire::test(); livewire/volt deinstalliert
- 83 Komponenten: Livewire\Volt\Component → Livewire\Component
- 73 Routen (admin, auth, customer): Volt::route() → Route::livewire()
- 88 Testdateien: Volt::test/actingAs → Livewire::test/actingAs
- VoltServiceProvider gelöscht; composer remove livewire/volt
- config/livewire.php auf v4-Schlüssel (component_layout, component_placeholder,
  component_locations, make_command: SFC ohne ⚡). Der alte Schlüssel layout war
  wirkungslos; alle gerouteten Komponenten setzen ihr Layout selbst.
- CLAUDE.md, AGENTS.md, boost.json, .cursorrules, Skill volt-development
- Roadmap: erledigt; Larastan erfasst SFCs weiterhin nicht (Blade-Dateien)

Suite 2.325 grün, einer übersprungen; Larastan und Pint ohne Meldung;
route:cache und view:cache laufen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 13:59:36 +00:00

211 lines
6.8 KiB
PHP

<?php
use App\Models\LegacyInvoice;
use App\Models\User;
use Database\Seeders\RolesAndPermissionsSeeder;
use Livewire\Livewire;
use Tests\TestCase;
beforeEach(function () {
/** @var TestCase $this */
$this->seed(RolesAndPermissionsSeeder::class);
$admin = User::factory()->create(['is_active' => true]);
$admin->assignRole('admin');
$this->actingAs($admin);
});
test('admin sees legacy invoice archive overview with filters and mapping hints', function () {
$customer = User::factory()->create([
'is_active' => true,
'name' => 'Archiv Kunde',
'email' => 'archiv@example.com',
]);
LegacyInvoice::query()->create([
'legacy_portal' => 'presseecho',
'legacy_id' => 2001,
'user_id' => $customer->id,
'legacy_user_id' => 501,
'number' => 'PE-2001',
'amount_cents' => 4900,
'total_cents' => 4900,
'status' => 'paid',
'invoice_date' => now()->subMonth(),
'paid_at' => now()->subMonth()->addDays(2),
'imported_at' => now(),
]);
LegacyInvoice::query()->create([
'legacy_portal' => 'businessportal24',
'legacy_id' => 2002,
'user_id' => null,
'legacy_user_id' => 999,
'number' => 'BP-2002',
'amount_cents' => 11900,
'total_cents' => 11900,
'status' => 'open',
'invoice_date' => now()->subWeeks(2),
'imported_at' => now(),
]);
Livewire::test('admin.invoices.index')
->assertSee('Legacy-Rechnungsarchiv')
->assertSee('PE-2001')
->assertSee('BP-2002')
->assertSee('Ohne Zuordnung')
->assertSee('Archiv Kunde')
->set('mappingFilter', 'unmapped')
->assertSee('BP-2002')
->assertDontSee('PE-2001')
->set('mappingFilter', 'all')
->set('portalFilter', 'presseecho')
->assertSee('PE-2001')
->assertDontSee('BP-2002')
->call('resetFilters')
->assertSee('PE-2001')
->assertSee('BP-2002');
});
test('never-paid hold invoices are hidden by default and can be shown on demand', function () {
$customer = User::factory()->create(['is_active' => true]);
LegacyInvoice::query()->create([
'legacy_portal' => 'businessportal24',
'legacy_id' => 3001,
'user_id' => $customer->id,
'legacy_user_id' => 601,
'number' => 'BP-HOLD-3001',
'amount_cents' => 19900,
'total_cents' => 19900,
'status' => 'hold',
'invoice_date' => now()->subYear(),
'imported_at' => now(),
]);
LegacyInvoice::query()->create([
'legacy_portal' => 'businessportal24',
'legacy_id' => 3002,
'user_id' => $customer->id,
'legacy_user_id' => 601,
'number' => 'BP-REMINDER-3002',
'amount_cents' => 19900,
'total_cents' => 19900,
'status' => 'reminder',
'invoice_date' => now()->subMonths(2),
'imported_at' => now(),
]);
Livewire::test('admin.invoices.index')
->assertSee('BP-REMINDER-3002')
->assertDontSee('BP-HOLD-3001')
->assertSee('1 erledigte hold-Rechnungen')
->set('showHold', true)
->assertSee('BP-HOLD-3001')
->set('showHold', false)
->set('statusFilter', 'hold')
->assertSee('BP-HOLD-3001')
->assertDontSee('BP-REMINDER-3002');
});
test('admin opens generated legacy invoice pdf inline', function () {
/** @var TestCase $this */
$invoice = LegacyInvoice::query()->create([
'legacy_portal' => 'presseecho',
'legacy_id' => 2003,
'user_id' => null,
'legacy_user_id' => 503,
'number' => 'PE-2003',
'amount_cents' => 9900,
'total_cents' => 9900,
'status' => 'paid',
'invoice_date' => now()->subMonth(),
'paid_at' => now()->subMonth()->addDays(2),
'payment_method' => 'SPK_Berlin',
'raw_snapshot' => [
'number' => 'PE-2003',
'service_period_begin_date' => now()->subYear()->toDateString(),
'service_period_end_date' => now()->toDateString(),
],
'pdf_payload' => [
'billing_address' => [
'name' => 'Admin Archiv GmbH',
'address' => 'Archivstrasse 1',
'postal_code' => '10115',
'city' => 'Berlin',
'country_name' => 'Deutschland',
],
],
'imported_at' => now(),
]);
Livewire::test('admin.invoices.index')
->assertSee('Öffnen');
$response = $this->get(route('admin.legacy-invoices.pdf', $invoice));
$response
->assertSuccessful()
->assertHeader('content-type', 'application/pdf')
->assertHeader('content-disposition', 'inline; filename="Presseecho-RNr-PE-2003.pdf"');
expect($response->content())
->toContain('adametz.media')
->toContain('Rechnungsbetrag')
->toContain('/F2 21 Tf');
expect($invoice->refresh()->pdf_generated_at)->not->toBeNull();
});
test('admin opens legacy invoice pdf with stern layout for non media invoices', function () {
/** @var TestCase $this */
$invoice = LegacyInvoice::query()->create([
'legacy_portal' => 'businessportal24',
'legacy_id' => 2004,
'user_id' => null,
'legacy_user_id' => 504,
'number' => 'BP-2004',
'amount_cents' => 11900,
'total_cents' => 11900,
'status' => 'open',
'invoice_date' => now()->subMonth(),
'due_date' => now()->addDays(14),
'payment_method' => 'invoice',
'raw_snapshot' => [
'number' => 'BP-2004',
'is_media' => false,
'service_period_begin_date' => now()->subYear()->toDateString(),
'service_period_end_date' => now()->toDateString(),
],
'pdf_payload' => [
'invoice' => [
'is_media' => false,
'service_period_begin_date' => now()->subYear()->toDateString(),
'service_period_end_date' => now()->toDateString(),
],
'billing_address' => [
'name' => 'Stern Archiv GmbH',
'address' => 'Archivstrasse 2',
'postal_code' => '10719',
'city' => 'Berlin',
'country_name' => 'Deutschland',
],
'payment_option_translation' => [
'name' => 'Legacy Pressepaket',
],
],
'imported_at' => now(),
]);
$response = $this->get(route('admin.legacy-invoices.pdf', $invoice));
$response
->assertSuccessful()
->assertHeader('content-type', 'application/pdf')
->assertHeader('content-disposition', 'inline; filename="Businessportal24-RNr-BP-2004.pdf"');
expect($response->content())
->toContain('Stern Consulting GmbH')
->toContain('Hypo Vereinsbank')
->toContain('/F2 19 Tf');
});