U-A/U-B: Prozesskern mit Fachmodulen, versionierten Modellen, eingefrorenem Prozessplan, ProcessRunner (harte/weiche Abhängigkeiten), CasePricing, Loyalty nur im Tester
CaseActivities/CaseAutomation sind Fassaden über ProcessRunner. Verhaltensvergleich v0.11: 11 Abläufe und 198 Konstellationen gleich, beabsichtigte Abweichungen I-004/I-005 (F-001/F-002). Volle Suite vor U-B: 785/785. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
98df5e9e3b
commit
7e22e12cac
80 files changed
+4628
-445
No files matched your search
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Process;
|
||||
|
||||
use App\Actions\ContributeCaseFacts;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Enums\ActivityState;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\FactSource;
|
||||
use App\Models\Booking;
|
||||
use App\Models\DataRequest;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\Activity;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\Modules\Intake\Hold;
|
||||
use App\Process\Modules\StepState;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessPlan;
|
||||
use App\Process\ProcessRunner;
|
||||
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\Support\Process\A1WithAddressCheck;
|
||||
use Tests\Support\Process\AddressVerification;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* The process core with the real modules: the frozen plan of a new case, the course of K1 (missing address,
|
||||
* clarification hold, data request, expired hold, late answer, offer), an external address check that waits without
|
||||
* holding the offer back (K2), retired versions of finished cases (T3) and the catalogue's consistency.
|
||||
*/
|
||||
#[Group('runner')]
|
||||
class ProcessCoreTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Property $property;
|
||||
|
||||
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', 'clarification_hold_auto_minutes' => 120, 'data_request_mode' => 'automatic']]);
|
||||
Http::preventStrayRequests();
|
||||
}
|
||||
|
||||
public function test_the_catalogue_is_consistent(): void
|
||||
{
|
||||
$this->assertSame([], app(ProcessCatalogue::class)->problems());
|
||||
}
|
||||
|
||||
public function test_a_new_case_freezes_its_plan(): void
|
||||
{
|
||||
$booking = $this->request(['street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE']);
|
||||
|
||||
$plan = $booking->fresh()->profile['plan'];
|
||||
$this->assertSame(['a1.offer', 1, 'standard', ProcessPlan::DERIVED], [$plan['model'], $plan['model_version'], $plan['variant'], $plan['source']]);
|
||||
$this->assertSame(2, $plan['modules']['offer.binding']);
|
||||
$this->assertSame('Verbindliches Angebot', $plan['labels']['offer.binding']);
|
||||
$this->assertArrayNotHasKey('guest.loyalty_status', $plan['modules'], 'tester-only modules never enter a real plan');
|
||||
}
|
||||
|
||||
public function test_clarification_hold_runs_on_while_the_data_request_waits_and_the_late_answer_brings_the_offer(): void
|
||||
{
|
||||
$booking = $this->request([]);
|
||||
|
||||
// The data request went out, the offer waits for the address, the clarification hold runs independently.
|
||||
$context = CaseContext::of($booking->fresh());
|
||||
$this->assertSame([BookingStatus::Reserved, Booking::HOLD_CLARIFICATION], [$booking->status, $booking->hold_purpose]);
|
||||
$this->assertSame(StepState::Waiting, app(Hold::class)->state($context));
|
||||
$this->assertSame(DataRequest::OPEN, $booking->openDataRequest()->status);
|
||||
$this->assertSame(ActivityState::Later, $this->activity($booking, 'offer')->state);
|
||||
$this->assertSame(ActivityState::Waiting, $this->activity($booking, 'contact')->state);
|
||||
|
||||
// The hold expires; the request stays open for its details (only offer holds expire).
|
||||
$this->travel(125)->minutes();
|
||||
$this->artisan('bookings:expire-holds')->assertSuccessful();
|
||||
$this->assertSame(BookingStatus::Reserved, $booking->fresh()->status);
|
||||
$this->assertSame(StepState::Done, app(Hold::class)->state(CaseContext::of($booking->fresh())));
|
||||
|
||||
// The guest answers later; the offer becomes ready and goes out with a new offer hold.
|
||||
app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.street' => 'Lindenallee 12', 'guest.postal_code' => '10115', 'guest.city' => 'Berlin', 'guest.country' => 'DE'], FactSource::GuestLink);
|
||||
$booking->refresh();
|
||||
$this->assertSame([BookingStatus::OfferSent, Booking::HOLD_OFFER], [$booking->status, $booking->hold_purpose]);
|
||||
$this->assertSame(DataRequest::COMPLETED, $booking->dataRequests()->sole()->status);
|
||||
}
|
||||
|
||||
public function test_an_external_address_check_waits_without_holding_back_the_offer(): void
|
||||
{
|
||||
config([
|
||||
'process.modules' => [...config('process.modules'), AddressVerification::class],
|
||||
'process.models' => [...config('process.models'), 'a1.offer_address' => [1 => A1WithAddressCheck::class]],
|
||||
]);
|
||||
$this->app->forgetInstance(ProcessCatalogue::class);
|
||||
AddressVerification::$serviceAvailable = false;
|
||||
$booking = $this->request(['street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE'], automatic: false);
|
||||
$plan = ProcessPlan::freeze($booking->process(), ['model' => 'a1.offer_address', 'variant' => 'address_check']);
|
||||
$booking->forceFill(['profile' => [...$booking->profile, 'plan' => $plan->toArray()], 'processing_mode' => 'automatic'])->saveQuietly();
|
||||
|
||||
$result = app(ProcessRunner::class)->advance($booking->fresh());
|
||||
|
||||
$this->assertTrue($result->ran('offer.binding'), 'the offer does not depend on the address check');
|
||||
$this->assertSame(ActivityState::Waiting, $this->activity($booking, 'address_check')->state);
|
||||
$this->assertSame([], app(ProcessCatalogue::class)->problems(), 'a new module and a variant fit without changing other models');
|
||||
}
|
||||
|
||||
public function test_a_finished_case_of_a_retired_version_stays_readable(): void
|
||||
{
|
||||
$booking = $this->request(['street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE']);
|
||||
$plan = $booking->profile['plan'];
|
||||
// An older release: model version 0 and a module that no longer exists.
|
||||
$plan['model_version'] = 0;
|
||||
$plan['modules'] = ['intake.record' => 1, 'old.welcome_call' => 1, ...$plan['modules']];
|
||||
$plan['labels']['old.welcome_call'] = 'Begrüßungsanruf';
|
||||
$booking->forceFill(['status' => BookingStatus::Declined, 'profile' => [...$booking->profile, 'plan' => $plan]])->saveQuietly();
|
||||
|
||||
$activities = CaseActivities::for($booking->fresh());
|
||||
|
||||
$this->assertTrue(ProcessPlan::of($booking->fresh())->isHistoric());
|
||||
$this->assertSame('Begrüßungsanruf (frühere Fassung)', collect($activities)->firstWhere('key', 'old.welcome_call')->label);
|
||||
$this->assertSame('done', collect($activities)->firstWhere('key', 'offer')->state->value);
|
||||
$this->assertNotNull(CaseActivities::situation($booking->fresh()));
|
||||
}
|
||||
|
||||
public function test_a_tester_only_variant_is_refused_for_real_cases(): void
|
||||
{
|
||||
$booking = $this->request(['street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE']);
|
||||
|
||||
$this->expectExceptionMessage('nur im Prozess-Tester');
|
||||
ProcessPlan::freeze($booking->process(), ['model' => 'a1.offer', 'variant' => 'loyalty']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $address
|
||||
*/
|
||||
private function request(array $address, bool $automatic = true): Booking
|
||||
{
|
||||
if (! $automatic) {
|
||||
Settings::tenant()->update(['process_defaults' => ['processing' => 'manual']]);
|
||||
}
|
||||
|
||||
return app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', ...$address]);
|
||||
}
|
||||
|
||||
private function activity(Booking $booking, string $key): Activity
|
||||
{
|
||||
return collect(CaseActivities::for($booking->fresh()))->firstWhere('key', $key) ?? $this->fail("No activity {$key}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user