-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from seatsio/create-multiple-events-in-one-go
create multiple events in one go
- Loading branch information
Showing
3 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Seatsio\Events; | ||
|
||
use Exception; | ||
|
||
class EventCreationParams | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $eventKey; | ||
|
||
/** | ||
* @var boolean|object|array | ||
*/ | ||
public $bookWholeTablesOrTableBookingModes; | ||
|
||
public function __construct($eventKey = null) | ||
{ | ||
$this->eventKey = $eventKey; | ||
} | ||
|
||
public function setBookWholeTablesOrTableBookingModes($bookWholeTablesOrTableBookingModes) | ||
{ | ||
$this->bookWholeTablesOrTableBookingModes = $bookWholeTablesOrTableBookingModes; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param $bookWholeTables bool | ||
* @return EventCreationParams | ||
* @throws Exception | ||
*/ | ||
public function setBookWholeTables($bookWholeTables) | ||
{ | ||
if (is_bool($bookWholeTables)) { | ||
return $this->setBookWholeTablesOrTableBookingModes($bookWholeTables); | ||
} else { | ||
throw new Exception('expected bool param'); | ||
} | ||
} | ||
|
||
/** | ||
* @param $tableBookingModes | ||
* @return EventCreationParams | ||
* @throws Exception | ||
*/ | ||
public function setTableBookingModes($tableBookingModes) | ||
{ | ||
if (is_array($tableBookingModes)) { | ||
return $this->setBookWholeTablesOrTableBookingModes($tableBookingModes); | ||
} else { | ||
throw new Exception('expected array param'); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace Seatsio\Events; | ||
|
||
use Seatsio\SeatsioClientTest; | ||
|
||
class CreateEventsTest extends SeatsioClientTest | ||
{ | ||
|
||
public function test_multipleEvents() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
$params = [new EventCreationParams(), new EventCreationParams()]; | ||
|
||
$events = $this->seatsioClient->events->createMultiple($chartKey, $params); | ||
|
||
self::assertEquals(2, sizeof($events)); | ||
foreach ($events as $e) { | ||
self::assertNotNull($e->key); | ||
} | ||
} | ||
|
||
public function test_single_event() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
$params = [new EventCreationParams()]; | ||
|
||
$events = $this->seatsioClient->events->createMultiple($chartKey, $params); | ||
|
||
self::assertEquals(1, sizeof($events)); | ||
$event = $events[0]; | ||
self::assertNotEquals(0, $event->id); | ||
self::assertNotNull($event->id); | ||
self::assertNotNull($event->key); | ||
self::assertEquals($chartKey, $event->chartKey); | ||
self::assertFalse($event->bookWholeTables); | ||
self::assertNull($event->supportsBestAvailable); | ||
self::assertNull($event->forSaleConfig); | ||
self::assertNull($event->updatedOn); | ||
} | ||
|
||
public function test_event_key_can_be_passed_in() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
$params = [new EventCreationParams("event1"), new EventCreationParams("event2")]; | ||
|
||
$events = $this->seatsioClient->events->createMultiple($chartKey, $params); | ||
|
||
self::assertEquals(2, sizeof($events)); | ||
self::assertEquals("event1", $events[0]->key); | ||
self::assertEquals("event2", $events[1]->key); | ||
} | ||
|
||
public function test_bookWholeTablesCanBePassedIn() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
$params = [(new EventCreationParams())->setBookWholeTables(true), (new EventCreationParams())->setBookWholeTables(false)]; | ||
|
||
$events = $this->seatsioClient->events->createMultiple($chartKey, $params); | ||
|
||
self::assertEquals(2, sizeof($events)); | ||
self::assertTrue($events[0]->bookWholeTables); | ||
self::assertFalse($events[1]->bookWholeTables); | ||
} | ||
|
||
public function test_tableBookingModesCanBePassedIn() | ||
{ | ||
$chartKey = $this->createTestChartWithTables(); | ||
$params = [(new EventCreationParams())->setTableBookingModes(["T1" => "BY_TABLE", "T2" => "BY_SEAT"]), (new EventCreationParams())->setTableBookingModes(["T1" => "BY_SEAT", "T2" => "BY_TABLE"])]; | ||
|
||
$events = $this->seatsioClient->events->createMultiple($chartKey, $params); | ||
|
||
self::assertEquals(2, sizeof($events)); | ||
self::assertFalse($events[0]->bookWholeTables); | ||
self::assertEquals((object)["T1" => "BY_TABLE", "T2" => "BY_SEAT"], $events[0]->tableBookingModes); | ||
self::assertFalse($events[1]->bookWholeTables); | ||
self::assertEquals((object)["T1" => "BY_SEAT", "T2" => "BY_TABLE"], $events[1]->tableBookingModes); | ||
} | ||
|
||
|
||
} |