Skip to content

Commit

Permalink
Added tryToPreventOrphanSeats flag when selecting best available obje…
Browse files Browse the repository at this point in the history
…cts (#82)

* Added tryToPreventOrphanSeats flag when selecting best available objects

* Fixed tests
  • Loading branch information
mroloux authored May 8, 2023
1 parent cdce7e9 commit 35b1886
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 113 deletions.
5 changes: 4 additions & 1 deletion src/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public function holdBestAvailable(string $eventKey, int $number, string $holdTok
* @param $ticketTypes string[]|null
* @param $channelKeys string[]|null
*/
public function changeBestAvailableObjectStatus(string $eventKey, int $number, string $status, array $categories = null, string $holdToken = null, array $extraData = null, array $ticketTypes = null, string $orderId = null, bool $keepExtraData = null, bool $ignoreChannels = null, array $channelKeys = null): BestAvailableObjects
public function changeBestAvailableObjectStatus(string $eventKey, int $number, string $status, array $categories = null, string $holdToken = null, array $extraData = null, array $ticketTypes = null, string $orderId = null, bool $keepExtraData = null, bool $ignoreChannels = null, array $channelKeys = null, bool $tryToPreventOrphanSeats = null): BestAvailableObjects
{
$request = new stdClass();
$bestAvailable = new stdClass();
Expand All @@ -463,6 +463,9 @@ public function changeBestAvailableObjectStatus(string $eventKey, int $number, s
if ($ticketTypes !== null) {
$bestAvailable->ticketTypes = $ticketTypes;
}
if ($tryToPreventOrphanSeats !== null) {
$bestAvailable->tryToPreventOrphanSeats = $tryToPreventOrphanSeats;
}
$request->bestAvailable = $bestAvailable;
$request->status = $status;
if ($holdToken !== null) {
Expand Down
47 changes: 29 additions & 18 deletions tests/Events/ChangeBestAvailableObjectStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function test()
$bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 2, "lolzor");

self::assertTrue($bestAvailableObjects->nextToEachOther);
self::assertEquals(["B-4", "B-5"], $bestAvailableObjects->objects);
self::assertEquals(["A-4", "A-5"], $bestAvailableObjects->objects);
}

public function testObjectDetails()
Expand All @@ -26,11 +26,11 @@ public function testObjectDetails()

$bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 1, "lolzor");

$objectDetails = $bestAvailableObjects->objectDetails["B-5"];
$objectDetails = $bestAvailableObjects->objectDetails["A-5"];
self::assertEquals("lolzor", $objectDetails->status);
self::assertEquals("B-5", $objectDetails->label);
self::assertEquals(someLabels("5", "seat", "B", "row"), $objectDetails->labels);
self::assertEquals(new IDs("5", "B", null), $objectDetails->ids);
self::assertEquals("A-5", $objectDetails->label);
self::assertEquals(someLabels("5", "seat", "A", "row"), $objectDetails->labels);
self::assertEquals(new IDs("5", "A", null), $objectDetails->ids);
self::assertEquals("Cat1", $objectDetails->categoryLabel);
self::assertEquals(9, $objectDetails->categoryKey);
self::assertNull($objectDetails->ticketType);
Expand All @@ -39,8 +39,8 @@ public function testObjectDetails()
self::assertTrue($objectDetails->forSale);
self::assertNull($objectDetails->section);
self::assertNull($objectDetails->entrance);
self::assertEquals("B-4", $objectDetails->leftNeighbour);
self::assertEquals("B-6", $objectDetails->rightNeighbour);
self::assertEquals("A-4", $objectDetails->leftNeighbour);
self::assertEquals("A-6", $objectDetails->rightNeighbour);
}

public function testCategories()
Expand All @@ -64,24 +64,35 @@ public function testExtraData()

$bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 2, "lolzor", null, null, $extraData);

self::assertEquals(["B-4", "B-5"], $bestAvailableObjects->objects);
$b4ObjectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "B-4");
self::assertEquals(["A-4", "A-5"], $bestAvailableObjects->objects);
$b4ObjectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "A-4");
self::assertEquals($b4ObjectInfo->extraData, (object)["foo" => "bar"]);
$b5ObjectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "B-5");
$b5ObjectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "A-5");
self::assertEquals($b5ObjectInfo->extraData, (object)["foo" => "baz"]);
}

public function testDoNotTryToPreventOrphanSeats()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->book($event->key, ["A-4", "A-5"]);

$bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 2, "lolzor", null, null, null, null, null, null, null, null, false);

self::assertEquals(["A-2", "A-3"], $bestAvailableObjects->objects);
}

public function testTicketTypes()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);

$bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 2, "lolzor", null, null, null, ["adult", "child"]);

self::assertEquals(["B-4", "B-5"], $bestAvailableObjects->objects);
$b4ObjectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "B-4");
self::assertEquals(["A-4", "A-5"], $bestAvailableObjects->objects);
$b4ObjectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "A-4");
self::assertEquals($b4ObjectInfo->ticketType, "adult");
$b5ObjectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "B-5");
$b5ObjectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "A-5");
self::assertEquals($b5ObjectInfo->ticketType, "child");
}

Expand Down Expand Up @@ -117,7 +128,7 @@ public function testBook()
$bestAvailableObjects = $this->seatsioClient->events->bookBestAvailable($event->key, 3);

self::assertTrue($bestAvailableObjects->nextToEachOther);
self::assertEquals(["B-4", "B-5", "B-6"], $bestAvailableObjects->objects);
self::assertEquals(["A-4", "A-5", "A-6"], $bestAvailableObjects->objects);
}

public function testHold()
Expand All @@ -138,11 +149,11 @@ public function testKeepExtraData()
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$extraData = ["foo" => "bar"];
$this->seatsioClient->events->updateExtraData($event->key, "B-5", $extraData);
$this->seatsioClient->events->updateExtraData($event->key, "A-5", $extraData);

$this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 1, "lolzor", null, null, null, null, null, true);

$objectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "B-5");
$objectInfo = $this->seatsioClient->events->retrieveObjectInfo($event->key, "A-5");
self::assertEquals((object)$extraData, $objectInfo->extraData);
}

Expand Down Expand Up @@ -170,11 +181,11 @@ public function testIgnoreChannels()
"channelKey1" => new Channel("channel 1", "#FF0000", 1)
]);
$this->seatsioClient->events->channels->setObjects($event->key, [
"channelKey1" => ["B-5"]
"channelKey1" => ["A-5"]
]);

$bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 1, "lolzor", null, null, null, null, null, null, true);

self::assertEquals(["B-5"], $bestAvailableObjects->objects);
self::assertEquals(["A-5"], $bestAvailableObjects->objects);
}
}
4 changes: 2 additions & 2 deletions tests/Events/ChangeObjectStatusForMultipleObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public function testQuantity()
$event = $this->seatsioClient->events->create($chartKey);
$objects = [
(new ObjectProperties("GA1"))->setQuantity(5),
(new ObjectProperties("34"))->setQuantity(10)
(new ObjectProperties("GA2"))->setQuantity(10)
];

$this->seatsioClient->events->changeObjectStatus($event->key, $objects, "lolzor");

$objectInfo1 = $this->seatsioClient->events->retrieveObjectInfo($event->key, "GA1");
self::assertEquals(5, $objectInfo1->numBooked);

$objectInfo2 = $this->seatsioClient->events->retrieveObjectInfo($event->key, "34");
$objectInfo2 = $this->seatsioClient->events->retrieveObjectInfo($event->key, "GA2");
self::assertEquals(10, $objectInfo2->numBooked);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Events/ChangeObjectStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public function testGA()
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);

$result = $this->seatsioClient->events->changeObjectStatus($event->key, "34", "lolzor");
$result = $this->seatsioClient->events->changeObjectStatus($event->key, "GA2", "lolzor");

self::assertEquals(["34"], array_keys($result->objects));
self::assertEquals(["GA2"], array_keys($result->objects));
}

public function testObjectIdAsString()
Expand Down
Loading

0 comments on commit 35b1886

Please sign in to comment.