Skip to content

Commit 0e0a902

Browse files
committed
Fix endpoint, add unit test
1 parent 8776b58 commit 0e0a902

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/Service/BrancherApp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BrancherApp extends AbstractService
2020
*/
2121
public function list(string $app, ?array $data = null): array
2222
{
23-
$url = sprintf(App::V2_APP_BRANCHER_URL, $app);
23+
$url = sprintf(App::V2_BRANCHER_APP_URL, $app);
2424

2525
$response = $this->client->api->get($url, [], $data ? json_encode($data) : null);
2626

@@ -42,7 +42,7 @@ public function list(string $app, ?array $data = null): array
4242
*/
4343
public function create(string $app, ?array $data = null): string
4444
{
45-
$url = sprintf(App::V2_APP_BRANCHER_URL, $app);
45+
$url = sprintf(App::V2_BRANCHER_APP_URL, $app);
4646

4747
$response = $this->client->api->post($url, [], $data ? json_encode($data) : null);
4848

tests/unit/Service/BrancherAppTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,49 @@
1111

1212
class BrancherAppTest extends HypernodeClientTestCase
1313
{
14+
public function testListBrancherApp()
15+
{
16+
$this->responses->append(
17+
new Response(200, [], json_encode([
18+
'name' => 'johndoe-eph123456',
19+
'parent' => 'johndoe',
20+
'type' => 'brancher',
21+
'branchers' => []
22+
])),
23+
);
24+
25+
$branchers = $this->client->brancherApp->list('johndoe');
26+
27+
$request = $this->responses->getLastRequest();
28+
$this->assertEquals('GET', $request->getMethod());
29+
$this->assertEquals('/v2/brancher/app/johndoe/', $request->getUri());
30+
$this->assertEquals([], $branchers);
31+
}
32+
33+
public function testListBrancherAppRaisesClientExceptions()
34+
{
35+
$badRequestResponse = new Response(400, [], json_encode([
36+
'non_field_errors' => ['Your request was invalid.']
37+
]));
38+
$this->responses->append($badRequestResponse);
39+
40+
$this->expectExceptionObject(new HypernodeApiClientException($badRequestResponse));
41+
42+
$this->client->brancherApp->list('johndoe');
43+
}
44+
45+
public function testListBrancherAppRaisesServerExceptions()
46+
{
47+
$badRequestResponse = new Response(500, [], json_encode([
48+
'non_field_errors' => ['Something went wrong processing your request.']
49+
]));
50+
$this->responses->append($badRequestResponse);
51+
52+
$this->expectExceptionObject(new HypernodeApiServerException($badRequestResponse));
53+
54+
$this->client->brancherApp->list('johndoe');
55+
}
56+
1457
public function testCreateBrancherApp()
1558
{
1659
$this->responses->append(

0 commit comments

Comments
 (0)