feat: force booking status 'O' for selection id 1473
addresses #869d79q0r
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\Model;
|
||||
|
||||
use App\BusProNet\Model\CrmSelection;
|
||||
use App\BusProNet\Model\CrmSelectionGroup;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -109,4 +111,44 @@ class TravelTest extends TestCase
|
||||
$this->assertSame('BUS', $result[0]->subType);
|
||||
$this->assertSame('PKW', $result[1]->subType);
|
||||
}
|
||||
|
||||
public function testHasSelectionIdReturnsTrueWhenSelectionExists(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->selectionGroups = [
|
||||
10 => $this->createSelectionGroup(10, [1473, 2001]),
|
||||
11 => $this->createSelectionGroup(11, [3001]),
|
||||
];
|
||||
|
||||
$this->assertTrue($travel->hasSelectionId(1473));
|
||||
}
|
||||
|
||||
public function testHasSelectionIdReturnsFalseWhenSelectionDoesNotExist(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->selectionGroups = [
|
||||
10 => $this->createSelectionGroup(10, [2001]),
|
||||
11 => $this->createSelectionGroup(11, [3001]),
|
||||
];
|
||||
|
||||
$this->assertFalse($travel->hasSelectionId(1473));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $selectionIds
|
||||
*/
|
||||
private function createSelectionGroup(int $groupId, array $selectionIds): CrmSelectionGroup
|
||||
{
|
||||
$group = new CrmSelectionGroup();
|
||||
$group->id = $groupId;
|
||||
$group->selections = [];
|
||||
|
||||
foreach ($selectionIds as $selectionId) {
|
||||
$selection = new CrmSelection();
|
||||
$selection->id = $selectionId;
|
||||
$group->selections[] = $selection;
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Tests\BusProNet\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\Service\BookingStatusRuleRegistry;
|
||||
use App\BusProNet\Service\Contract\BookingStatusRuleInterface;
|
||||
use App\BusProNet\Service\StatusRule\Selection1473StatusRule;
|
||||
use App\Form\Model\BookingDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -99,6 +100,22 @@ class BookingStatusRuleRegistryTest extends TestCase
|
||||
$this->assertSame('L', $registry->evaluateStatus($bookingDto));
|
||||
}
|
||||
|
||||
public function testSelection1473RuleWinsOverLowerPriorityRule(): void
|
||||
{
|
||||
$lowerPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$lowerPriorityRule->method('evaluate')->willReturn(true);
|
||||
$lowerPriorityRule->method('getStatus')->willReturn('X');
|
||||
$lowerPriorityRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$registry = new BookingStatusRuleRegistry([
|
||||
$lowerPriorityRule,
|
||||
new Selection1473StatusRule(),
|
||||
]);
|
||||
$bookingDto = new BookingDto($this->createMockTravelWithSelection1473(), 1);
|
||||
|
||||
$this->assertSame('O', $registry->evaluateStatus($bookingDto));
|
||||
}
|
||||
|
||||
private function createMockTravel(): Travel
|
||||
{
|
||||
$travel = new Travel();
|
||||
@@ -109,4 +126,32 @@ class BookingStatusRuleRegistryTest extends TestCase
|
||||
|
||||
return $travel;
|
||||
}
|
||||
|
||||
private function createMockTravelWithSelection1473(): Travel
|
||||
{
|
||||
$travel = $this->createMockTravel();
|
||||
$travel->selectionGroups = [
|
||||
1 => $this->createSelectionGroup(1, [1473]),
|
||||
];
|
||||
|
||||
return $travel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $selectionIds
|
||||
*/
|
||||
private function createSelectionGroup(int $groupId, array $selectionIds): \App\BusProNet\Model\CrmSelectionGroup
|
||||
{
|
||||
$group = new \App\BusProNet\Model\CrmSelectionGroup();
|
||||
$group->id = $groupId;
|
||||
$group->selections = [];
|
||||
|
||||
foreach ($selectionIds as $selectionId) {
|
||||
$selection = new \App\BusProNet\Model\CrmSelection();
|
||||
$selection->id = $selectionId;
|
||||
$group->selections[] = $selection;
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\Service\StatusRule;
|
||||
|
||||
use App\BusProNet\Model\CrmSelection;
|
||||
use App\BusProNet\Model\CrmSelectionGroup;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\Service\StatusRule\Selection1473StatusRule;
|
||||
use App\Form\Model\BookingDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class Selection1473StatusRuleTest extends TestCase
|
||||
{
|
||||
private Selection1473StatusRule $rule;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->rule = new Selection1473StatusRule();
|
||||
}
|
||||
|
||||
public function testEvaluatesTrueWhenSelection1473Exists(): void
|
||||
{
|
||||
$bookingDto = new BookingDto($this->createTravelWithSelectionIds([1473]), 1);
|
||||
|
||||
$this->assertTrue($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testEvaluatesFalseWhenSelection1473DoesNotExist(): void
|
||||
{
|
||||
$bookingDto = new BookingDto($this->createTravelWithSelectionIds([2001]), 1);
|
||||
|
||||
$this->assertFalse($this->rule->evaluate($bookingDto));
|
||||
}
|
||||
|
||||
public function testReturnsStatusO(): void
|
||||
{
|
||||
$this->assertSame('O', $this->rule->getStatus());
|
||||
}
|
||||
|
||||
public function testReturnsPriority200(): void
|
||||
{
|
||||
$this->assertSame(200, $this->rule->getPriority());
|
||||
}
|
||||
|
||||
public function testReturnsDescription(): void
|
||||
{
|
||||
$this->assertSame('Assigns Option status when selection 1473 is present', $this->rule->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $selectionIds
|
||||
*/
|
||||
private function createTravelWithSelectionIds(array $selectionIds): Travel
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->id = 1;
|
||||
$travel->hotelId = 1;
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
|
||||
$travel->selectionGroups = [
|
||||
1 => $this->createSelectionGroup(1, $selectionIds),
|
||||
];
|
||||
|
||||
return $travel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $selectionIds
|
||||
*/
|
||||
private function createSelectionGroup(int $groupId, array $selectionIds): CrmSelectionGroup
|
||||
{
|
||||
$group = new CrmSelectionGroup();
|
||||
$group->id = $groupId;
|
||||
$group->selections = [];
|
||||
|
||||
foreach ($selectionIds as $selectionId) {
|
||||
$selection = new CrmSelection();
|
||||
$selection->id = $selectionId;
|
||||
$group->selections[] = $selection;
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user