111 lines
3.5 KiB
PHP
111 lines
3.5 KiB
PHP
<?php
|
|
|
|
use App\Models\LegacyInvoice;
|
|
use App\Models\User;
|
|
use Database\Seeders\RolesAndPermissionsSeeder;
|
|
use Livewire\Volt\Volt as LivewireVolt;
|
|
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(),
|
|
]);
|
|
|
|
LivewireVolt::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('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(),
|
|
]);
|
|
|
|
LivewireVolt::test('admin.invoices.index')
|
|
->assertSee('Öffnen');
|
|
|
|
$this->get(route('admin.legacy-invoices.pdf', $invoice))
|
|
->assertSuccessful()
|
|
->assertHeader('content-type', 'application/pdf')
|
|
->assertHeader('content-disposition', 'inline; filename="Presseecho-RNr-PE-2003.pdf"');
|
|
|
|
expect($invoice->refresh()->pdf_generated_at)->not->toBeNull();
|
|
});
|