presseportale/tests/Feature/CustomerPressKitCreatePhase8eTest.php
Kevin Adametz fd8e050cb7 Backend-WIP: Kontakt-Queue, Page-Cache, Validierungs-Feedback, i18n
Gebuendelt, da ueber gemeinsame lang-/Service-Dateien verschraenkt:
- Kontakt-Nachrichten: contact_messages-Tabelle + Model/Enums/Factory,
  Admin-Queue (livewire/admin/contact-messages), ContactController
  persistiert das Anliegen zusaetzlich zur Brand-Mail
- Page-Data-Cache (Services/Web/*PageData) + web-archive-Indizes auf
  press_releases
- Validierungs-Feedback + Company-Portal-Restriction (Feature-Tests)
- i18n-Auslagerung lang/de|en (auth, passwords, validation, static)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 15:38:11 +00:00

117 lines
3.7 KiB
PHP

<?php
use App\Enums\Portal;
use App\Models\Company;
use App\Models\User;
use Database\Seeders\RolesAndPermissionsSeeder;
use Livewire\Volt\Volt as LivewireVolt;
use Tests\TestCase;
beforeEach(function (): void {
/** @var TestCase $this */
$this->seed(RolesAndPermissionsSeeder::class);
});
function makeCustomerForCreate(): User
{
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
return $customer;
}
test('Create-Route ist für eingeloggte Customer erreichbar', function () {
/** @var TestCase $this */
$customer = makeCustomerForCreate();
$this->actingAs($customer)
->get('/admin/me/firmen/anlegen')
->assertOk()
->assertSeeText('Neue Firma anlegen')
->assertSeeText('Firmenname');
});
test('Create-Route ist für Gäste nicht zugänglich', function () {
/** @var TestCase $this */
$this->get('/admin/me/firmen/anlegen')
->assertRedirect();
});
test('save erstellt eine Firma und ordnet sie dem User als Owner zu', function () {
/** @var TestCase $this */
$customer = makeCustomerForCreate();
LivewireVolt::actingAs($customer)
->test('customer.press-kits.create')
->set('name', 'Neue Brauerei AG')
->set('portal', 'presseecho')
->set('email', 'kontakt@brauerei.de')
->call('save')
->assertHasNoErrors()
->assertRedirect();
/** @var Company $company */
$company = Company::query()->withoutGlobalScopes()->where('name', 'Neue Brauerei AG')->first();
expect($company)->not->toBeNull()
->and($company->owner_user_id)->toBe($customer->id)
->and($company->portal->value)->toBe('presseecho')
// Ohne Typ-Feld immer Newsroom: der Übermittler („Agentur") lebt
// seit dem Attributions-Umbau im Profilfeld users.agency_name.
->and($company->type?->value)->toBe('company')
->and($company->email)->toBe('kontakt@brauerei.de')
->and($company->is_active)->toBeTrue();
expect($customer->companies()->where('companies.id', $company->id)->wherePivot('role', 'owner')->exists())
->toBeTrue();
});
test('save validiert Pflichtfelder Name und Portal', function () {
/** @var TestCase $this */
$customer = makeCustomerForCreate();
LivewireVolt::actingAs($customer)
->test('customer.press-kits.create')
->set('name', '')
->set('portal', '')
->call('save')
->assertHasErrors(['name' => 'required', 'portal' => 'required']);
});
test('save lehnt unbekannte Portal-Werte ab', function () {
/** @var TestCase $this */
$customer = makeCustomerForCreate();
LivewireVolt::actingAs($customer)
->test('customer.press-kits.create')
->set('name', 'Test GmbH')
->set('portal', 'invalid')
->call('save')
->assertHasErrors(['portal']);
});
test('save lehnt Portal Both ab', function () {
/** @var TestCase $this */
$customer = makeCustomerForCreate();
LivewireVolt::actingAs($customer)
->test('customer.press-kits.create')
->set('name', 'Beide Portale GmbH')
->set('portal', Portal::Both->value)
->call('save')
->assertHasErrors(['portal']);
expect(Company::query()->withoutGlobalScopes()->where('name', 'Beide Portale GmbH')->exists())
->toBeFalse();
});
test('Portal-Auswahl bietet Beide Portale nicht an', function () {
/** @var TestCase $this */
$customer = makeCustomerForCreate();
LivewireVolt::actingAs($customer)
->test('customer.press-kits.create')
->assertSeeText(Portal::Presseecho->label())
->assertSeeText(Portal::Businessportal24->label())
->assertDontSeeText(Portal::Both->label());
});