From 8fa887fb87920675a5400ed5d6f48e7c2b0dc5d5 Mon Sep 17 00:00:00 2001 From: mroloux Date: Mon, 16 Oct 2023 16:37:06 +0200 Subject: [PATCH] Added call that copies a chart from a workspace to another workspace (#100) --- src/Charts/Charts.php | 8 +++++++ tests/Charts/CopyChartFromWorkspaceToTest.php | 24 +++++++++++++++++++ tests/SeatsioClientTest.php | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 tests/Charts/CopyChartFromWorkspaceToTest.php diff --git a/src/Charts/Charts.php b/src/Charts/Charts.php index c78016d..f100bd9 100644 --- a/src/Charts/Charts.php +++ b/src/Charts/Charts.php @@ -161,6 +161,14 @@ public function copyToWorkspace(string $chartKey, string $toWorkspaceKey): Chart return $mapper->map($json, new Chart()); } + public function copyFromWorkspaceTo(string $chartKey, string $fromWorkspaceKey, string $toWorkspaceKey): Chart + { + $res = $this->client->post('/charts/' . $chartKey . '/version/published/actions/copy/from/' . $fromWorkspaceKey . '/to/' . $toWorkspaceKey); + $json = Utils::jsonDecode($res->getBody()); + $mapper = SeatsioJsonMapper::create(); + return $mapper->map($json, new Chart()); + } + public function retrievePublishedVersionThumbnail(string $key): StreamInterface { $res = $this->client->get('/charts/' . $key . '/version/published/thumbnail'); diff --git a/tests/Charts/CopyChartFromWorkspaceToTest.php b/tests/Charts/CopyChartFromWorkspaceToTest.php new file mode 100644 index 0000000..422bfb7 --- /dev/null +++ b/tests/Charts/CopyChartFromWorkspaceToTest.php @@ -0,0 +1,24 @@ +seatsioClient->charts->create('my chart'); + $toWorkspace = $this->seatsioClient->workspaces->create('my ws'); + $toWorkspaceSeatsioClient = self::createSeatsioClient($toWorkspace->secretKey); + + $copiedChart = $this->seatsioClient->charts->copyFromWorkspaceTo($chart->key, $this->workspace->key, $toWorkspace->key); + + self::assertEquals('my chart', $copiedChart->name); + self::assertNotEquals($chart->key, $copiedChart->key); + $retrievedChart = $toWorkspaceSeatsioClient->charts->retrieve($copiedChart->key); + self::assertEquals('my chart', $retrievedChart->name); + } + +} diff --git a/tests/SeatsioClientTest.php b/tests/SeatsioClientTest.php index 8bc4b50..7b04661 100644 --- a/tests/SeatsioClientTest.php +++ b/tests/SeatsioClientTest.php @@ -15,11 +15,13 @@ abstract class SeatsioClientTest extends TestCase protected $seatsioClient; protected $user; + protected $workspace; protected function setUp(): void { $company = $this->createTestCompany(); $this->user = $company->admin; + $this->workspace = $company->workspace; $this->seatsioClient = self::createSeatsioClient($this->user->secretKey); }