Skip to content

Commit

Permalink
Add validation to chartlistparams (#20)
Browse files Browse the repository at this point in the history
* Add validation to chartlistparams

* Improve tests

* fix validation condition
  • Loading branch information
nahue authored Jun 12, 2019
1 parent a269fbf commit 848c384
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Charts/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ class Chart
* @var boolean
*/
public $archived;

/**
* @var array
*/
public $validation;
}
17 changes: 16 additions & 1 deletion src/Charts/ChartListParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ class ChartListParams
* @param $tag string
* @param $expandEvents boolean
*/
public function __construct($filter = null, $tag = null, $expandEvents = null)
public function __construct($filter = null, $tag = null, $expandEvents = null, $withValidation = false)
{
$this->filter = $filter;
$this->tag = $tag;
$this->expandEvents = $expandEvents;
$this->validation = $withValidation;
}

/**
Expand Down Expand Up @@ -63,6 +64,16 @@ public function withExpandEvents($expandEvents)
return $this;
}

/**
* @param $withValidation boolean
* @return $this
*/
public function withValidation($withValidation)
{
$this->validation = $withValidation;
return $this;
}

public function toArray()
{
$result = [];
Expand All @@ -79,6 +90,10 @@ public function toArray()
$result["expand"] = "events";
}

if ($this->validation) {
$result["validation"] = "true";
}

return $result;
}
}
34 changes: 34 additions & 0 deletions tests/Charts/ListAllChartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,38 @@ public function testExpand()
self::assertEquals([$event2->id, $event1->id], array_values($eventIds));
}

public function testWithValidation()
{
self::createTestChartWithErrors();

$charts = $this->seatsioClient->charts->listAll((new ChartListParams())->withValidation(true));
$validations = \Functional\map($charts, function ($chart) {
return $chart->validation;
});

$expected = [
["errors" => [
"VALIDATE_DUPLICATE_LABELS",
"VALIDATE_UNLABELED_OBJECTS",
"VALIDATE_OBJECTS_WITHOUT_CATEGORIES"
], "warnings" => []]
];

self::assertEquals($expected, array_values($validations));
}

public function testWithoutValidation()
{
$this->seatsioClient->charts->create();

$charts = $this->seatsioClient->charts->listAll((new ChartListParams()));
$validations = \Functional\map($charts, function ($chart) {
return $chart->validation;
});

$expected = [null];

self::assertEquals($expected, array_values($validations));
}

}

0 comments on commit 848c384

Please sign in to comment.