Add mapping for assignable_to_pools property of ips index response

This commit is contained in:
Joseph Shanak 2020-10-07 14:45:28 -05:00 committed by David Garcia
parent a91f5f6185
commit 90028dc6a1
3 changed files with 37 additions and 0 deletions

View File

@ -28,6 +28,11 @@ final class IndexResponse implements ApiResponse
*/ */
private $totalCount; private $totalCount;
/**
* @var string[]
*/
private $assignableToPools;
private function __construct() private function __construct()
{ {
} }
@ -37,6 +42,7 @@ final class IndexResponse implements ApiResponse
$model = new self(); $model = new self();
$model->items = $data['items']; $model->items = $data['items'];
$model->totalCount = $data['total_count'] ?? 0; $model->totalCount = $data['total_count'] ?? 0;
$model->assignableToPools = $data['assignable_to_pools'];
return $model; return $model;
} }
@ -49,6 +55,14 @@ final class IndexResponse implements ApiResponse
return $this->items; return $this->items;
} }
/**
* @return string[]
*/
public function getAssignableToPools(): array
{
return $this->assignableToPools;
}
public function getTotalCount(): int public function getTotalCount(): int
{ {
return $this->totalCount; return $this->totalCount;

View File

@ -28,6 +28,7 @@ class IpTest extends TestCase
$this->setRequestUri('/v3/ips'); $this->setRequestUri('/v3/ips');
$this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' $this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON'
{ {
"assignable_to_pools": ["192.168.0.1"],
"items": ["192.161.0.1", "192.168.0.2"], "items": ["192.161.0.1", "192.168.0.2"],
"total_count": 2 "total_count": 2
} }
@ -41,6 +42,7 @@ JSON
$this->assertEquals(2, $response->getTotalCount()); $this->assertEquals(2, $response->getTotalCount());
$this->assertEquals('192.161.0.1', $response->getItems()[0]); $this->assertEquals('192.161.0.1', $response->getItems()[0]);
$this->assertEquals('192.168.0.2', $response->getItems()[1]); $this->assertEquals('192.168.0.2', $response->getItems()[1]);
$this->assertEquals('192.168.0.1', $response->getAssignableToPools()[0]);
} }
public function testIndexOnlyDedicated() public function testIndexOnlyDedicated()
@ -49,6 +51,7 @@ JSON
$this->setRequestUri('/v3/ips?dedicated=1'); $this->setRequestUri('/v3/ips?dedicated=1');
$this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' $this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON'
{ {
"assignable_to_pools": ["192.168.0.1"],
"items": ["192.161.0.1"], "items": ["192.161.0.1"],
"total_count": 1 "total_count": 1
} }
@ -61,6 +64,7 @@ JSON
$this->assertInstanceOf(IndexResponse::class, $response); $this->assertInstanceOf(IndexResponse::class, $response);
$this->assertEquals(1, $response->getTotalCount()); $this->assertEquals(1, $response->getTotalCount());
$this->assertEquals('192.161.0.1', $response->getItems()[0]); $this->assertEquals('192.161.0.1', $response->getItems()[0]);
$this->assertEquals('192.168.0.1', $response->getAssignableToPools()[0]);
} }
public function testIndexOnlyShared() public function testIndexOnlyShared()
@ -69,6 +73,7 @@ JSON
$this->setRequestUri('/v3/ips?dedicated=0'); $this->setRequestUri('/v3/ips?dedicated=0');
$this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' $this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON'
{ {
"assignable_to_pools": ["192.168.0.1"],
"items": ["192.168.0.2"], "items": ["192.168.0.2"],
"total_count": 1 "total_count": 1
} }
@ -81,5 +86,6 @@ JSON
$this->assertInstanceOf(IndexResponse::class, $response); $this->assertInstanceOf(IndexResponse::class, $response);
$this->assertEquals(1, $response->getTotalCount()); $this->assertEquals(1, $response->getTotalCount());
$this->assertEquals('192.168.0.2', $response->getItems()[0]); $this->assertEquals('192.168.0.2', $response->getItems()[0]);
$this->assertEquals('192.168.0.1', $response->getAssignableToPools()[0]);
} }
} }

View File

@ -21,6 +21,7 @@ class IndexResponseTest extends BaseModelTest
$json = $json =
<<<'JSON' <<<'JSON'
{ {
"assignable_to_pools": ["192.161.0.1"],
"items": ["192.161.0.1", "192.168.0.2"], "items": ["192.161.0.1", "192.168.0.2"],
"total_count": 2 "total_count": 2
} }
@ -31,4 +32,20 @@ JSON;
$this->assertCount(2, $items); $this->assertCount(2, $items);
$this->assertEquals('192.161.0.1', $items[0]); $this->assertEquals('192.161.0.1', $items[0]);
} }
public function testCreateWithAssignableToPools()
{
$json =
<<<'JSON'
{
"assignable_to_pools": ["192.161.0.1"],
"items": ["192.161.0.1", "192.168.0.2"],
"total_count": 2
}
JSON;
$model = IndexResponse::create(json_decode($json, true));
$assignableToPools = $model->getAssignableToPools();
$this->assertCount(1, $assignableToPools);
$this->assertEquals('192.161.0.1', $assignableToPools[0]);
}
} }