diff --git a/src/Service/BrancherApp.php b/src/Service/BrancherApp.php index ae5b62f..94a238e 100644 --- a/src/Service/BrancherApp.php +++ b/src/Service/BrancherApp.php @@ -10,18 +10,19 @@ class BrancherApp extends AbstractService { /** - * Create an brancher app for given parent app. + * Create a brancher app for given parent app. * * @param string $app Name of the parent app + * @param array|null $data Extra data to be provided * @return string Name of the brancher app * @throws HypernodeApiClientException * @throws HypernodeApiServerException */ - public function create(string $app): string + public function create(string $app, ?array $data = null): string { $url = sprintf(App::V2_APP_BRANCHER_URL, $app); - $response = $this->client->api->post($url); + $response = $this->client->api->post($url, [], $data ? json_encode($data) : null); $this->client->maybeThrowApiExceptions($response); diff --git a/tests/unit/Service/BrancherAppTest.php b/tests/unit/Service/BrancherAppTest.php index 6a8e9c2..36d9461 100644 --- a/tests/unit/Service/BrancherAppTest.php +++ b/tests/unit/Service/BrancherAppTest.php @@ -29,6 +29,32 @@ public function testCreateBrancherApp() $this->assertEquals('johndoe-eph123456', $brancherAppName); } + public function testCreateBrancherAppWithData() + { + $this->responses->append( + new Response(200, [], json_encode([ + 'name' => 'johndoe-eph123456', + 'parent' => 'johndoe', + 'type' => 'brancher', + ])), + ); + + $brancherAppName = $this->client->brancherApp->create( + 'johndoe', + ['labels' => ['mybranchernode', 'mylabel=myvalue']] + ); + + $request = $this->responses->getLastRequest(); + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('/v2/app/johndoe/brancher/', $request->getUri()); + $this->assertEquals('johndoe-eph123456', $brancherAppName); + $this->assertJson((string)$request->getBody()); + $this->assertEquals( + ['labels' => ['mybranchernode', 'mylabel=myvalue']], + json_decode((string)$request->getBody(), true) + ); + } + public function testCreateBrancherAppRaisesClientExceptions() { $badRequestResponse = new Response(400, [], json_encode([