U-D/U-E/O5: Prozess-Tester im eigenen Prozess (standardmäßig gesperrt, 15 Negativtests, statischer Wächter), Szenarien und Bericht, Kanalereignisse (API-Eingang ohne Umbau von iCal/Mail), Abschluss nach finanzieller Klärung, Löschfrist 30 Tage

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-04 15:34:40 +01:00
1 parent c255783cec
commit 0689c0a591
68 files changed
+3350 -35

No files matched your search

@@ -0,0 +1,78 @@
<?php
namespace Tests\Feature\Process;
use App\Actions\RecordPayment;
use App\Actions\RecordPortalAmounts;
use App\Enums\BookingStatus;
use App\Enums\BookingTaskKind;
use App\Enums\BookingTaskStatus;
use App\Enums\PaymentKind;
use App\Exceptions\ReservationException;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Models\Channel;
use App\Models\Property;
use App\Process\CaseClosure;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
/**
* Decision O5 (intended change I-007): with portal collection the commercial closing needs the financial clarification
* of the payout – received, offset, booked difference or written-off claim; a portal's report of the payout is no proof,
* a reason alone is not enough, and an open claim stays traceable as a task of its own.
*/
#[Group('module:case.settlement')]
class SettlementClarificationTest extends TestCase
{
use RefreshDatabase;
private Booking $booking;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed(PropertySeeder::class);
Mail::fake();
$portal = Channel::factory()->for(Property::sole())->create(['name' => 'FeWo-direkt', 'booking_model' => 'portal_booking', 'process_overrides' => ['booking' => ['payments' => 'portal']]]);
$this->booking = Booking::factory()->for(Property::sole())->create(['status' => BookingStatus::Completed, 'intake' => 'booking', 'import_channel_id' => $portal->id, 'origin_channel_id' => $portal->id,
'arrival' => '2026-10-10', 'departure' => '2026-10-17', 'total' => 97951, 'completed_at' => now()]);
app(RecordPortalAmounts::class)->handle($this->booking->fresh(), null, [['kind' => 'payout_announced', 'amount' => 89469]], [], 'FeWo-direkt');
}
public function test_a_reason_alone_does_not_settle_an_open_payout(): void
{
$this->expectException(ReservationException::class);
CaseClosure::settle($this->booking->fresh(), 'Portal hat ausgezahlt', 'Lars');
}
public function test_an_open_claim_stays_traceable_and_the_case_stays_commercially_open(): void
{
CaseClosure::settle($this->booking->fresh(), 'Auszahlung fehlt, beim Portal nachgefragt', 'Lars', CaseClosure::CLAIM_OPEN);
$this->assertNull($this->booking->fresh()->settled_at);
$this->assertTrue(BookingTask::query()->where('booking_id', $this->booking->id)->where('kind', BookingTaskKind::OpenClaim)->where('status', BookingTaskStatus::Open)->exists());
}
public function test_a_written_off_claim_settles_with_its_clarification_on_record(): void
{
CaseClosure::settle($this->booking->fresh(), 'Kulanz, Betrag ausgebucht', 'Lars', 'written_off');
$booking = $this->booking->fresh();
$this->assertNotNull($booking->settled_at);
$this->assertSame('Forderung ausgebucht: Kulanz, Betrag ausgebucht', $booking->settled_note);
}
public function test_the_received_payout_settles_by_itself(): void
{
app(RecordPayment::class)->handle($this->booking->fresh(), 89469, CarbonImmutable::today(), kind: PaymentKind::PortalPayout, source: 'FeWo-direkt');
$this->assertNotNull($this->booking->fresh()->settled_at);
}
}