Zahlungsaufgaben, Freigabe-/Storno-Link, Vertragsvorlagen, Anreise-Mail
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m36s

- Zahlungen werden nicht mehr automatisch angemahnt: faellige Anzahlung/Restzahlung werden Aufgaben
  (Zahlungen & Wuensche, Tages-/Wochenuebersicht); Mail nur per Klick; je Portal und Buchungstyp abschaltbar
- Freigabe-Link in der Eingangsbestaetigung, Storno-Link in der Buchungsbestaetigung; je Wohnung
  Wunsch / sofort / sofort bis Frist; Stornowuensche und Kosten bleiben Aufgabe des Gastgebers
- Vertragsvorlagen mit Versionen (je Angebot, Portal oder Wohnung waehlbar), benutzte Versionen gesperrt;
  Angebot und finaler Vertrag als unveraenderliche PDF mit SHA-256, Vertrag wird nie neu geschrieben
- Anreise-Mail je Wohnung einstellbar (Standard 3 Tage), neue Textfelder Schluessel/Parken/Ankunftstag

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-10-30 12:46:29 +01:00
1 parent eafab8a2cb
commit a73b164ea1
51 files changed
+1807 -52

No files matched your search

+138
View File
@@ -0,0 +1,138 @@
<?php
namespace Tests\Feature;
use App\Actions\AcceptOffer;
use App\Actions\ConfirmBooking;
use App\Actions\SendOffer;
use App\Documents\RentalContract;
use App\Filament\Resources\ContractTemplates\ContractTemplateResource;
use App\Filament\Resources\ContractTemplates\Pages\ListContractTemplates;
use App\Models\Booking;
use App\Models\Channel;
use App\Models\ContractTemplate;
use App\Models\Property;
use App\Models\User;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\SiteSeeder;
use Filament\Actions\Testing\TestAction;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
/**
* Contract templates with versions and the documents of record (stored PDFs with fingerprint).
*/
class ContractTemplateTest extends TestCase
{
use RefreshDatabase;
private Property $property;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed([PropertySeeder::class, SiteSeeder::class]);
$this->property = Property::sole();
Mail::fake();
Storage::fake('local');
$this->withoutVite();
}
public function test_offer_uses_the_chosen_template_and_freezes_it_with_name_and_version(): void
{
$template = $this->template('Portal XY', ['terms' => '<p>Bedingungen Portal XY</p>', 'cancellation' => '<p>Storno bis 30 Tage</p>']);
$offer = $this->offer(['contract_template_id' => $template->id]);
$this->assertSame('Bedingungen Portal XY', trim(strip_tags($offer->offerText('contract.terms'))));
$this->assertSame(['id' => $template->id, 'name' => 'Portal XY', 'version' => 1], $offer->offer_terms['template']);
$this->assertNotNull($offer->offer_pdf_sha256);
// blank template fields fall back to the website text
$this->assertNotEmpty($offer->offerText('contract.closing'));
}
public function test_default_order_is_explicit_choice_then_portal_then_property(): void
{
$propertyDefault = $this->template('Direkt', ['terms' => '<p>DIREKT</p>']);
$portalDefault = $this->template('Portal', ['terms' => '<p>PORTAL</p>']);
$this->property->update(['contract_template_id' => $propertyDefault->id]);
$channel = Channel::factory()->for($this->property)->create(['contract_template_id' => $portalDefault->id]);
$direct = $this->offer();
$viaPortal = $this->offer([], ['import_channel_id' => $channel->id, 'arrival' => '2026-12-01', 'departure' => '2026-12-04']);
$this->assertSame('DIREKT', trim(strip_tags($direct->offerText('contract.terms'))));
$this->assertSame('PORTAL', trim(strip_tags($viaPortal->offerText('contract.terms'))));
}
public function test_editing_a_template_later_does_not_change_a_sent_offer_or_the_contract(): void
{
$template = $this->template('Direkt', ['terms' => '<p>VERSION EINS</p>']);
$offer = $this->offer(['contract_template_id' => $template->id]);
$template->update(['texts' => ['terms' => '<p>GEÄNDERT</p>']]);
app(AcceptOffer::class)->handle($offer->fresh(), 1);
$this->assertSame('VERSION EINS', trim(strip_tags($offer->fresh()->offerText('contract.terms'))));
}
public function test_used_versions_are_locked_and_a_new_version_can_be_made(): void
{
$template = $this->template('Direkt', ['terms' => '<p>A</p>']);
$this->assertTrue(ContractTemplateResource::canEdit($template));
$this->offer(['contract_template_id' => $template->id]);
$this->assertFalse(ContractTemplateResource::canEdit($template->fresh()));
$this->assertFalse(ContractTemplateResource::canDelete($template->fresh()));
$this->actingAs(User::factory()->create());
Livewire::test(ListContractTemplates::class)->callAction(TestAction::make('newVersion')->table($template), []);
$this->assertSame([1, 2], ContractTemplate::query()->where('name', 'Direkt')->orderBy('version')->pluck('version')->all());
$this->assertTrue(ContractTemplateResource::canEdit(ContractTemplate::query()->where('version', 2)->sole()));
}
public function test_final_contract_is_a_document_of_record_that_is_never_rewritten(): void
{
$offer = $this->offer();
app(AcceptOffer::class)->handle($offer->fresh(), 1);
$booking = $offer->fresh();
$content = Storage::disk('local')->get($booking->contract_path);
$this->assertSame(hash('sha256', $content), $booking->contract_pdf_sha256);
$this->travel(3)->days();
app(ConfirmBooking::class)->resend($booking);
app(RentalContract::class)->generate($booking->fresh());
$this->assertSame($content, Storage::disk('local')->get($booking->contract_path));
$this->assertSame($booking->contract_pdf_sha256, $booking->fresh()->contract_pdf_sha256);
}
/**
* @param array<string, string> $texts
*/
private function template(string $name, array $texts): ContractTemplate
{
return ContractTemplate::query()->create(['name' => $name, 'version' => 1, 'texts' => $texts]);
}
/**
* @param array<string, mixed> $changes
* @param array<string, mixed> $attributes
*/
private function offer(array $changes = [], array $attributes = []): Booking
{
$booking = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create([
'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'guests' => 2, ...$attributes,
]);
return app(SendOffer::class)->handle($booking, $changes);
}
}
+6 -2
View File
@@ -4,10 +4,13 @@
use App\Actions\SendDigests;
use App\Enums\BookingStatus;
use App\Enums\BookingTaskKind;
use App\Enums\BookingTaskStatus;
use App\Enums\DigestSection;
use App\Filament\Pages\Operations;
use App\Mail\Digest;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Models\Guest;
use App\Models\InboxMessage;
use App\Models\Property;
@@ -87,7 +90,8 @@ public function test_summary_lists_requests_stays_payments_and_inbox_and_only_th
{
$this->openRequest();
$this->booking(['arrival' => '2026-11-03', 'departure' => '2026-11-07'], 'Erika Mustermann');
$this->booking(['arrival' => '2026-12-01', 'departure' => '2026-12-05', 'balance_due_on' => '2026-10-20', 'created_at' => now()->subWeek()], 'Hans Säumig');
$late = $this->booking(['arrival' => '2026-12-01', 'departure' => '2026-12-05', 'balance_due_on' => '2026-10-20', 'created_at' => now()->subWeek()], 'Hans Säumig');
BookingTask::query()->create(['booking_id' => $late->id, 'kind' => BookingTaskKind::BalanceReminder, 'status' => BookingTaskStatus::Open, 'due_on' => '2026-10-20']);
InboxMessage::factory()->create(['subject' => 'Mögliche Doppelbuchung über FeWo-direkt', 'body' => '<b>Ostsee</b>']);
app(SendDigests::class)->send($this->tenant, weekly: false);
@@ -98,7 +102,7 @@ public function test_summary_lists_requests_stays_payments_and_inbox_and_only_th
return in_array('Offene Anfragen und Angebote', $titles, true)
&& in_array('An- und Abreisen heute und morgen', $titles, true)
&& in_array('Überfällige Zahlungen', $titles, true)
&& in_array('Zahlungsaufgaben und Gästewünsche', $titles, true)
&& str_contains($html, 'Morgen: Anreise')
&& str_contains($html, 'Erika Mustermann')
&& str_contains($html, 'Hans Säumig')
+15 -1
View File
@@ -6,13 +6,17 @@
use App\Actions\CreateReservation;
use App\Actions\RecordPayment;
use App\Actions\SendBookingReminders;
use App\Actions\SendPaymentReminder;
use App\Enums\BookingStatus;
use App\Enums\BookingTaskKind;
use App\Enums\BookingTaskStatus;
use App\Filament\Resources\Bookings\Pages\ViewBooking;
use App\Filament\Resources\Bookings\RelationManagers\PaymentsRelationManager;
use App\Mail\ArrivalInformation;
use App\Mail\BookingConfirmed;
use App\Mail\PaymentReminder;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Models\Property;
use App\Models\User;
use App\Pricing\StayRequest;
@@ -85,7 +89,15 @@ public function test_reminders_are_sent_once_at_the_right_time(): void
$this->travelTo(CarbonImmutable::parse('2026-10-30 09:00'));
$this->assertSame(1, $reminders->handle()['deposit_overdue']);
$this->assertSame(0, $reminders->handle()['deposit_overdue']);
Mail::assertNotSent(PaymentReminder::class);
$task = BookingTask::query()->where('kind', BookingTaskKind::DepositReminder)->sole();
$this->assertSame(BookingTaskStatus::Open, $task->status);
app(SendPaymentReminder::class)->handle($task, 'Test');
Mail::assertSent(PaymentReminder::class, 1);
Mail::assertSent(PaymentReminder::class, fn (PaymentReminder $mail): bool => $mail->kind === PaymentReminder::DEPOSIT_OVERDUE && $mail->hasBcc(config('fewo.notification_email')));
$this->assertSame(BookingTaskStatus::Done, $task->fresh()->status);
$this->assertNotNull($booking->fresh()->deposit_reminded_at);
(new RecordPayment)->handle($booking, $booking->deposit, today());
@@ -97,7 +109,9 @@ public function test_reminders_are_sent_once_at_the_right_time(): void
$this->travelTo(CarbonImmutable::parse('2026-11-04 09:00'));
$this->assertSame(1, $reminders->handle()['balance_overdue']);
$this->travelTo(CarbonImmutable::parse('2026-11-24 09:00'));
$this->travelTo(CarbonImmutable::parse('2026-11-27 09:00'));
$this->assertSame(0, $reminders->handle()['arrival_info'], 'default: 3 days before arrival');
$this->travelTo(CarbonImmutable::parse('2026-11-28 09:00'));
$this->assertSame(1, $reminders->handle()['arrival_info']);
Mail::assertSent(ArrivalInformation::class);
+189
View File
@@ -0,0 +1,189 @@
<?php
namespace Tests\Feature;
use App\Actions\AcceptOffer;
use App\Actions\SendBookingReminders;
use App\Actions\SendOffer;
use App\Enums\BookingStatus;
use App\Enums\BookingTaskKind;
use App\Enums\CancellationMode;
use App\Mail\BookingCancelled;
use App\Mail\BookingConfirmed;
use App\Mail\CancellationRequested;
use App\Mail\PaymentReminder;
use App\Mail\ReservationReceived;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Models\Channel;
use App\Models\Property;
use App\Support\SelfServiceLinks;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\SiteSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use Illuminate\Testing\TestResponse;
use Tests\TestCase;
/**
* Release link (held requests), cancellation link (bookings) and the payment task policy per channel.
*/
class SelfServiceTest extends TestCase
{
use RefreshDatabase;
private Property $property;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed([PropertySeeder::class, SiteSeeder::class]);
$this->property = Property::sole();
Mail::fake();
Storage::fake('local');
$this->withoutVite();
}
public function test_release_link_opens_a_page_and_only_the_button_releases_the_dates(): void
{
$booking = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(['arrival' => '2026-11-07', 'departure' => '2026-11-10']);
$link = SelfServiceLinks::release($booking);
$this->get($link)->assertOk()->assertSee('Zeitraum freigeben');
$this->assertSame(BookingStatus::Reserved, $booking->fresh()->status);
$action = $this->formAction($link, 'freigeben/bestaetigen');
$this->submit($action)->assertOk()->assertSee('wieder freigegeben');
$this->submit($action)->assertOk();
$this->assertSame(BookingStatus::Declined, $booking->fresh()->status);
$this->assertSame(0, Booking::query()->occupying()->count());
}
public function test_release_never_touches_a_binding_booking_and_needs_a_valid_signature(): void
{
$booking = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => '2026-11-07', 'departure' => '2026-11-10']);
$this->get(SelfServiceLinks::release($booking).'x')->assertForbidden();
$this->post(SelfServiceLinks::release($booking))->assertStatus(405);
$this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status);
}
public function test_reservation_mail_contains_the_release_link_only_while_the_dates_are_held(): void
{
$booking = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create();
$this->assertStringContainsString('/freigeben', (new ReservationReceived($booking))->render());
$booking->update(['hold_expires_at' => null]);
$this->assertStringNotContainsString('/freigeben', (new ReservationReceived($booking->fresh()))->render());
}
public function test_confirmation_contains_the_cancellation_link(): void
{
$offer = app(SendOffer::class)->handle(Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(['arrival' => '2026-11-07', 'departure' => '2026-11-10', 'guests' => 2]));
app(AcceptOffer::class)->handle($offer->fresh(), 1);
Mail::assertSent(BookingConfirmed::class, fn (BookingConfirmed $mail): bool => str_contains($mail->render(), '/storno'));
}
public function test_request_mode_only_creates_a_task_and_keeps_the_booking(): void
{
$booking = $this->confirmed();
$link = SelfServiceLinks::cancel($booking);
$this->get($link)->assertOk()->assertSee('Stornierung anfragen');
$action = $this->formAction($link, 'storno/bestaetigen');
$this->submit($action, ['message' => 'Krank'])->assertOk()->assertSee('Stornierungswunsch erhalten');
$this->submit($action)->assertOk()->assertSee('liegt uns bereits vor');
$this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status);
$task = BookingTask::query()->where('kind', BookingTaskKind::CancellationRequest)->sole();
$this->assertSame('Krank', $task->note);
Mail::assertSent(CancellationRequested::class, 1);
Mail::assertSent(BookingCancelled::class, fn (BookingCancelled $mail): bool => ! $mail->cancelled);
}
public function test_instant_mode_cancels_at_once_and_still_leaves_a_task_for_the_costs(): void
{
$this->property->update(['cancellation_mode' => CancellationMode::Instant]);
$booking = $this->confirmed();
$link = SelfServiceLinks::cancel($booking);
$this->submit($this->formAction($link, 'storno/bestaetigen'))->assertOk()->assertSee('storniert');
$this->assertSame(BookingStatus::Cancelled, $booking->fresh()->status);
$this->assertSame(0, Booking::query()->occupying()->count());
$this->assertStringContainsString('Stornokosten', BookingTask::query()->sole()->note);
Mail::assertSent(BookingCancelled::class, fn (BookingCancelled $mail): bool => $mail->cancelled);
}
public function test_free_cancellation_window_switches_between_instant_and_request(): void
{
$this->property->update(['cancellation_mode' => CancellationMode::InstantWhenFree, 'free_cancellation_days' => 14]);
$far = $this->confirmed('2026-12-20', '2026-12-24');
$near = $this->confirmed('2026-11-01', '2026-11-04');
$this->post($this->formAction(SelfServiceLinks::cancel($far), 'storno/bestaetigen'));
$this->post($this->formAction(SelfServiceLinks::cancel($near), 'storno/bestaetigen'));
$this->assertSame(BookingStatus::Cancelled, $far->fresh()->status);
$this->assertSame(BookingStatus::Confirmed, $near->fresh()->status);
}
public function test_payment_tasks_follow_the_channel_policy(): void
{
$own = $this->confirmed();
$reservationPortal = Channel::factory()->for($this->property)->create(['booking_model' => 'portal_booking', 'payment_tasks_reservation' => false]);
$inquiryPortal = Channel::factory()->for($this->property)->create(['booking_model' => 'inquiry', 'payment_tasks_inquiry' => true]);
$portalReservation = $this->confirmed('2026-12-10', '2026-12-14', ['import_channel_id' => $reservationPortal->id, 'source' => 'portal']);
$portalInquiry = $this->confirmed('2026-12-16', '2026-12-18', ['import_channel_id' => $inquiryPortal->id, 'source' => 'portal']);
$this->travelTo(CarbonImmutable::parse('2026-11-30 09:00'));
(new SendBookingReminders)->handle();
$withTasks = BookingTask::query()->pluck('booking_id')->unique()->all();
$this->assertContains($own->id, $withTasks);
$this->assertContains($portalInquiry->id, $withTasks);
$this->assertNotContains($portalReservation->id, $withTasks);
Mail::assertNotSent(PaymentReminder::class);
}
/**
* @param array<string, mixed> $attributes
*/
private function confirmed(string $arrival = '2026-12-01', string $departure = '2026-12-05', array $attributes = []): Booking
{
return Booking::factory()->for($this->property)->create([
'status' => BookingStatus::Confirmed,
'arrival' => $arrival,
'departure' => $departure,
'deposit_due_on' => '2026-10-25',
'balance_due_on' => '2026-11-20',
'total' => 100000,
'deposit' => 30000,
...$attributes,
]);
}
/**
* Posts the form and opens the page it redirects to (the redirect carries the result message in the session).
*
* @param array<string, mixed> $data
*/
private function submit(string $action, array $data = []): TestResponse
{
return $this->get($this->post($action, $data)->headers->get('Location'));
}
private function formAction(string $pageUrl, string $action): string
{
preg_match('~action="([^"]*/'.preg_quote($action, '~').'[^"]*)"~', $this->get($pageUrl)->getContent(), $match);
$this->assertNotEmpty($match, "form for {$action} not found");
return html_entity_decode($match[1]);
}
}