12-05-2026 Frontend dev
This commit is contained in:
parent
405df0a122
commit
5b8bdf4182
779 changed files with 480564 additions and 6241 deletions
149
tests/Feature/CustomerPortalTest.php
Normal file
149
tests/Feature/CustomerPortalTest.php
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\UserPaymentOptionStatus;
|
||||
use App\Models\LegacyInvoice;
|
||||
use App\Models\User;
|
||||
use App\Models\UserPaymentOption;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
use Livewire\Volt\Volt as LivewireVolt;
|
||||
use Tests\TestCase;
|
||||
|
||||
test('customer can create and revoke api tokens with selected abilities', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $customer->id,
|
||||
'status' => UserPaymentOptionStatus::Active->value,
|
||||
'current_period_start' => now()->subDay(),
|
||||
'current_period_end' => now()->addMonth(),
|
||||
]);
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.tokens')
|
||||
->assertSee('API-Tokens')
|
||||
->set('tokenName', 'Website Integration')
|
||||
->set('selectedAbilities', ['press-releases:read', 'companies:read'])
|
||||
->call('createToken')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Token wurde erstellt');
|
||||
|
||||
$token = $customer->tokens()->firstOrFail();
|
||||
|
||||
expect($token->name)->toBe('Website Integration');
|
||||
expect($token->abilities)->toBe(['press-releases:read', 'companies:read']);
|
||||
|
||||
LivewireVolt::test('customer.tokens')
|
||||
->call('revokeToken', $token->id)
|
||||
->assertSee('Token wurde widerrufen.');
|
||||
|
||||
expect($customer->tokens()->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('customer cannot create api token without active payment access', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.tokens')
|
||||
->set('tokenName', 'Website Integration')
|
||||
->set('selectedAbilities', ['press-releases:read'])
|
||||
->call('createToken')
|
||||
->assertSee('API-Tokens werden erst freigeschaltet');
|
||||
|
||||
expect($customer->tokens()->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('customer sees only own legacy invoices', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$otherUser = User::factory()->create(['is_active' => true]);
|
||||
|
||||
LegacyInvoice::query()->create([
|
||||
'legacy_portal' => 'presseecho',
|
||||
'legacy_id' => 1001,
|
||||
'user_id' => $customer->id,
|
||||
'legacy_user_id' => 501,
|
||||
'number' => 'RE-CUSTOMER-001',
|
||||
'amount_cents' => 9900,
|
||||
'total_cents' => 9900,
|
||||
'status' => 'paid',
|
||||
'invoice_date' => now()->subMonth(),
|
||||
'paid_at' => now()->subMonth()->addDays(2),
|
||||
'imported_at' => now(),
|
||||
]);
|
||||
|
||||
LegacyInvoice::query()->create([
|
||||
'legacy_portal' => 'businessportal24',
|
||||
'legacy_id' => 1002,
|
||||
'user_id' => $otherUser->id,
|
||||
'legacy_user_id' => 502,
|
||||
'number' => 'RE-OTHER-001',
|
||||
'amount_cents' => 14900,
|
||||
'total_cents' => 14900,
|
||||
'status' => 'paid',
|
||||
'invoice_date' => now()->subMonth(),
|
||||
'paid_at' => now()->subMonth()->addDays(2),
|
||||
'imported_at' => now(),
|
||||
]);
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.invoices')
|
||||
->assertSee('RE-CUSTOMER-001')
|
||||
->assertDontSee('RE-OTHER-001')
|
||||
->assertSee('99,00 €');
|
||||
});
|
||||
|
||||
test('customer can open generated legacy invoice pdf inline from archive data', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$customer->assignRole('customer');
|
||||
|
||||
$invoice = LegacyInvoice::query()->create([
|
||||
'legacy_portal' => 'presseecho',
|
||||
'legacy_id' => 1003,
|
||||
'user_id' => $customer->id,
|
||||
'legacy_user_id' => 503,
|
||||
'number' => 'RE-CUSTOMER-002',
|
||||
'amount_cents' => 9900,
|
||||
'total_cents' => 9900,
|
||||
'status' => 'paid',
|
||||
'invoice_date' => now()->subMonth(),
|
||||
'due_date' => now()->subMonth()->addDays(14),
|
||||
'paid_at' => now()->subMonth()->addDays(2),
|
||||
'payment_method' => 'SPK_Berlin',
|
||||
'raw_snapshot' => [
|
||||
'number' => 'RE-CUSTOMER-002',
|
||||
'service_period_begin_date' => now()->subYear()->toDateString(),
|
||||
'service_period_end_date' => now()->toDateString(),
|
||||
],
|
||||
'pdf_payload' => [
|
||||
'billing_address' => [
|
||||
'name' => 'Customer GmbH',
|
||||
'address' => 'Kundenstrasse 1',
|
||||
'postal_code' => '10115',
|
||||
'city' => 'Berlin',
|
||||
'country_name' => 'Deutschland',
|
||||
],
|
||||
],
|
||||
'imported_at' => now(),
|
||||
]);
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.invoices')
|
||||
->assertSee('Hinweis zu Rechnungen')
|
||||
->assertSee('Rechnungsadresse im Profil pflegen')
|
||||
->assertSee('Öffnen');
|
||||
|
||||
$this->get(route('me.invoices.pdf', $invoice))
|
||||
->assertSuccessful()
|
||||
->assertHeader('content-type', 'application/pdf')
|
||||
->assertHeader('content-disposition', 'inline; filename="Presseecho-RNr-RE-CUSTOMER-002.pdf"');
|
||||
|
||||
expect($invoice->refresh()->pdf_generated_at)->not->toBeNull();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue