Recht: Kuendigungsbutton nach Par. 312k BGB - Backend + Admin-Queue
Oeffentliche Bestaetigungsseite /de/kuendigung ohne Login: Art der Kuendigung (Grund nur bei ausserordentlich), Zuordnungsdaten, Beendigungszeitpunkt; Honeypot + Rate-Limit wie beim Widerruf. Sofortige automatische Zugangsbestaetigung per E-Mail (Par. 312k Abs. 4 BGB) + Betreiber-Mail. Kuendigungen laufen in der Recht-&-Compliance-Queue unter den Widerrufen auf (K-Vorgaenge, eigener Filter, Erledigt/Wieder-oeffnen, vierte KPI-Karte). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
239ec571bc
commit
1c3a52ae3c
12 changed files with 826 additions and 2 deletions
77
tests/Feature/Admin/TerminationRequestsAdminTest.php
Normal file
77
tests/Feature/Admin/TerminationRequestsAdminTest.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
use App\Models\TerminationRequest;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
use Livewire\Volt\Volt;
|
||||
use Tests\TestCase;
|
||||
|
||||
beforeEach(function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
});
|
||||
|
||||
function terminationAdmin(): User
|
||||
{
|
||||
$admin = User::factory()->create(['is_active' => true]);
|
||||
$admin->assignRole('admin');
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
test('the legal queue lists open termination requests', function () {
|
||||
$termination = TerminationRequest::factory()->extraordinary()->create([
|
||||
'name' => 'Paula Presse',
|
||||
'email' => 'paula@example.test',
|
||||
'contract_reference' => 'STR-2026-0042',
|
||||
'reason' => 'Wiederholte Störung der Leistung.',
|
||||
]);
|
||||
|
||||
Volt::actingAs(terminationAdmin())
|
||||
->test('admin.legal-requests.index')
|
||||
->assertOk()
|
||||
->assertSee('Kündigungen')
|
||||
->assertSee('K-'.$termination->id)
|
||||
->assertSee('Paula Presse')
|
||||
->assertSee('paula@example.test')
|
||||
->assertSee('STR-2026-0042')
|
||||
->assertSee('Außerordentlich');
|
||||
});
|
||||
|
||||
test('an admin can resolve a termination request', function () {
|
||||
$termination = TerminationRequest::factory()->create();
|
||||
|
||||
Volt::actingAs(terminationAdmin())
|
||||
->test('admin.legal-requests.index')
|
||||
->call('resolveTermination', $termination->id)
|
||||
->assertOk();
|
||||
|
||||
$termination->refresh();
|
||||
|
||||
expect($termination->status)->toBe('resolved');
|
||||
expect($termination->resolved_at)->not->toBeNull();
|
||||
});
|
||||
|
||||
test('an admin can reopen a resolved termination request', function () {
|
||||
$termination = TerminationRequest::factory()->resolved()->create();
|
||||
|
||||
Volt::actingAs(terminationAdmin())
|
||||
->test('admin.legal-requests.index')
|
||||
->set('terminationStatusFilter', 'all')
|
||||
->call('reopenTermination', $termination->id)
|
||||
->assertOk();
|
||||
|
||||
$termination->refresh();
|
||||
|
||||
expect($termination->status)->toBe('open');
|
||||
expect($termination->resolved_at)->toBeNull();
|
||||
});
|
||||
|
||||
test('resolved terminations are hidden from the default open view', function () {
|
||||
TerminationRequest::factory()->resolved()->create(['name' => 'Erledigte Kündigung']);
|
||||
|
||||
Volt::actingAs(terminationAdmin())
|
||||
->test('admin.legal-requests.index')
|
||||
->assertOk()
|
||||
->assertDontSee('Erledigte Kündigung');
|
||||
});
|
||||
143
tests/Feature/Web/TerminationRequestTest.php
Normal file
143
tests/Feature/Web/TerminationRequestTest.php
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
use App\Mail\TerminationRequestReceived;
|
||||
use App\Mail\TerminationRequestSubmitted;
|
||||
use App\Models\TerminationRequest;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\TestCase;
|
||||
|
||||
test('the hub footer shows the legally required termination button', function () {
|
||||
/** @var TestCase $this */
|
||||
$response = $this->get('https://pressekonto.test/')->assertSuccessful();
|
||||
|
||||
expect($response->getContent())
|
||||
->toContain('Verträge hier kündigen')
|
||||
->toContain(route('kuendigung', ['edition' => 'de']));
|
||||
});
|
||||
|
||||
test('the termination confirmation page renders the § 312k form with the hub shell', function () {
|
||||
/** @var TestCase $this */
|
||||
$response = $this->get('https://pressekonto.test/de/kuendigung')->assertSuccessful();
|
||||
$content = $response->getContent();
|
||||
|
||||
expect($content)
|
||||
// Pflichtangaben der Bestätigungsseite (§ 312k Abs. 2 BGB).
|
||||
->toContain('Ordentliche Kündigung')
|
||||
->toContain('Außerordentliche Kündigung')
|
||||
->toContain('name="kind"')
|
||||
->toContain('name="reason"')
|
||||
->toContain('name="terminate_mode"')
|
||||
->toContain('Zum nächstmöglichen Zeitpunkt')
|
||||
// Bestätigungsschaltfläche mit gesetzeskonformer Aufschrift.
|
||||
->toContain('jetzt kündigen')
|
||||
// Hub-Gerüst (host-aware static-page).
|
||||
->toContain('Publisher · Hub');
|
||||
});
|
||||
|
||||
test('an ordinary termination is persisted and both mails are sent immediately', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
config()->set('domains.domains.pressekonto.brand.contact_email', 'kontakt@pressekonto.de');
|
||||
|
||||
$this->from('https://pressekonto.test/de/kuendigung')
|
||||
->post('https://pressekonto.test/de/kuendigung', [
|
||||
'kind' => 'ordentlich',
|
||||
'name' => 'Paula Presse',
|
||||
'email' => 'paula@example.test',
|
||||
'contract_reference' => 'STR-2026-0042',
|
||||
'terminate_mode' => 'asap',
|
||||
])
|
||||
->assertRedirect('https://pressekonto.test/de/kuendigung')
|
||||
->assertSessionHas('termination-status');
|
||||
|
||||
$request = TerminationRequest::query()->firstOrFail();
|
||||
|
||||
expect($request->kind)->toBe('ordentlich');
|
||||
expect($request->reason)->toBeNull();
|
||||
expect($request->name)->toBe('Paula Presse');
|
||||
expect($request->email)->toBe('paula@example.test');
|
||||
expect($request->contract_reference)->toBe('STR-2026-0042');
|
||||
expect($request->terminate_at)->toBeNull();
|
||||
expect($request->host)->toBe('pressekonto.test');
|
||||
expect($request->status)->toBe('open');
|
||||
|
||||
// § 312k Abs. 4 BGB: sofortige automatische Zugangsbestätigung.
|
||||
Mail::assertSent(TerminationRequestReceived::class, fn (TerminationRequestReceived $mail) => $mail->hasTo('paula@example.test'));
|
||||
Mail::assertSent(TerminationRequestSubmitted::class, fn (TerminationRequestSubmitted $mail) => $mail->hasTo('kontakt@pressekonto.de'));
|
||||
});
|
||||
|
||||
test('an extraordinary termination requires a reason', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
|
||||
$this->post('https://pressekonto.test/de/kuendigung', [
|
||||
'kind' => 'ausserordentlich',
|
||||
'name' => 'Paula Presse',
|
||||
'email' => 'paula@example.test',
|
||||
'terminate_mode' => 'asap',
|
||||
])->assertSessionHasErrorsIn('termination', ['reason']);
|
||||
|
||||
expect(TerminationRequest::query()->count())->toBe(0);
|
||||
Mail::assertNothingSent();
|
||||
|
||||
$this->post('https://pressekonto.test/de/kuendigung', [
|
||||
'kind' => 'ausserordentlich',
|
||||
'reason' => 'Wiederholte Störung der Leistung.',
|
||||
'name' => 'Paula Presse',
|
||||
'email' => 'paula@example.test',
|
||||
'terminate_mode' => 'asap',
|
||||
])->assertSessionHas('termination-status');
|
||||
|
||||
expect(TerminationRequest::query()->firstOrFail()->reason)->toBe('Wiederholte Störung der Leistung.');
|
||||
});
|
||||
|
||||
test('a termination to a specific date requires and persists the date', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
|
||||
$this->post('https://pressekonto.test/de/kuendigung', [
|
||||
'kind' => 'ordentlich',
|
||||
'name' => 'Paula Presse',
|
||||
'email' => 'paula@example.test',
|
||||
'terminate_mode' => 'date',
|
||||
])->assertSessionHasErrorsIn('termination', ['terminate_at']);
|
||||
|
||||
$this->post('https://pressekonto.test/de/kuendigung', [
|
||||
'kind' => 'ordentlich',
|
||||
'name' => 'Paula Presse',
|
||||
'email' => 'paula@example.test',
|
||||
'terminate_mode' => 'date',
|
||||
'terminate_at' => '2026-08-31',
|
||||
])->assertSessionHas('termination-status');
|
||||
|
||||
expect(TerminationRequest::query()->firstOrFail()->terminate_at->format('Y-m-d'))->toBe('2026-08-31');
|
||||
});
|
||||
|
||||
test('termination validation errors land in the termination error bag', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
|
||||
$this->post('https://pressekonto.test/de/kuendigung', [
|
||||
'name' => '',
|
||||
'email' => 'keine-mail',
|
||||
])->assertSessionHasErrorsIn('termination', ['kind', 'name', 'email', 'terminate_mode']);
|
||||
|
||||
expect(TerminationRequest::query()->count())->toBe(0);
|
||||
Mail::assertNothingSent();
|
||||
});
|
||||
|
||||
test('honeypot submissions are silently accepted without persisting or mailing', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
|
||||
$this->post('https://pressekonto.test/de/kuendigung', [
|
||||
'kind' => 'ordentlich',
|
||||
'name' => 'Bot',
|
||||
'email' => 'bot@example.test',
|
||||
'terminate_mode' => 'asap',
|
||||
'website' => 'https://spam.example',
|
||||
])->assertSessionHas('termination-status');
|
||||
|
||||
expect(TerminationRequest::query()->count())->toBe(0);
|
||||
Mail::assertNothingSent();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue