Booking path 1 (offer + guest acceptance), 2FA for all, privacy hardening, brand graphics in theme

- Offer workflow: "Angebot senden" in the admin (dates, guests, promo code, manual price adjustment,
  validity from the property's hold time, message, guest data for the contract) with live price;
  contract draft PDF; signed, versioned offer page for the guest to accept (acceptance record without
  IP) or decline; expiry job, landlord notifications, editable offer texts, wording on the website.
- 2FA is mandatory for every admin account.
- Privacy: complete anonymisation (notes, attribution, review names, offer messages), shorter
  periods for unbinding requests, portal mail excerpts and attribution (configurable proposals),
  iCal summary not stored, known e-mail no longer overwrites guest data, security headers, bearer
  tokens for automations, metadata stripped from photo originals, review link throttled.
- Daily database backup (backup:database) and scripts/backup-pull.sh for the NAS.
- Theme: brand mark in header/footer, favicon/touch icon, wave divider, icons, illustration as
  image placeholder; navy follows the text colour for dark appearances.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 21:38:22 +02:00
1 parent 82698f8eda
commit 4f69b426a4
77 files changed
+1658 -108

No files matched your search

+191
View File
@@ -0,0 +1,191 @@
<?php
namespace Tests\Feature;
use App\Actions\ExpireReservations;
use App\Actions\SendOffer;
use App\Availability\AvailabilityChecker;
use App\Enums\BookingStatus;
use App\Enums\QuoteLineType;
use App\Filament\Resources\Bookings\Pages\ViewBooking;
use App\Mail\BookingConfirmed;
use App\Mail\OfferAnswered;
use App\Mail\OfferMade;
use App\Models\Booking;
use App\Models\Property;
use App\Models\SpecialOffer;
use App\Models\User;
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\Support\Facades\URL;
use Livewire\Livewire;
use Tests\TestCase;
class OfferWorkflowTest extends TestCase
{
use RefreshDatabase;
private Property $property;
private Booking $booking;
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();
$this->booking = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create([
'arrival' => '2026-11-07',
'departure' => '2026-11-10',
'guests' => 2,
]);
}
public function test_offer_recalculates_the_price_with_adjustment_and_promo_code_and_updates_the_guest(): void
{
SpecialOffer::factory()->for($this->property)->create(['name' => 'Stammgast', 'code' => 'OSTSEE', 'discount_value' => 10]);
$offer = app(SendOffer::class)->handle($this->booking, [
'departure' => '2026-11-11',
'promo_code' => 'ostsee',
'price_adjustment' => -2000,
'price_adjustment_label' => 'Nachlass für Wiederkehrer',
'valid_until' => '2026-10-25 18:00',
'offer_message' => 'Wir freuen uns auf Sie!',
'guest' => ['first_name' => 'Erika', 'last_name' => 'Musterfrau', 'street' => 'Seeweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn'],
]);
$lines = collect($offer->quote['lines']);
$this->assertSame(BookingStatus::OfferSent, $offer->status);
$this->assertSame([1, '2026-11-11', 'ostsee', -2000], [$offer->offer_version, $offer->departure->toDateString(), $offer->promo_code, $offer->price_adjustment]);
$this->assertSame('2026-10-25 18:00', $offer->hold_expires_at->format('Y-m-d H:i'));
$this->assertTrue($lines->contains(fn (array $line): bool => $line['label'] === 'Stammgast' && $line['amount'] < 0));
$this->assertTrue($lines->contains(fn (array $line): bool => $line['type'] === QuoteLineType::Adjustment->value && $line['amount'] === -2000 && $line['label'] === 'Nachlass für Wiederkehrer'));
$this->assertSame($lines->sum('amount'), $offer->total);
$this->assertSame(['Erika', 'Kühlungsborn'], [$offer->guest->first_name, $offer->guest->city]);
Storage::disk('local')->assertExists($offer->offer_path);
Mail::assertSent(OfferMade::class, fn (OfferMade $mail): bool => $mail->hasTo($offer->guest->email) && str_contains($mail->offerUrl, 'signature='));
}
public function test_guest_accepts_the_offer_and_the_booking_becomes_binding(): void
{
$url = $this->sendOffer();
$this->get($url)->assertOk()->assertSee('Angebot zahlungspflichtig annehmen')->assertSee('Gesamtpreis')->assertSee('Gesamtbetrag');
$acceptUrl = $this->formAction($url, 'annehmen');
$this->post($acceptUrl, [])->assertSessionHasErrors('terms');
$this->followingRedirects()->post($acceptUrl, ['terms' => '1'])->assertOk()->assertSee('Ihre Buchung ist verbindlich');
$booking = $this->booking->fresh();
$this->assertSame(BookingStatus::Confirmed, $booking->status);
$this->assertNotNull($booking->accepted_at);
$this->assertSame(1, $booking->acceptance['offer_version']);
$this->assertSame($booking->total, $booking->acceptance['total']);
Storage::disk('local')->assertExists($booking->contract_path);
Mail::assertSent(BookingConfirmed::class);
Mail::assertSent(OfferAnswered::class, fn (OfferAnswered $mail): bool => $mail->accepted);
$html = $this->get($url)->getContent();
preg_match('~<main.*</main>~s', $html, $m);
dump(strip_tags($m[0] ?? substr($html, 0, 3000)));
}
public function test_link_of_an_older_offer_version_cannot_be_used(): void
{
$oldUrl = $this->sendOffer();
$this->sendOffer();
$this->get($oldUrl)->assertOk()->assertSee('aktualisiertes Angebot')->assertDontSee('Angebot zahlungspflichtig annehmen');
$this->post(URL::temporarySignedRoute('offers.accept', now()->addDay(), ['booking' => $this->booking, 'v' => 1]), ['terms' => '1']);
$this->assertSame(BookingStatus::OfferSent, $this->booking->fresh()->status);
}
public function test_offer_holds_the_dates_until_it_expires(): void
{
$url = $this->sendOffer(['valid_until' => '2026-10-24 10:00']);
$availability = new AvailabilityChecker;
$this->assertFalse($availability->isAvailable($this->property, $this->booking->arrival, $this->booking->departure));
$this->travelTo(CarbonImmutable::parse('2026-10-24 11:00'));
$this->assertTrue($availability->isAvailable($this->property, $this->booking->arrival, $this->booking->departure));
$this->assertSame(1, app(ExpireReservations::class)->handle());
$this->assertSame(BookingStatus::Expired, $this->booking->fresh()->status);
$this->get($url)->assertForbidden();
}
public function test_guest_declines_the_offer(): void
{
$url = $this->sendOffer();
$this->post($this->formAction($url, 'ablehnen'))->assertRedirect();
$booking = $this->booking->fresh();
$this->assertSame([BookingStatus::Declined, 'guest'], [$booking->status, $booking->declined_by]);
$this->assertTrue((new AvailabilityChecker)->isAvailable($this->property, $booking->arrival, $booking->departure));
Mail::assertSent(OfferAnswered::class, fn (OfferAnswered $mail): bool => ! $mail->accepted);
}
public function test_offer_page_needs_a_valid_signature(): void
{
$this->sendOffer();
$this->get('/angebot/'.$this->booking->id.'?v=1')->assertForbidden();
$this->post('/angebot/'.$this->booking->id.'/annehmen?v=1', ['terms' => '1'])->assertForbidden();
}
public function test_landlord_sends_the_offer_from_the_booking_page(): void
{
$this->actingAs(User::factory()->create());
Livewire::test(ViewBooking::class, ['record' => $this->booking->getRouteKey()])
->callAction('sendOffer', [
'arrival' => '2026-11-07',
'departure' => '2026-11-10',
'guests' => 2,
'price_adjustment' => '-25.50',
'price_adjustment_label' => 'Sonderpreis',
'valid_until' => '2026-10-26 12:00',
'guest' => ['first_name' => 'Max', 'last_name' => 'Muster'],
])
->assertHasNoFormErrors()
->assertNotified('Angebot gesendet');
$this->assertSame([BookingStatus::OfferSent, -2550], [$this->booking->fresh()->status, $this->booking->fresh()->price_adjustment]);
Mail::assertSent(OfferMade::class);
}
/**
* @param array<string, mixed> $changes
*/
private function sendOffer(array $changes = []): string
{
$send = app(SendOffer::class);
$booking = $send->handle($this->booking->fresh(), $changes);
return $send->offerUrl($booking);
}
/**
* The signed form action of the offer page ("annehmen" or "ablehnen").
*/
private function formAction(string $pageUrl, string $action): string
{
preg_match('~action="([^"]*/'.$action.'[^"]*)"~', $this->get($pageUrl)->getContent(), $match);
$this->assertNotEmpty($match, "form for {$action} not found");
return html_entity_decode($match[1]);
}
}
+139
View File
@@ -0,0 +1,139 @@
<?php
namespace Tests\Feature;
use App\Actions\AnonymizeGuests;
use App\Actions\CreateReservation;
use App\Enums\BookingStatus;
use App\Enums\PortalEmailStatus;
use App\Enums\PortalEmailType;
use App\Models\Booking;
use App\Models\Channel;
use App\Models\Guest;
use App\Models\Photo;
use App\Models\PortalEmail;
use App\Models\Property;
use App\Models\Review;
use App\Pricing\StayRequest;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class PrivacyHardeningTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
Mail::fake();
}
public function test_anonymisation_also_removes_notes_attribution_and_review_details(): void
{
$booking = Booking::factory()->create(['internal_notes' => 'ruft abends an', 'utm_source' => 'newsletter', 'offer_message' => 'Hallo Frau Muster']);
$review = Review::factory()->create(['booking_id' => $booking->id, 'display_name' => 'Erika M.', 'private_feedback' => 'Nachbar laut']);
$booking->guest->anonymize();
$booking->refresh();
$this->assertSame([null, null, null], [$booking->internal_notes, $booking->utm_source, $booking->offer_message]);
$this->assertSame(['Gast', null], [$review->fresh()->display_name, $review->fresh()->private_feedback]);
}
public function test_guests_with_only_unbinding_requests_are_anonymised_after_the_inquiry_period(): void
{
$inquiry = Booking::factory()->create(['status' => BookingStatus::Expired, 'confirmed_at' => null]);
$customer = Booking::factory()->create(['status' => BookingStatus::Completed, 'confirmed_at' => now()]);
Guest::query()->update(['updated_at' => now()]);
Booking::query()->update(['updated_at' => now()]);
$this->travel(7)->months();
app(AnonymizeGuests::class)->handle();
$this->assertNotNull($inquiry->guest->fresh()->anonymized_at);
$this->assertNull($customer->guest->fresh()->anonymized_at);
}
public function test_portal_mail_excerpts_and_old_attribution_are_removed_after_their_periods(): void
{
$mail = PortalEmail::query()->create(['channel_id' => Channel::factory()->create()->id, 'message_id' => 'x@portal', 'from' => 'noreply@portal.example', 'subject' => 'Neue Buchung', 'received_at' => now(), 'type' => PortalEmailType::Booking, 'status' => PortalEmailStatus::Blocked, 'excerpt' => 'Gast: Erika Musterfrau']);
$booking = Booking::factory()->create(['utm_source' => 'instagram', 'referral_source' => null]);
$this->travel(100)->days();
app(AnonymizeGuests::class)->handle();
$this->assertNull($mail->fresh()->excerpt);
$this->assertSame('instagram', $booking->fresh()->utm_source);
$this->travel(2)->years();
app(AnonymizeGuests::class)->handle();
$this->assertNull($booking->fresh()->utm_source);
}
public function test_request_with_a_known_email_does_not_overwrite_the_guest_file(): void
{
$this->seed(PropertySeeder::class);
$guest = Guest::factory()->create(['email' => 'erika@example.com', 'first_name' => 'Erika', 'last_name' => 'Muster', 'city' => 'Rostock', 'phone' => null]);
$booking = app(CreateReservation::class)->handle(
Property::sole(),
new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2),
['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'Erika@Example.com', 'city' => 'Berlin', 'phone' => '0170 1'],
sendMails: false,
);
$guest->refresh();
$this->assertSame($guest->id, $booking->guest_id);
$this->assertSame(['Rostock', '0170 1'], [$guest->city, $guest->phone], 'existing data stays, empty fields are completed');
$this->assertStringContainsString('Ort: Berlin (Kartei: Rostock)', $booking->internal_notes);
}
public function test_automation_tokens_are_accepted_as_bearer_header(): void
{
config(['fewo.scheduler_token' => 'geheim']);
$this->get('/automation/scheduler', ['Authorization' => 'Bearer geheim'])->assertOk();
$this->get('/automation/scheduler', ['Authorization' => 'Bearer falsch'])->assertNotFound();
}
public function test_responses_carry_security_headers(): void
{
$this->get('/up')
->assertHeader('X-Content-Type-Options', 'nosniff')
->assertHeader('X-Frame-Options', 'SAMEORIGIN')
->assertHeader('Referrer-Policy', 'strict-origin-when-cross-origin');
}
public function test_uploaded_photo_originals_are_stripped_of_metadata(): void
{
Storage::fake('public');
$photo = Photo::factory()->create();
$media = $photo->addMedia(UploadedFile::fake()->image('drohne.jpg', 1200, 800))->toMediaCollection(Photo::COLLECTION);
$this->assertTrue($media->fresh()->getCustomProperty('metadata_stripped'));
$this->artisan('photos:strip-metadata')->expectsOutputToContain('0 Original-Foto(s) bereinigt.')->assertSuccessful();
}
public function test_database_backup_is_written_and_rotated(): void
{
Storage::fake('local');
Guest::factory()->create(['last_name' => "O'Brien"]);
$this->artisan('backup:database', ['--keep' => 1])->assertSuccessful();
$this->travel(1)->minutes();
$this->artisan('backup:database', ['--keep' => 1])->assertSuccessful();
$files = Storage::disk('local')->files('backups');
$this->assertCount(1, $files);
$dump = gzdecode(Storage::disk('local')->get($files[0]));
$this->assertStringContainsString('CREATE TABLE "guests"', $dump);
$this->assertStringContainsString("O''Brien", $dump);
}
}
@@ -31,11 +31,12 @@ public function test_admin_with_two_factor_enters_the_admin(): void
$this->get(BookingResource::getUrl('index'))->assertOk();
}
public function test_other_roles_may_work_without_two_factor(): void
public function test_every_role_must_set_up_two_factor(): void
{
$this->actingAs(User::factory()->role(UserRole::Rentals)->withoutTwoFactor()->create());
$this->get(BookingResource::getUrl('index'))->assertOk();
$this->get(BookingResource::getUrl('index'))
->assertRedirect(Filament::getPanel('admin')->getSetUpRequiredMultiFactorAuthenticationUrl());
}
public function test_two_factor_secret_is_stored_encrypted(): void