From dff5c37034622ad025c00915361a6ae88f87ddbb Mon Sep 17 00:00:00 2001 From: mroloux Date: Fri, 25 Aug 2023 14:14:01 +0200 Subject: [PATCH] Channels can be passed in when creating events (#92) * Channels can be passed in when creating events * Refactoring --- src/Events/CreateEventParams.php | 14 ++++++++++++++ src/Events/EventParams.php | 5 ++++- src/Events/Events.php | 8 ++++++++ src/Seasons/SeasonCreationParams.php | 14 ++++++++++++++ src/Seasons/Seasons.php | 4 ++++ tests/Events/BookObjectsTest.php | 10 ++++------ .../ChangeBestAvailableObjectStatusTest.php | 10 ++++------ .../Events/ChangeObjectStatusInBatchTest.php | 10 ++++------ tests/Events/ChangeObjectStatusTest.php | 10 ++++------ tests/Events/Channels/RemoveChannelTest.php | 7 +++---- tests/Events/CreateEventTest.php | 13 +++++++++++++ tests/Events/CreateEventsTest.php | 14 ++++++++++++++ tests/Events/HoldObjectsTest.php | 14 ++++++-------- tests/Events/ReleaseObjectsTest.php | 10 ++++------ tests/Reports/EventReportsSummaryTest.php | 6 +++--- tests/Reports/EventReportsTest.php | 19 ++++++++----------- tests/Seasons/CreateSeasonTest.php | 15 +++++++++++++++ 17 files changed, 126 insertions(+), 57 deletions(-) diff --git a/src/Events/CreateEventParams.php b/src/Events/CreateEventParams.php index 2225d4d..220a020 100644 --- a/src/Events/CreateEventParams.php +++ b/src/Events/CreateEventParams.php @@ -4,8 +4,22 @@ class CreateEventParams extends EventParams { + /** + * @var \Seatsio\Events\Channel[] + */ + public $channels; + static function create(): CreateEventParams { return new CreateEventParams(); } + + /** + * @param \Seatsio\Events\Channel[] $channels + */ + public function setChannels(array $channels): self + { + $this->channels = $channels; + return $this; + } } diff --git a/src/Events/EventParams.php b/src/Events/EventParams.php index b09d1f8..9c884d7 100644 --- a/src/Events/EventParams.php +++ b/src/Events/EventParams.php @@ -66,7 +66,10 @@ public function setObjectCategories($objectCategories): self return $this; } - public function setCategories($categories): self + /** + * @param \Seatsio\Charts\Category[] $categories + */ + public function setCategories(array $categories): self { $this->categories = $categories; return $this; diff --git a/src/Events/Events.php b/src/Events/Events.php index 4c8f9cb..e5b9ea2 100644 --- a/src/Events/Events.php +++ b/src/Events/Events.php @@ -61,6 +61,10 @@ public function create(string $chartKey, CreateEventParams $params = null): Even if ($params->categories !== null) { $request->categories = $params->categories; } + + if ($params->channels !== null) { + $request->channels = $params->channels; + } } $res = $this->client->post('/events', ['json' => $request]); @@ -104,6 +108,10 @@ public function createMultiple(string $chartKey, array $createEventParams): arra $eventToCreate->categories = $param->categories; } + if ($param->channels !== null) { + $eventToCreate->channels = $param->channels; + } + $request->events[] = $eventToCreate; } diff --git a/src/Seasons/SeasonCreationParams.php b/src/Seasons/SeasonCreationParams.php index d5ced45..4a65f19 100644 --- a/src/Seasons/SeasonCreationParams.php +++ b/src/Seasons/SeasonCreationParams.php @@ -27,6 +27,11 @@ class SeasonCreationParams */ public $tableBookingConfig; + /** + * @var \Seatsio\Events\Channel[] + */ + public $channels; + public function __construct(string $key = null) { $this->key = $key; @@ -54,4 +59,13 @@ public function setTableBookingConfig(TableBookingConfig $tableBookingConfig): s $this->tableBookingConfig = $tableBookingConfig; return $this; } + + /** + * @param \Seatsio\Events\Channel[] $channels + */ + public function setChannels(array $channels): self + { + $this->channels = $channels; + return $this; + } } diff --git a/src/Seasons/Seasons.php b/src/Seasons/Seasons.php index af72b59..e0688da 100644 --- a/src/Seasons/Seasons.php +++ b/src/Seasons/Seasons.php @@ -46,6 +46,10 @@ public function create(string $chartKey, SeasonCreationParams $seasonCreationPar if ($seasonCreationParams->tableBookingConfig !== null) { $request->tableBookingConfig = $this->serializeTableBookingConfig($seasonCreationParams->tableBookingConfig); } + + if ($seasonCreationParams->channels !== null) { + $request->channels = $seasonCreationParams->channels; + } } $res = $this->client->post('/seasons', ['json' => $request]); diff --git a/tests/Events/BookObjectsTest.php b/tests/Events/BookObjectsTest.php index c14d34b..355a5f4 100644 --- a/tests/Events/BookObjectsTest.php +++ b/tests/Events/BookObjectsTest.php @@ -79,10 +79,9 @@ public function testKeepExtraData() public function testChannelKeys() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); $this->seatsioClient->events->book($event->key, "A-1", null, null, null, null, ["channelKey1"]); @@ -93,10 +92,9 @@ public function testChannelKeys() public function testIgnoreChannels() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); $this->seatsioClient->events->book($event->key, "A-1", null, null, null, true); diff --git a/tests/Events/ChangeBestAvailableObjectStatusTest.php b/tests/Events/ChangeBestAvailableObjectStatusTest.php index e21bb68..44cfcf8 100644 --- a/tests/Events/ChangeBestAvailableObjectStatusTest.php +++ b/tests/Events/ChangeBestAvailableObjectStatusTest.php @@ -160,10 +160,9 @@ public function testKeepExtraData() public function testChannelKeys() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["B-6"]) - ]); + ])); $bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 1, "lolzor", null, null, null, null, null, null, null, ["channelKey1"]); @@ -173,10 +172,9 @@ public function testChannelKeys() public function testIgnoreChannels() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-5"]) - ]); + ])); $bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 1, "lolzor", null, null, null, null, null, null, true); diff --git a/tests/Events/ChangeObjectStatusInBatchTest.php b/tests/Events/ChangeObjectStatusInBatchTest.php index ab8ae15..00ff354 100644 --- a/tests/Events/ChangeObjectStatusInBatchTest.php +++ b/tests/Events/ChangeObjectStatusInBatchTest.php @@ -32,10 +32,9 @@ public function test() public function testChannelKeys() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1"]) - ]); + ])); $response = $this->seatsioClient->events->changeObjectStatusInBatch([ new StatusChangeRequest($event->key, "A-1", "lolzor", null, null, null, null, ["channelKey1"]) @@ -47,10 +46,9 @@ public function testChannelKeys() public function testIgnoreChannels() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1"]) - ]); + ])); $response = $this->seatsioClient->events->changeObjectStatusInBatch([ new StatusChangeRequest($event->key, "A-1", "lolzor", null, null, null, true) diff --git a/tests/Events/ChangeObjectStatusTest.php b/tests/Events/ChangeObjectStatusTest.php index 4dd18a3..ac97a46 100644 --- a/tests/Events/ChangeObjectStatusTest.php +++ b/tests/Events/ChangeObjectStatusTest.php @@ -125,10 +125,9 @@ public function testKeepExtraData() public function testChannelKeys() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); $this->seatsioClient->events->changeObjectStatus($event->key, "A-1", "someStatus", null, null, null, null, ["channelKey1"]); @@ -139,10 +138,9 @@ public function testChannelKeys() public function testIgnoreChannels() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); $this->seatsioClient->events->changeObjectStatus($event->key, "A-1", "someStatus", null, null, null, true); diff --git a/tests/Events/Channels/RemoveChannelTest.php b/tests/Events/Channels/RemoveChannelTest.php index b290b15..4876466 100644 --- a/tests/Events/Channels/RemoveChannelTest.php +++ b/tests/Events/Channels/RemoveChannelTest.php @@ -3,6 +3,7 @@ namespace Seatsio\Events\Channels; use Seatsio\Events\Channel; +use Seatsio\Events\CreateEventParams; use Seatsio\SeatsioClientTest; class RemoveChannelTest extends SeatsioClientTest @@ -12,12 +13,10 @@ public function test() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]), new Channel("channelKey2", "channel 2", "#FF0000", 2, []) - ]); + ])); $this->seatsioClient->events->channels->remove($event->key, "channelKey2"); diff --git a/tests/Events/CreateEventTest.php b/tests/Events/CreateEventTest.php index 3d812ad..ab4637b 100644 --- a/tests/Events/CreateEventTest.php +++ b/tests/Events/CreateEventTest.php @@ -103,4 +103,17 @@ public function testDateCanBePassedIn() self::assertEquals(LocalDate::create(2022, 1, 5), $event->date); } + + public function testChannelsCanBePassedIn() + { + $chartKey = $this->createTestChart(); + $channels = [ + new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]), + new Channel("channelKey2", "channel 2", "#00FFFF", 2, []) + ]; + + $event = $this->seatsioClient->events->create($chartKey, CreateEventParams::create()->setChannels($channels)); + + self::assertEquals($channels, $event->channels); + } } diff --git a/tests/Events/CreateEventsTest.php b/tests/Events/CreateEventsTest.php index eac0882..1d5b17b 100644 --- a/tests/Events/CreateEventsTest.php +++ b/tests/Events/CreateEventsTest.php @@ -122,4 +122,18 @@ public function test_dateCanBePassedIn() self::assertEquals(LocalDate::create(2022, 1, 10), $events[0]->date); } + public function test_channelsCanBePassedIn() + { + $chartKey = $this->createTestChart(); + $channels = [ + new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]), + new Channel("channelKey2", "channel 2", "#00FFFF", 2, []) + ]; + + $params = [CreateEventParams::create()->setChannels($channels)]; + $events = $this->seatsioClient->events->createMultiple($chartKey, $params); + + self::assertEquals($channels, $events[0]->channels); + } + } diff --git a/tests/Events/HoldObjectsTest.php b/tests/Events/HoldObjectsTest.php index 609d774..bde55c3 100644 --- a/tests/Events/HoldObjectsTest.php +++ b/tests/Events/HoldObjectsTest.php @@ -55,11 +55,10 @@ public function testKeepExtraData() public function testChannelKeys() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $holdToken = $this->seatsioClient->holdTokens->create(); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); + $holdToken = $this->seatsioClient->holdTokens->create(); $this->seatsioClient->events->hold($event->key, "A-1", $holdToken->holdToken, null, null, null, ["channelKey1"]); @@ -70,11 +69,10 @@ public function testChannelKeys() public function testIgnoreChannels() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $holdToken = $this->seatsioClient->holdTokens->create(); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); + $holdToken = $this->seatsioClient->holdTokens->create(); $this->seatsioClient->events->hold($event->key, "A-1", $holdToken->holdToken, null, null, true); diff --git a/tests/Events/ReleaseObjectsTest.php b/tests/Events/ReleaseObjectsTest.php index da13391..401e524 100644 --- a/tests/Events/ReleaseObjectsTest.php +++ b/tests/Events/ReleaseObjectsTest.php @@ -63,10 +63,9 @@ public function testKeepExtraData() public function testChannelKeys() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); $this->seatsioClient->events->book($event->key, "A-1", null, null, null, null, ["channelKey1"]); $this->seatsioClient->events->release($event->key, "A-1", null, null, null, null, ["channelKey1"]); @@ -78,10 +77,9 @@ public function testChannelKeys() public function testIgnoreChannels() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); $this->seatsioClient->events->book($event->key, "A-1", null, null, null, null, ["channelKey1"]); $this->seatsioClient->events->release($event->key, "A-1", null, null, null, true); diff --git a/tests/Reports/EventReportsSummaryTest.php b/tests/Reports/EventReportsSummaryTest.php index 0d0b03f..ff38bdb 100644 --- a/tests/Reports/EventReportsSummaryTest.php +++ b/tests/Reports/EventReportsSummaryTest.php @@ -3,6 +3,7 @@ namespace Seatsio\Reports; use Seatsio\Events\Channel; +use Seatsio\Events\CreateEventParams; use Seatsio\Events\ObjectProperties; use Seatsio\SeatsioClientTest; @@ -336,10 +337,9 @@ public function testSummaryByAvailabilityReason() public function testSummaryByChannel() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); $report = $this->seatsioClient->eventReports->summaryByChannel($event->key); diff --git a/tests/Reports/EventReportsTest.php b/tests/Reports/EventReportsTest.php index 39c4e78..b3e3979 100644 --- a/tests/Reports/EventReportsTest.php +++ b/tests/Reports/EventReportsTest.php @@ -16,12 +16,11 @@ class EventReportsTest extends SeatsioClientTest public function testReportItemProperties() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ + new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) + ])); $extraData = ["foo" => "bar"]; - $this->seatsioClient->events->book($event->key, (new ObjectProperties("A-1"))->setTicketType("ticketType1")->setExtraData($extraData), null, "order1"); - $this->seatsioClient->events->channels->replace($event->key, [ - new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1"]) - ]); + $this->seatsioClient->events->book($event->key, (new ObjectProperties("A-1"))->setTicketType("ticketType1")->setExtraData($extraData), null, "order1", null, true); $report = $this->seatsioClient->eventReports->byLabel($event->key); @@ -315,10 +314,9 @@ public function testBySpecificAvailabilityReason() public function testByChannel() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); $report = $this->seatsioClient->eventReports->byChannel($event->key); @@ -329,10 +327,9 @@ public function testByChannel() public function testBySpecificChannel() { $chartKey = $this->createTestChart(); - $event = $this->seatsioClient->events->create($chartKey); - $this->seatsioClient->events->channels->replace($event->key, [ + $event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([ new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]) - ]); + ])); $report = $this->seatsioClient->eventReports->byChannel($event->key, 'channel1'); diff --git a/tests/Seasons/CreateSeasonTest.php b/tests/Seasons/CreateSeasonTest.php index c580e14..7319129 100644 --- a/tests/Seasons/CreateSeasonTest.php +++ b/tests/Seasons/CreateSeasonTest.php @@ -2,6 +2,7 @@ namespace Seatsio\Seasons; +use Seatsio\Events\Channel; use Seatsio\Events\TableBookingConfig; use Seatsio\SeatsioClientTest; use function Functional\map; @@ -75,4 +76,18 @@ public function testTableBookingConfigInheritCanBePassedIn() self::assertNotNull($season->key); self::assertEquals(TableBookingConfig::inherit(), $season->tableBookingConfig); } + + public function testChannelsCanBePassedIn() + { + $chartKey = $this->createTestChart(); + $channels = [ + new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]), + new Channel("channelKey2", "channel 2", "#00FFFF", 2, []) + ]; + + $season = $this->seatsioClient->seasons->create($chartKey, (new SeasonCreationParams())->setChannels($channels)); + + self::assertNotNull($season->key); + self::assertEquals($channels, $season->channels); + } }