Skip to content

Commit 0987c68

Browse files
author
Jonathan Visser
committed
Add support for ordering a new Hypernode (POST /v2/app/order/)
1 parent 49e852a commit 0987c68

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

src/Service/App.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class App extends AbstractService
1414
public const V1_APP_FLOWS_URL = "/logbook/v1/logbooks/%s/flows/";
1515
public const V2_APP_BLOCK_ATTACK_DESCRIPTIONS_URL = "/v2/app/block_attack_descriptions/";
1616
public const V2_APP_EAV_DESCRIPTIONS_URL = "/v2/app/eav_descriptions/";
17+
public const V2_APP_ORDER_URL = "/v2/app/order/";
1718

1819
/**
1920
* @param array $params
@@ -81,4 +82,21 @@ public function getEavDescriptions(): array
8182

8283
return $this->client->getJsonFromResponse($response);
8384
}
85+
86+
/**
87+
* Order a new Hypernode under your account.
88+
*
89+
* @param array $data Order data, requires at least the keys
90+
* `product_code`, `app_name` and `initial_app_configuration`.
91+
* @return void
92+
* @throws \Http\Client\Exception
93+
* @throws \Hypernode\Api\Exception\HypernodeApiClientException
94+
* @throws \Hypernode\Api\Exception\HypernodeApiServerException
95+
*/
96+
public function order(array $data): void
97+
{
98+
$response = $this->client->api->post(self::V2_APP_ORDER_URL, [], json_encode($data));
99+
100+
$this->client->maybeThrowApiExceptions($response);
101+
}
84102
}

tests/unit/Service/AppTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,48 @@ public function testGetEavDescriptionsRaisesServerExceptions()
198198

199199
$this->client->app->getEavDescriptions();
200200
}
201+
202+
public function testOrder()
203+
{
204+
$this->responses->append(
205+
new Response(201, [], null),
206+
);
207+
208+
$orderData = [
209+
'product_code' => 'FALCON_M_202203',
210+
'app_name' => 'johndoe',
211+
'initial_app_configuration' => 'magento_2',
212+
];
213+
$this->client->app->order($orderData);
214+
215+
$request = $this->responses->getLastRequest();
216+
$this->assertEquals('POST', $request->getMethod());
217+
$this->assertEquals('/v2/app/order/', $request->getUri());
218+
$this->assertJson((string)$request->getBody());
219+
$this->assertEquals($orderData, json_decode((string)$request->getBody(), true));
220+
}
221+
222+
public function testOrderRaisesClientExceptions()
223+
{
224+
$badRequestResponse = new Response(400, [], json_encode([
225+
'non_field_errors' => ['Your request was invalid.']
226+
]));
227+
$this->responses->append($badRequestResponse);
228+
229+
$this->expectExceptionObject(new HypernodeApiClientException($badRequestResponse));
230+
231+
$this->client->app->order(['product_code' => 'FALCON_M_202203']);
232+
}
233+
234+
public function testOrderRaisesServerExceptions()
235+
{
236+
$badRequestResponse = new Response(500, [], json_encode([
237+
'non_field_errors' => ['Something went wrong processing your request.']
238+
]));
239+
$this->responses->append($badRequestResponse);
240+
241+
$this->expectExceptionObject(new HypernodeApiServerException($badRequestResponse));
242+
243+
$this->client->app->order(['product_code' => 'FALCON_M_202203']);
244+
}
201245
}

0 commit comments

Comments
 (0)