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,155 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Process;
|
||||
|
||||
use App\Actions\AcceptOffer;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Actions\SendOffer;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\QuoteLineType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Guest;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\CasePricing;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\QuoteLine;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\Modules\Loyalty\LoyaltyDiscount;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessPlan;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Package U-B / requirement K8: loyalty proves the extensibility – two new modules and an A1 variant at existing
|
||||
* extension points, the price lines only before the price is fixed, never usable for real cases, the other archetypes
|
||||
* untouched. The business rules (count, look-back, percentage, no combination with special offers) are test
|
||||
* assumptions, not released rules (decisions E5–E7).
|
||||
*/
|
||||
#[Group('module:guest.loyalty_status')]
|
||||
#[Group('module:pricing.loyalty_discount')]
|
||||
class LoyaltyArchitectureProofTest 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']);
|
||||
Http::preventStrayRequests();
|
||||
}
|
||||
|
||||
public function test_without_contributing_modules_the_case_price_is_exactly_the_calculator_price(): void
|
||||
{
|
||||
$booking = $this->request('neu@example.org');
|
||||
$stay = $this->stay();
|
||||
|
||||
$this->assertEquals(app(PriceCalculator::class)->calculate($this->property, $stay), app(CasePricing::class)->quote($booking, $stay));
|
||||
}
|
||||
|
||||
public function test_a_returning_guest_gets_the_discount_line_after_the_status_check_and_before_the_price_is_fixed(): void
|
||||
{
|
||||
$this->formerStay('stamm@example.org');
|
||||
$booking = $this->loyaltyCase($this->request('stamm@example.org'));
|
||||
|
||||
$quote = app(CasePricing::class)->quote($booking, $this->stay());
|
||||
$plain = app(PriceCalculator::class)->calculate($this->property, $this->stay());
|
||||
$discount = collect($quote->lines)->first(fn ($line): bool => $line->type === QuoteLineType::Discount);
|
||||
|
||||
$this->assertNotNull($discount, 'the discount reads the status of the check before it');
|
||||
$this->assertSame(-(int) round($plain->rent() * 5 / 100), $discount->amount);
|
||||
$this->assertStringContainsString('1 frühere Aufenthalte', $discount->label);
|
||||
|
||||
// The offer fixes the price: the line is in the frozen quote, and the binding case gets no contribution any more.
|
||||
app(SendOffer::class)->handle($booking->fresh());
|
||||
$booking->refresh();
|
||||
$this->assertSame($quote->total(), $booking->total);
|
||||
$this->assertContains('discount', array_column($booking->quote['lines'], 'type'));
|
||||
app(AcceptOffer::class)->handle($booking->fresh(), $booking->offer_version);
|
||||
$this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status);
|
||||
$this->assertEquals($plain, app(CasePricing::class)->quote($booking->fresh(), $this->stay()), 'no contribution after binding (R5)');
|
||||
$this->assertSame('loyalty_status', collect(CaseActivities::for($booking->fresh()))->firstWhere('key', 'loyalty_status')?->key);
|
||||
}
|
||||
|
||||
public function test_a_new_guest_and_an_unknown_status_get_no_discount_and_the_offer_is_never_held_back(): void
|
||||
{
|
||||
$new = $this->loyaltyCase($this->request('neu@example.org'));
|
||||
$this->assertSame(app(PriceCalculator::class)->calculate($this->property, $this->stay())->total(), app(CasePricing::class)->quote($new, $this->stay())->total());
|
||||
|
||||
$unknown = $this->loyaltyCase($this->request('ohne@example.org', '2026-11-20', '2026-11-23'));
|
||||
$unknown->guest->forceFill(['email' => null])->saveQuietly();
|
||||
$activity = collect(CaseActivities::for($unknown->fresh()))->firstWhere('key', 'loyalty_status');
|
||||
$this->assertStringContainsString('nicht feststellbar', $activity->detail);
|
||||
}
|
||||
|
||||
public function test_the_discount_is_not_combined_with_a_special_offer_discount(): void
|
||||
{
|
||||
$this->formerStay('stamm@example.org');
|
||||
$booking = $this->loyaltyCase($this->request('stamm@example.org'));
|
||||
$quote = app(PriceCalculator::class)->calculate($this->property, $this->stay())
|
||||
->withLine(new QuoteLine(QuoteLineType::Discount, 'Sonderangebot', 1, -1000, -1000));
|
||||
|
||||
$this->assertSame([], app(LoyaltyDiscount::class)->priceLines(CaseContext::of($booking), $quote));
|
||||
}
|
||||
|
||||
public function test_loyalty_cannot_reach_a_real_case_and_leaves_the_other_models_unchanged(): void
|
||||
{
|
||||
$catalogue = app(ProcessCatalogue::class);
|
||||
$using = array_keys(array_filter($catalogue->models(), fn ($model): bool => collect($model->variants())->contains(fn ($variant): bool => in_array('pricing.loyalty_discount', $model->modules($variant->key), true))));
|
||||
|
||||
$this->assertSame(['a1.offer'], $using, 'only the A1 offer model has the variant');
|
||||
$this->assertSame([], $catalogue->problems());
|
||||
foreach ($catalogue->models() as $key => $model) {
|
||||
$this->assertNotContains('guest.loyalty_status', $model->modules('standard'), "{$key}: standard course unchanged");
|
||||
}
|
||||
$this->expectExceptionMessage('nur im Prozess-Tester');
|
||||
ProcessPlan::freeze($this->request('neu@example.org')->process(), ['model' => 'a1.offer', 'variant' => 'loyalty']);
|
||||
}
|
||||
|
||||
private function loyaltyCase(Booking $booking): Booking
|
||||
{
|
||||
$plan = ProcessPlan::freeze($booking->process(), ['model' => 'a1.offer', 'variant' => 'loyalty'], sandbox: true);
|
||||
$booking->forceFill(['profile' => [...$booking->profile, 'plan' => $plan->toArray()]])->saveQuietly();
|
||||
|
||||
return $booking->fresh();
|
||||
}
|
||||
|
||||
private function formerStay(string $email): void
|
||||
{
|
||||
$guest = Guest::query()->create(['tenant_id' => $this->property->tenant_id, 'first_name' => 'Stamm', 'last_name' => 'Gast', 'email' => 'alt-'.$email]);
|
||||
Booking::factory()->for($this->property)->create(['guest_id' => $guest->id, 'status' => BookingStatus::Completed, 'arrival' => '2025-08-01', 'departure' => '2025-08-08']);
|
||||
$guest->forceFill(['email' => $email])->saveQuietly();
|
||||
}
|
||||
|
||||
private function request(string $email, string $arrival = '2026-11-07', string $departure = '2026-11-10'): Booking
|
||||
{
|
||||
return app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email, 'street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE']);
|
||||
}
|
||||
|
||||
private function stay(): StayRequest
|
||||
{
|
||||
return new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user