feat: extensible participant status determination for booking creation
Adds a rule-based system to determine participant status in CREATE payloads. Participants selecting a 'Begleitperson' service now receive status 'O' (Option), all others default to 'F' (Final). - Add ParticipantStatusRuleInterface for defining status rules - Add ParticipantStatusRuleRegistry for priority-based rule evaluation - Add ChaperonServiceStatusRule for Begleitperson detection - Integrate status evaluation into BookingPayloadBuilder
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\Service\StatusRule;
|
||||
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Service\StatusRule\ChaperonServiceStatusRule;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ChaperonServiceStatusRuleTest extends TestCase
|
||||
{
|
||||
private ChaperonServiceStatusRule $rule;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->rule = new ChaperonServiceStatusRule();
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInAdditionalServices(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'Skibegleitperson Kurs';
|
||||
$participant->additionalServices = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInCourses(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'Begleitperson Anfängerkurs';
|
||||
$participant->courses = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInBoard(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'Halbpension Begleitperson';
|
||||
$participant->board = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInRentals(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'Skiset Begleitperson';
|
||||
$participant->rentals = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInSkiPass(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'Skipass Begleitperson 6 Tage';
|
||||
$participant->skiPass = $service;
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testReturnsTrueWhenBegleitpersonInVeg(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'Vegetarisch Begleitperson';
|
||||
$participant->veg = $service;
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testReturnsFalseWhenNoBegleitpersonService(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'Skipass 6 Tage Erwachsene';
|
||||
$participant->skiPass = $service;
|
||||
|
||||
$this->assertFalse($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testReturnsFalseWithEmptyServices(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->assertFalse($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testCaseInsensitiveMatch(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'BEGLEITPERSON Kurs';
|
||||
$participant->additionalServices = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testMixedCaseMatch(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = 'beGleitPerson Kurs';
|
||||
$participant->courses = [$service];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testReturnsStatusO(): void
|
||||
{
|
||||
$this->assertSame('O', $this->rule->getStatus());
|
||||
}
|
||||
|
||||
public function testGetPriorityReturns100(): void
|
||||
{
|
||||
$this->assertSame(100, $this->rule->getPriority());
|
||||
}
|
||||
|
||||
public function testGetDescriptionReturnsNonEmptyString(): void
|
||||
{
|
||||
$description = $this->rule->getDescription();
|
||||
|
||||
$this->assertIsString($description);
|
||||
$this->assertNotEmpty($description);
|
||||
}
|
||||
|
||||
public function testHandlesNullLabel(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$service = new Service();
|
||||
$service->label = null;
|
||||
$participant->additionalServices = [$service];
|
||||
|
||||
$this->assertFalse($this->rule->evaluate($participant));
|
||||
}
|
||||
|
||||
public function testMultipleServicesWithOneBegleitperson(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$normalService = new Service();
|
||||
$normalService->label = 'Skipass 6 Tage';
|
||||
|
||||
$begleitpersonService = new Service();
|
||||
$begleitpersonService->label = 'Skipass Begleitperson';
|
||||
|
||||
$participant->additionalServices = [$normalService, $begleitpersonService];
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($participant));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user