Skip to content

Commit

Permalink
Added call that copies a chart from a workspace to another workspace (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Oct 16, 2023
1 parent d744dce commit 8fa887f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Charts/Charts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
24 changes: 24 additions & 0 deletions tests/Charts/CopyChartFromWorkspaceToTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Charts;

use Seatsio\SeatsioClientTest;

class CopyChartFromWorkspaceToTest extends SeatsioClientTest
{

public function test()
{
$chart = $this->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);
}

}
2 changes: 2 additions & 0 deletions tests/SeatsioClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 8fa887f

Please sign in to comment.