Skip to content

Commit

Permalink
Added chart report summary calls (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Jan 31, 2022
1 parent 971b1a5 commit b4a68d2
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Reports/Charts/ChartReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public function byObjectType($chartKey, $bookWholeTables = null)
return $this->getChartReport('byObjectType', $chartKey, $bookWholeTables);
}

/**
* @param $chartKey string
* @return array
*/
public function summaryByObjectType($chartKey)
{
$res = $this->client->get(self::summaryReportUrl('byObjectType', $chartKey));
return \GuzzleHttp\json_decode($res->getBody(), true);
}

/**
* @param $chartKey string
* @param $bookWholeTables string
Expand All @@ -50,6 +60,16 @@ public function byCategoryKey($chartKey, $bookWholeTables = null)
return $this->getChartReport('byCategoryKey', $chartKey, $bookWholeTables);
}

/**
* @param $chartKey string
* @return array
*/
public function summaryByCategoryKey($chartKey)
{
$res = $this->client->get(self::summaryReportUrl('byCategoryKey', $chartKey));
return \GuzzleHttp\json_decode($res->getBody(), true);
}

/**
* @param $chartKey string
* @param $bookWholeTables string
Expand All @@ -60,11 +80,46 @@ public function byCategoryLabel($chartKey, $bookWholeTables = null)
return $this->getChartReport('byCategoryLabel', $chartKey, $bookWholeTables);
}

/**
* @param $chartKey string
* @return array
*/
public function summaryByCategoryLabel($chartKey)
{
$res = $this->client->get(self::summaryReportUrl('byCategoryLabel', $chartKey));
return \GuzzleHttp\json_decode($res->getBody(), true);
}

/**
* @param $chartKey string
* @param $objectType string
* @return array
*/
public function bySection($chartKey, $bookWholeTables = null)
{
return $this->getChartReport('bySection', $chartKey, $bookWholeTables);
}

/**
* @param $chartKey string
* @return array
*/
public function summaryBySection($chartKey)
{
$res = $this->client->get(self::summaryReportUrl('bySection', $chartKey));
return \GuzzleHttp\json_decode($res->getBody(), true);
}

private static function reportUrl($reportType, $eventKey)
{
return UriTemplate::expand('/reports/charts/{key}/{reportType}', array("key" => $eventKey, "reportType" => $reportType));
}

private static function summaryReportUrl($reportType, $chartKey)
{
return UriTemplate::expand('/reports/charts/{key}/{reportType}/summary', array("key" => $chartKey, "reportType" => $reportType));
}

private function getChartReport($reportType, $chartKey, $bookWholeTables)
{
$res = $this->client->get(self::reportUrl($reportType, $chartKey), ["query" => ["bookWholeTables" => $bookWholeTables]]);
Expand Down
114 changes: 114 additions & 0 deletions tests/Reports/ChartReportsSummaryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace Seatsio\Reports;

use Seatsio\Events\Channel;
use Seatsio\Events\ObjectProperties;
use Seatsio\SeatsioClientTest;

class ChartReportsSummaryTest extends SeatsioClientTest
{
public function testSummaryByObjectType()
{
$chartKey = $this->createTestChart();

$report = $this->seatsioClient->chartReports->summaryByObjectType($chartKey);

$expectedReport = [
'seat' => [
'count' => 32,
'byCategoryKey' => [9 => 16, 10 => 16],
'byCategoryLabel' => ['Cat2' => 16, 'Cat1' => 16],
'bySection' => ['NO_SECTION' => 32]
],
'generalAdmission' => [
'count' => 200,
'byCategoryKey' => [9 => 100, 10 => 100],
'byCategoryLabel' => ['Cat1' => 100, 'Cat2' => 100],
'bySection' => ['NO_SECTION' => 200]
],
'table' => [
'count' => 0,
'byCategoryKey' => [],
'byCategoryLabel' => [],
'bySection' => []
],
'booth' => [
'count' => 0,
'byCategoryKey' => [],
'byCategoryLabel' => [],
'bySection' => []
]
];
self::assertEquals($expectedReport, $report);
}

public function testSummaryByCategoryKey()
{
$chartKey = $this->createTestChart();

$report = $this->seatsioClient->chartReports->summaryByCategoryKey($chartKey);

$expectedReport = [
'9' => [
'count' => 116,
'bySection' => ['NO_SECTION' => 116],
'byObjectType' => ['seat' => 16, 'generalAdmission' => 100]
],
'10' => [
'count' => 116,
'bySection' => ['NO_SECTION' => 116],
'byObjectType' => ['seat' => 16, 'generalAdmission' => 100]
],
'NO_CATEGORY' => [
'count' => 0,
'bySection' => [],
'byObjectType' => []
]
];
self::assertEquals($expectedReport, $report);
}

public function testSummaryByCategoryLabel()
{
$chartKey = $this->createTestChart();

$report = $this->seatsioClient->chartReports->summaryByCategoryLabel($chartKey);

$expectedReport = [
'Cat1' => [
'count' => 116,
'bySection' => ['NO_SECTION' => 116],
'byObjectType' => ['seat' => 16, 'generalAdmission' => 100]
],
'Cat2' => [
'count' => 116,
'bySection' => ['NO_SECTION' => 116],
'byObjectType' => ['seat' => 16, 'generalAdmission' => 100]
],
'NO_CATEGORY' => [
'count' => 0,
'bySection' => [],
'byObjectType' => []
]
];
self::assertEquals($expectedReport, $report);
}

public function testSummaryBySection()
{
$chartKey = $this->createTestChart();

$report = $this->seatsioClient->chartReports->summaryBySection($chartKey);

$expectedReport = [
'NO_SECTION' => [
'count' => 232,
'byCategoryKey' => [9 => 116, 10 => 116],
'byCategoryLabel' => ['Cat2' => 116, 'Cat1' => 116],
'byObjectType' => ['seat' => 32, 'generalAdmission' => 200]
]
];
self::assertEquals($expectedReport, $report);
}
}
18 changes: 18 additions & 0 deletions tests/Reports/ChartReportsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testByLabel()
$chartKey = $this->createTestChart();

$report = $this->seatsioClient->chartReports->byLabel($chartKey);

self::assertCount(1, $report["A-1"]);
self::assertCount(1, $report["A-2"]);
}
Expand All @@ -54,6 +55,7 @@ public function testByObjectType()
$chartKey = $this->createTestChart();

$report = $this->seatsioClient->chartReports->byObjectType($chartKey);

self::assertCount(32, $report["seat"]);
self::assertCount(2, $report["generalAdmission"]);
}
Expand All @@ -63,6 +65,7 @@ public function testByLabel_bookWholeTablesNull()
$chartKey = $this->createTestChartWithTables();

$report = $this->seatsioClient->chartReports->byLabel($chartKey);

self::assertCount(14, array_keys($report));
}

Expand All @@ -71,6 +74,7 @@ public function testByLabel_bookWholeTablesChart()
$chartKey = $this->createTestChartWithTables();

$report = $this->seatsioClient->chartReports->byLabel($chartKey, 'chart');

self::assertCount(7, array_keys($report));
}

Expand All @@ -79,6 +83,7 @@ public function testByLabel_bookWholeTablesTrue()
$chartKey = $this->createTestChartWithTables();

$report = $this->seatsioClient->chartReports->byLabel($chartKey, 'true');

self::assertCount(2, array_keys($report));
}

Expand All @@ -87,6 +92,7 @@ public function testByLabel_bookWholeTablesFalse()
$chartKey = $this->createTestChartWithTables();

$report = $this->seatsioClient->chartReports->byLabel($chartKey, 'false');

self::assertCount(12, array_keys($report));
}

Expand All @@ -95,6 +101,7 @@ public function testByCategoryKey()
$chartKey = $this->createTestChart();

$report = $this->seatsioClient->chartReports->byCategoryKey($chartKey);

self::assertCount(17, $report["9"]);
self::assertCount(17, $report["10"]);
}
Expand All @@ -104,8 +111,19 @@ public function testByCategoryLabel()
$chartKey = $this->createTestChart();

$report = $this->seatsioClient->chartReports->byCategoryLabel($chartKey);

self::assertCount(17, $report["Cat1"]);
self::assertCount(17, $report["Cat2"]);
}

public function testBySection()
{
$chartKey = $this->createTestChartWithSections();

$report = $this->seatsioClient->chartReports->bySection($chartKey);

self::assertCount(36, $report["Section A"]);
self::assertCount(35, $report["Section B"]);
}

}

0 comments on commit b4a68d2

Please sign in to comment.