113 lines
5.7 KiB
PHP
113 lines
5.7 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature\Process;
|
||
|
||
use App\Actions\ContributeCaseFacts;
|
||
use App\Actions\ProcessPortalMail;
|
||
use App\Actions\SendBookingReminders;
|
||
use App\Actions\TakeOverExternalBooking;
|
||
use App\Channels\Mail\PortalMail;
|
||
use App\Enums\BookingStatus;
|
||
use App\Enums\BookingTaskKind;
|
||
use App\Enums\BookingTaskStatus;
|
||
use App\Enums\FactSource;
|
||
use App\Models\Booking;
|
||
use App\Models\BookingTask;
|
||
use App\Models\Channel;
|
||
use App\Models\Property;
|
||
use App\Process\CaseAutomation;
|
||
use App\Process\OutwardSuspension;
|
||
use App\Support\Content;
|
||
use App\Support\Settings;
|
||
use Carbon\CarbonImmutable;
|
||
use Database\Seeders\PropertySeeder;
|
||
use Database\Seeders\SiteSeeder;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Illuminate\Mail\MailManager;
|
||
use Illuminate\Support\Facades\Http;
|
||
use Illuminate\Support\Facades\Mail;
|
||
use Illuminate\Support\Facades\Storage;
|
||
use PHPUnit\Framework\Attributes\Group;
|
||
use Tests\TestCase;
|
||
|
||
/**
|
||
* Decision O4 (intended deviation I-002): an open portal report of a cancellation or change, reliably assigned to a
|
||
* case, holds back the automatic messages it could make wrong – documents, arrival information, review request – until
|
||
* the landlord has clarified it. Internal work goes on, the booking itself is never changed by the report, and
|
||
* unassigned portal mails stop nothing.
|
||
*/
|
||
#[Group('runner')]
|
||
class PortalReportSuspendsAutomationTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
private Property $property;
|
||
|
||
private Channel $portal;
|
||
|
||
protected function setUp(): void
|
||
{
|
||
parent::setUp();
|
||
|
||
$this->travelTo(CarbonImmutable::parse('2026-10-23 18:00'));
|
||
$this->seed([PropertySeeder::class, SiteSeeder::class]);
|
||
$this->property = Property::sole();
|
||
Storage::fake('local');
|
||
Content::save(['contract.terms' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
|
||
config(['mail.default' => 'array']);
|
||
Mail::swap(new MailManager($this->app));
|
||
Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'test@example.org', 'process_defaults' => ['processing' => 'automatic']]);
|
||
Http::preventStrayRequests();
|
||
$this->portal = Channel::factory()->for($this->property)->create(['name' => 'Destination Solutions', 'booking_model' => 'portal_booking', 'import_enabled' => false, 'settings' => ['import_url' => 'https://ds.example/a.ics', 'email_senders' => 'ds.example']]);
|
||
}
|
||
|
||
public function test_documents_wait_while_a_cancellation_report_is_open_and_go_after_clarification(): void
|
||
{
|
||
$booking = app(TakeOverExternalBooking::class)->handle($this->property, $this->portal, CarbonImmutable::parse('2026-12-05'), CarbonImmutable::parse('2026-12-12'), ['portal_reference' => 'DS-9', 'portal_total' => 98000, 'guests' => 2]);
|
||
$task = $this->report($booking);
|
||
|
||
app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.first_name' => 'Dora', 'guest.last_name' => 'Gast', 'guest.email' => 'dora@example.org'], FactSource::PortalMail);
|
||
|
||
$booking->refresh();
|
||
$this->assertNull($booking->confirmation_sent_at, 'no documents while the report is open');
|
||
$this->assertSame(BookingStatus::Confirmed, $booking->status, 'the report never changes the booking');
|
||
$held = app(CaseAutomation::class)->advance($booking->fresh());
|
||
$this->assertSame([OutwardSuspension::reason($booking)], $held, 'the documents wait only for the clarification');
|
||
|
||
$task->update(['status' => BookingTaskStatus::Done, 'completed_at' => now(), 'note' => 'Portal bestätigt: keine Stornierung']);
|
||
$held = app(CaseAutomation::class)->advance($booking->fresh());
|
||
|
||
// After clarification the step is evaluated from the case's current state again: here the documents' own
|
||
// release rules (portal template, released texts) decide, no longer the report.
|
||
$this->assertNotContains(OutwardSuspension::reason($booking), $held);
|
||
$this->assertStringContainsString('Arbeitsfassung', implode(' ', $held));
|
||
}
|
||
|
||
public function test_arrival_information_waits_but_internal_tasks_go_on(): void
|
||
{
|
||
$booking = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => now()->addDays(2)->toDateString(), 'departure' => now()->addDays(6)->toDateString(), 'deposit_due_on' => now()->subDay()->toDateString(), 'confirmed_at' => now()]);
|
||
$this->report($booking);
|
||
|
||
app(SendBookingReminders::class)->handle();
|
||
|
||
$this->assertNull($booking->fresh()->arrival_info_sent_at);
|
||
$this->assertTrue(BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::DepositReminder)->exists(), 'internal tasks are not blocked');
|
||
}
|
||
|
||
public function test_an_unassigned_portal_mail_suspends_nothing(): void
|
||
{
|
||
$booking = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => now()->addDays(2)->toDateString(), 'departure' => now()->addDays(6)->toDateString(), 'confirmed_at' => now()]);
|
||
|
||
app(ProcessPortalMail::class)->handle(new PortalMail('<x@ds.example>', 'noreply@ds.example', 'Buchung storniert: UNBEKANNT-1', 'Die Buchung vom 01.03.2027 bis 05.03.2027 wurde storniert.', CarbonImmutable::now()));
|
||
app(SendBookingReminders::class)->handle();
|
||
|
||
$this->assertNull(OutwardSuspension::reason($booking));
|
||
$this->assertNotNull($booking->fresh()->arrival_info_sent_at);
|
||
}
|
||
|
||
private function report(Booking $booking): BookingTask
|
||
{
|
||
return BookingTask::query()->create(['booking_id' => $booking->id, 'kind' => BookingTaskKind::PortalCancellationReported, 'status' => BookingTaskStatus::Open, 'title' => 'Portal meldet Stornierung']);
|
||
}
|
||
}
|