Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Apr 29, 2019
2 parents 6ff3ea3 + 60c7b50 commit 4b2a7f2
Show file tree
Hide file tree
Showing 8 changed files with 554 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/Accounts/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ public function retrieveMyAccount()
return \GuzzleHttp\json_decode($res->getBody());
}

}
/**
* @param $key string
* @param $value string
* @return void
*/
public function updateSetting ($key, $value) {
$request = new \stdClass();
$request->key = $key;
$request->value = $value;
$this->client->post('/accounts/me/settings', ['json' => $request]);
}

}
12 changes: 11 additions & 1 deletion src/Accounts/ChartValidationSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ class ChartValidationSettings
*/
public $VALIDATE_UNLABELED_OBJECTS;

}
/**
* @var string
*/
public $VALIDATE_FOCAL_POINT;

/**
* @var string
*/
public $VALIDATE_OBJECT_TYPES_PER_CATEGORY;

}
22 changes: 21 additions & 1 deletion src/Charts/Charts.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ public function retrievePublishedVersionThumbnail($key)
return $res->getBody();
}

/**
* @param $key string
* @return object
*/
public function validatePublishedVersion($key)
{
$res = $this->client->post('/charts/' . $key . '/version/published/actions/validate');
return \GuzzleHttp\json_decode($res->getBody());
}

/**
* @param $key string
* @return object
*/
public function validateDraftVersion($key)
{
$res = $this->client->post('/charts/' . $key . '/version/draft/actions/validate');
return \GuzzleHttp\json_decode($res->getBody());
}

/**
* @param $key string
* @return StreamInterface
Expand Down Expand Up @@ -287,4 +307,4 @@ private function listParamsToArray($chartListParams)
return $chartListParams->toArray();
}

}
}
2 changes: 2 additions & 0 deletions tests/Accounts/RetrieveMyAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public function test()
self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_DUPLICATE_LABELS);
self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_OBJECTS_WITHOUT_CATEGORIES);
self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_UNLABELED_OBJECTS);
self::assertEquals("OFF", $account->settings->chartValidation->VALIDATE_FOCAL_POINT);
self::assertEquals("OFF", $account->settings->chartValidation->VALIDATE_OBJECT_TYPES_PER_CATEGORY);
}
}
22 changes: 22 additions & 0 deletions tests/Accounts/UpdateChartValidationSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Seatsio\Accounts;

use Seatsio\SeatsioClientTest;

class UpdateSetting extends SeatsioClientTest
{
public function test()
{

$this->seatsioClient->accounts->updateSetting('VALIDATE_DUPLICATE_LABELS', 'WARNING');
$this->seatsioClient->accounts->updateSetting('VALIDATE_OBJECT_TYPES_PER_CATEGORY', 'ERROR');

$account = $this->seatsioClient->accounts->retrieveMyAccount();
self::assertEquals("WARNING", $account->settings->chartValidation->VALIDATE_DUPLICATE_LABELS);
self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_OBJECTS_WITHOUT_CATEGORIES);
self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_UNLABELED_OBJECTS);
self::assertEquals("OFF", $account->settings->chartValidation->VALIDATE_FOCAL_POINT);
self::assertEquals("ERROR", $account->settings->chartValidation->VALIDATE_OBJECT_TYPES_PER_CATEGORY);
}
}
35 changes: 35 additions & 0 deletions tests/Charts/validateChartTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Seatsio\Charts;

use Seatsio\SeatsioClientTest;

class ValidateChartTest extends SeatsioClientTest
{
public function testValidatePublishedVersion()
{
$chartKey = $this->createTestChartWithErrors();

$validationRes = $this->seatsioClient->charts->validatePublishedVersion($chartKey);

self::assertEmpty($validationRes->warnings);
self::assertEquals(['VALIDATE_UNLABELED_OBJECTS', 'VALIDATE_DUPLICATE_LABELS', 'VALIDATE_OBJECTS_WITHOUT_CATEGORIES'], $validationRes->errors, '', 0.0, 10, true);
}

public function testValidateDraftVersion() {
$this->seatsioClient->accounts->updateSetting('VALIDATE_DUPLICATE_LABELS', 'WARNING');
$this->seatsioClient->accounts->updateSetting('VALIDATE_UNLABELED_OBJECTS', 'WARNING');
$this->seatsioClient->accounts->updateSetting('VALIDATE_OBJECTS_WITHOUT_CATEGORIES', 'WARNING');
$this->seatsioClient->accounts->updateSetting('VALIDATE_FOCAL_POINT', 'WARNING');
$this->seatsioClient->accounts->updateSetting('VALIDATE_OBJECT_TYPES_PER_CATEGORY', 'WARNING');

$chartKey = $this->createTestChartWithErrors();
$this->seatsioClient->events->create($chartKey);
$this->seatsioClient->charts->update($chartKey, 'New name');

$validationRes = $this->seatsioClient->charts->validateDraftVersion($chartKey);

self::assertEmpty($validationRes->errors);
self::assertEquals(['VALIDATE_UNLABELED_OBJECTS', 'VALIDATE_DUPLICATE_LABELS', 'VALIDATE_OBJECTS_WITHOUT_CATEGORIES', 'VALIDATE_FOCAL_POINT', 'VALIDATE_OBJECT_TYPES_PER_CATEGORY'], $validationRes->warnings, '', 0.0, 10, true);
}
}
7 changes: 6 additions & 1 deletion tests/SeatsioClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ protected function createTestChartWithSections()
return $this->createTestChartFromFile('sampleChartWithSections.json');
}

protected function createTestChartWithErrors()
{
return $this->createTestChartFromFile('sampleChartWithErrors.json');
}

private function createTestChartFromFile($file)
{
$client = new Client();
Expand Down Expand Up @@ -89,4 +94,4 @@ private static function uuid()
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
}
}
Loading

0 comments on commit 4b2a7f2

Please sign in to comment.