Skip to content

Commit

Permalink
ability to add & remove a chart category (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
bverbeken authored Mar 21, 2022
1 parent 16d7108 commit 3d22d1c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Charts/Charts.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ public function update(string $key, string $name = null, array $categories = nul
$this->client->post('/charts/' . $key, ['json' => $request]);
}

public function addCategory(string $key, CategoryRequestBuilder $category): void
{
$this->client->post('/charts/' . $key . '/categories', ['json' => $category]);
}

/**
* @param string $key
* @param $categoryKey string|int
* @return void
*/
public function removeCategory(string $key, $categoryKey): void
{
$this->client->delete('/charts/' . $key . '/categories/' . $categoryKey);
}

public function retrieve(string $key): Chart
{
$res = $this->client->get('/charts/' . $key);
Expand Down
45 changes: 45 additions & 0 deletions tests/Charts/ManageCategoriesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Seatsio\Charts;

use Seatsio\SeatsioClientTest;

class ManageCategoriesTest extends SeatsioClientTest
{

public function testAddCategory()
{
$categories = [
(object)['key' => 1, 'label' => 'Category 1', 'color' => '#aaaaaa', 'accessible' => true]
];
$chart = $this->seatsioClient->charts->create('aChart', null, $categories);

$category2 = (new CategoryRequestBuilder())->setKey(2)->setLabel('Category 2')->setColor('blue');
$this->seatsioClient->charts->addCategory($chart->key, $category2);

$retrievedChart = $this->seatsioClient->charts->retrievePublishedVersion($chart->key);
self::assertEquals('aChart', $retrievedChart->name);
self::assertEquals([
(object)['key' => 1, 'label' => 'Category 1', 'color' => '#aaaaaa', 'accessible' => true],
(object)['key' => 2, 'label' => 'Category 2', 'color' => 'blue', 'accessible' => false]
], $retrievedChart->categories->list);
}

public function testRemoveCategory()
{
$categories = [
(object)['key' => 1, 'label' => 'Category 1', 'color' => '#aaaaaa', 'accessible' => true],
(object)['key' => 'cat2', 'label' => 'Category 2', 'color' => '#bbbbbb', 'accessible' => false]
];
$chart = $this->seatsioClient->charts->create('aChart', null, $categories);

$this->seatsioClient->charts->removeCategory($chart->key, 1);

$retrievedChart = $this->seatsioClient->charts->retrievePublishedVersion($chart->key);
self::assertEquals('aChart', $retrievedChart->name);
self::assertEquals([
(object)['key' => 'cat2', 'label' => 'Category 2', 'color' => '#bbbbbb', 'accessible' => false]
], $retrievedChart->categories->list);
}

}

0 comments on commit 3d22d1c

Please sign in to comment.