Gästeverzeichnis und Customer Voice
- Gäste: Markierungen, Aufenthalte & Umsatz, Stammgast-/Einwilligungsfilter, CSV-Export, Anonymisierung (manuell + automatisch nach Aufbewahrungsfrist) - Werbe-Einwilligung per Double-Opt-in aus dem Anfrageformular, signierte Bestätigungs-/Abmeldelinks - Bewertungen: automatische Einladung nach Abreise, Bewertungsformular mit Kategorien und internem Feedback, Freigabe und öffentliche Antwort im Admin - Konzept: Rollen, Inhalte, Customer Voice, Architektur Portal-Sync/Buchungshoheit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bb7eb62782
commit
2892e6aeab
44 files changed
+1505
-23
No files matched your search
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Actions\AnonymizeGuests;
|
||||
use App\Actions\RequestReviews;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\ReviewStatus;
|
||||
use App\Enums\UserRole;
|
||||
use App\Filament\Resources\Guests\GuestResource;
|
||||
use App\Filament\Resources\Guests\Pages\EditGuest;
|
||||
use App\Filament\Resources\Guests\Pages\ListGuests;
|
||||
use App\Filament\Resources\Reviews\Pages\ListReviews;
|
||||
use App\Filament\Resources\Reviews\ReviewResource;
|
||||
use App\Livewire\BookingRequest;
|
||||
use App\Livewire\ReviewForm;
|
||||
use App\Mail\MarketingConsentRequest;
|
||||
use App\Mail\NewReview;
|
||||
use App\Mail\ReviewRequest;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Guest;
|
||||
use App\Models\Property;
|
||||
use App\Models\Review;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GuestRelationsTest 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);
|
||||
$this->property = Property::sole();
|
||||
Mail::fake();
|
||||
}
|
||||
|
||||
public function test_review_invitation_is_sent_once_after_departure(): void
|
||||
{
|
||||
$due = $this->stay('2026-10-13', '2026-10-20');
|
||||
$this->stay('2026-10-15', '2026-10-21');
|
||||
$this->stay('2026-08-01', '2026-08-08');
|
||||
Booking::factory()->for($this->property)->create(['status' => BookingStatus::Cancelled, 'arrival' => '2026-10-10', 'departure' => '2026-10-17']);
|
||||
|
||||
$this->assertSame(1, (new RequestReviews)->handle());
|
||||
$this->assertSame(0, (new RequestReviews)->handle());
|
||||
|
||||
Mail::assertSent(ReviewRequest::class, fn (ReviewRequest $mail): bool => $mail->hasTo($due->guest->email));
|
||||
$this->assertNotNull($due->fresh()->review_requested_at);
|
||||
}
|
||||
|
||||
public function test_guest_submits_a_review_through_the_signed_link(): void
|
||||
{
|
||||
$booking = $this->stay('2026-10-13', '2026-10-20');
|
||||
$url = URL::temporarySignedRoute('reviews.create', now()->addDays(90), $booking);
|
||||
|
||||
$this->withoutVite()->get($url)->assertOk()->assertSeeLivewire(ReviewForm::class);
|
||||
$this->withoutVite()->get(route('reviews.create', $booking))->assertForbidden();
|
||||
|
||||
Livewire::test(ReviewForm::class, ['booking' => $booking])
|
||||
->set('rating', 5)
|
||||
->set('categories.rating_cleanliness', 4)
|
||||
->set('body', 'Wunderbar ruhig, wir kommen wieder.')
|
||||
->set('privateFeedback', 'Der Toaster ist alt.')
|
||||
->call('submit')
|
||||
->assertSee('Herzlichen Dank');
|
||||
|
||||
$review = Review::sole();
|
||||
$this->assertSame([ReviewStatus::Pending, 5, 4, 'website'], [$review->status, $review->rating, $review->rating_cleanliness, $review->source]);
|
||||
$this->assertSame(0, Review::published()->count());
|
||||
Mail::assertSent(NewReview::class);
|
||||
|
||||
Livewire::test(ReviewForm::class, ['booking' => $booking])->assertSee('bereits eine Bewertung');
|
||||
}
|
||||
|
||||
public function test_approved_reviews_with_consent_are_published(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->role(UserRole::Content)->create());
|
||||
$review = Review::factory()->for($this->property)->create();
|
||||
Review::factory()->for($this->property)->create(['publish_consent' => false, 'status' => ReviewStatus::Approved]);
|
||||
|
||||
$this->get(ReviewResource::getUrl('index'))->assertOk();
|
||||
Livewire::test(ListReviews::class)->callTableAction('approve', $review);
|
||||
|
||||
$this->assertNotNull($review->fresh()->approved_at);
|
||||
$this->assertSame([$review->id], Review::published()->pluck('id')->all());
|
||||
}
|
||||
|
||||
public function test_marketing_opt_in_is_confirmed_by_double_opt_in(): void
|
||||
{
|
||||
Livewire::test(BookingRequest::class)
|
||||
->set('arrival', '2026-11-07')
|
||||
->set('departure', '2026-11-10')
|
||||
->set('firstName', 'Anna')
|
||||
->set('lastName', 'Muster')
|
||||
->set('email', 'anna@example.com')
|
||||
->set('privacyAccepted', true)
|
||||
->set('marketingOptIn', true)
|
||||
->call('submit');
|
||||
|
||||
$guest = Guest::sole();
|
||||
$this->assertNull($guest->marketing_consent_at);
|
||||
Mail::assertSent(MarketingConsentRequest::class);
|
||||
|
||||
$this->withoutVite()->get(URL::temporarySignedRoute('marketing.confirm', now()->addDay(), $guest))->assertOk()->assertSee('Anmeldung bestätigt');
|
||||
$this->assertNotNull($guest->fresh()->marketing_consent_at);
|
||||
|
||||
$this->withoutVite()->get(URL::signedRoute('marketing.unsubscribe', $guest))->assertOk();
|
||||
$this->assertNull($guest->fresh()->marketing_consent_at);
|
||||
}
|
||||
|
||||
public function test_guests_are_anonymized_after_the_retention_period(): void
|
||||
{
|
||||
$old = $this->stay('2015-07-01', '2015-07-08')->guest;
|
||||
$old->forceFill(['created_at' => '2015-06-01'])->save();
|
||||
$recent = $this->stay('2026-07-01', '2026-07-08')->guest;
|
||||
|
||||
$this->assertSame(1, (new AnonymizeGuests)->handle());
|
||||
|
||||
$old->refresh();
|
||||
$this->assertNotNull($old->anonymized_at);
|
||||
$this->assertSame('Anonymisiert', $old->first_name);
|
||||
$this->assertNull($old->phone);
|
||||
$this->assertNull($recent->fresh()->anonymized_at);
|
||||
$this->assertSame(1, $old->bookings()->count());
|
||||
}
|
||||
|
||||
public function test_admin_sees_guest_history_and_can_export_and_anonymize(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
$guest = $this->stay('2026-07-01', '2026-07-08')->guest;
|
||||
$guest->update(['tags' => ['Stammgast']]);
|
||||
|
||||
$this->get(GuestResource::getUrl('edit', ['record' => $guest]))->assertOk();
|
||||
Livewire::test(ListGuests::class)->callAction('export', ['consent_only' => false])->assertFileDownloaded('gaeste-2026-10-22.csv');
|
||||
Livewire::test(EditGuest::class, ['record' => $guest->getRouteKey()])->callAction('anonymize');
|
||||
|
||||
$this->assertNotNull($guest->fresh()->anonymized_at);
|
||||
}
|
||||
|
||||
public function test_rentals_role_cannot_anonymize(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->role(UserRole::Rentals)->create());
|
||||
$guest = $this->stay('2026-07-01', '2026-07-08')->guest;
|
||||
|
||||
Livewire::test(EditGuest::class, ['record' => $guest->getRouteKey()])->assertActionHidden('anonymize');
|
||||
}
|
||||
|
||||
private function stay(string $arrival, string $departure): Booking
|
||||
{
|
||||
return Booking::factory()->for($this->property)->create([
|
||||
'status' => BookingStatus::Paid,
|
||||
'arrival' => $arrival,
|
||||
'departure' => $departure,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user