Files
fewo-stommer/tests/Feature/Process/ExtensionAndIndependentStepsTest.php
T
LarsandClaude Sonnet 5.5 221ce8ca81 Anfrage-Basisprozess inquiry.request mit Schablonen für Antwort und Gastkommunikation
Antwortart (Auskunft/Angebot) und Reservierung sind entkoppelt (neue Einstellung inquiry_answer;
pre_reservation bleibt die Reservierungsstrategie). Anlass-bezogene Absender für Anreise-Information
und Bewertungsbitte; Schablonen liefern Standardwerte unterhalb aller einstellbaren Ebenen.
A1/A2 bleiben Voreinstellungen und Altfassungen.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 12:40:22 +01:00

89 lines
4.3 KiB
PHP

<?php
namespace Tests\Feature\Process;
use App\Actions\CreateReservation;
use App\Enums\ActivityState;
use App\Models\Booking;
use App\Models\Property;
use App\Pricing\StayRequest;
use App\Process\CaseActivities;
use App\Process\ProcessCatalogue;
use App\Process\ProcessPlan;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\SiteSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
/**
* V2.1 cases G and H: independent steps proceed while others wait (G); a new optional step is added at an existing
* extension point without touching any other model (H).
*/
#[Group('module:guest.address_check')]
class ExtensionAndIndependentStepsTest extends TestCase
{
use RefreshDatabase;
private Property $property;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-23 10:00'));
$this->seed([PropertySeeder::class, SiteSeeder::class]);
$this->property = Property::sole();
Mail::fake();
}
/** Case H: the optional address check sits at an extension point; only the A1 offer model offers the variant. */
public function test_case_h_an_optional_address_check_is_added_at_an_extension_point_without_changing_other_models(): void
{
$catalogue = app(ProcessCatalogue::class);
$using = array_keys(array_filter($catalogue->models(), fn ($model): bool => collect($model->variants())->contains(fn ($variant): bool => in_array('guest.address_check', $model->modules($variant->key), true))));
$this->assertSame(['a1.offer', 'inquiry.request'], $using, 'the former offer model and the request base process that replaces it');
$this->assertSame([], $catalogue->problems());
foreach ($catalogue->models() as $key => $model) {
$this->assertNotContains('guest.address_check', $model->modules('standard'), "{$key}: standard course unchanged");
}
$booking = $this->request(postalCode: '1011');
$plan = ProcessPlan::freeze($booking->process(), ['model' => 'a1.offer', 'variant' => 'address_check'], sandbox: true);
$booking->forceFill(['profile' => [...$booking->profile, 'plan' => $plan->toArray()]])->saveQuietly();
$check = collect(CaseActivities::for($booking->fresh()))->firstWhere('key', 'address_check');
$this->assertSame(ActivityState::Done, $check->state, 'the check only informs and holds nothing back');
$this->assertStringContainsString('Postleitzahl hat nicht fünf Ziffern', $check->detail);
}
public function test_case_h_the_address_check_cannot_reach_a_real_case(): void
{
$this->expectExceptionMessage('nur im Prozess-Tester');
ProcessPlan::freeze($this->request()->process(), ['model' => 'a1.offer', 'variant' => 'address_check']);
}
/** Case G: the clarification hold stands while the missing details are collected; the offer waits for them, not for the hold. */
public function test_case_g_hold_and_data_collection_run_independently_and_the_offer_waits_for_the_details(): void
{
$booking = $this->request(street: '');
$activities = collect(CaseActivities::for($booking->fresh()))->keyBy('key');
$this->assertTrue(Booking::query()->occupying()->whereKey($booking->id)->exists(), 'the dates are held at once, independent of the missing details');
$this->assertSame(ActivityState::Open, $activities['contact']->state);
$this->assertStringContainsString('fehlt: Straße und Hausnummer', $activities['contact']->detail);
$this->assertSame(ActivityState::Later, $activities['offer']->state, 'no binding offer before the required details');
$this->assertSame('erst wenn alle Angaben da sind', $activities['offer']->detail);
}
private function request(string $street = 'Weg 1', string $postalCode = '10115'): Booking
{
return app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => $street, 'postal_code' => $postalCode, 'city' => 'Berlin', 'country' => 'DE'])->fresh();
}
}