Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Resources/Workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Workspace extends Resource

public ?string $serverId = null;

public ?string $url = null;

public ?string $branch = null;

public bool $branchRenamed = false;
Expand Down
36 changes: 36 additions & 0 deletions tests/PolyscopeSDKTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,38 @@ public function test_repositories_support_server_filter(): void
$this->assertSame('srv-1', $repositories[0]->serverId);
}

public function test_listing_workspaces_maps_url(): void
{
$sdk = new Polyscope('token', $http = Mockery::mock(Client::class));

$http->shouldReceive('request')
->once()
->with('GET', 'v1/workspaces', Mockery::on(function (array $options): bool {
return ($options['timeout'] ?? null) === 30
&& ($options['query']['server_id'] ?? null) === 'srv-1';
}))
->andReturn(new Response(200, [], json_encode([
'data' => [
[
'id' => 'wt-1',
'server_id' => 'srv-1',
'url' => 'https://getpolyscope.com/servers/srv-1/session?workspace=wt-1',
],
[
'id' => 'wt-2',
'server_id' => 'srv-1',
],
],
], JSON_THROW_ON_ERROR)));

$workspaces = $sdk->workspaces(['server_id' => 'srv-1']);

$this->assertCount(2, $workspaces);
$this->assertInstanceOf(Workspace::class, $workspaces[0]);
$this->assertSame('https://getpolyscope.com/servers/srv-1/session?workspace=wt-1', $workspaces[0]->url);
$this->assertNull($workspaces[1]->url);
}

public function test_creating_workspace_returns_workspace_resource(): void
{
$sdk = new Polyscope('token', $http = Mockery::mock(Client::class));
Expand All @@ -169,6 +201,7 @@ public function test_creating_workspace_returns_workspace_resource(): void
'id' => 'wt-1',
'repo_id' => 'repo-1',
'server_id' => 'srv-1',
'url' => 'https://getpolyscope.com/servers/srv-1/session?workspace=wt-1',
'branch' => 'fix-bug',
'branch_renamed' => false,
'path' => '/code/polyscope/.polyscope/worktrees/fix-bug',
Expand Down Expand Up @@ -198,6 +231,7 @@ public function test_creating_workspace_returns_workspace_resource(): void
$this->assertSame('wt-1', $workspace->id);
$this->assertSame('repo-1', $workspace->repoId);
$this->assertSame('srv-1', $workspace->serverId);
$this->assertSame('https://getpolyscope.com/servers/srv-1/session?workspace=wt-1', $workspace->url);
$this->assertSame('fix-bug', $workspace->branch);
$this->assertFalse($workspace->branchRenamed);
$this->assertSame('/code/polyscope/.polyscope/worktrees/fix-bug', $workspace->path);
Expand Down Expand Up @@ -313,6 +347,7 @@ public function test_workspace_show_maps_nested_properties(): void
'id' => 'wt-1',
'repo_id' => 'repo-1',
'server_id' => 'srv-1',
'url' => 'https://getpolyscope.com/servers/srv-1/session?workspace=wt-1',
'branch' => 'fix-bug',
'branch_renamed' => true,
'path' => '/code/polyscope/.polyscope/worktrees/fix-bug',
Expand Down Expand Up @@ -349,6 +384,7 @@ public function test_workspace_show_maps_nested_properties(): void
$this->assertSame('wt-1', $workspace->id);
$this->assertSame('repo-1', $workspace->repoId);
$this->assertSame('srv-1', $workspace->serverId);
$this->assertSame('https://getpolyscope.com/servers/srv-1/session?workspace=wt-1', $workspace->url);
$this->assertTrue($workspace->branchRenamed);
$this->assertSame(12, $workspace->prNumber);
$this->assertSame('https://github.com/beyondcode/polyscope/pull/12', $workspace->prUrl);
Expand Down
Loading