-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
767 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
tests/cases/Unit/Controllers/GroupsV1ControllerTest.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Cases; | ||
|
||
use FastyBird\NodeWebServer\Http; | ||
use FastyBird\UINode\Router; | ||
use Fig\Http\Message\RequestMethodInterface; | ||
use React\Http\Io\ServerRequest; | ||
use Tester\Assert; | ||
use Tests\Tools; | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
require_once __DIR__ . '/../DbTestCase.php'; | ||
|
||
final class GroupsV1ControllerTest extends DbTestCase | ||
{ | ||
|
||
/** | ||
* @param string $url | ||
* @param int $statusCode | ||
* @param string $fixture | ||
* | ||
* @dataProvider ./../../../fixtures/Controllers/groupsRead.php | ||
*/ | ||
public function testRead(string $url, int $statusCode, string $fixture): void | ||
{ | ||
/** @var Router\Router $router */ | ||
$router = $this->getContainer()->getByType(Router\Router::class); | ||
|
||
$request = new ServerRequest( | ||
RequestMethodInterface::METHOD_GET, | ||
$url | ||
); | ||
|
||
$response = $router->handle($request); | ||
|
||
Tools\JsonAssert::assertFixtureMatch( | ||
$fixture, | ||
(string) $response->getBody() | ||
); | ||
Assert::same($statusCode, $response->getStatusCode()); | ||
Assert::type(Http\Response::class, $response); | ||
} | ||
|
||
/** | ||
* @param string $url | ||
* @param string $body | ||
* @param int $statusCode | ||
* @param string $fixture | ||
* | ||
* @dataProvider ./../../../fixtures/Controllers/groupsCreate.php | ||
*/ | ||
public function testCreate(string $url, string $body, int $statusCode, string $fixture): void | ||
{ | ||
/** @var Router\Router $router */ | ||
$router = $this->getContainer()->getByType(Router\Router::class); | ||
|
||
$request = new ServerRequest( | ||
RequestMethodInterface::METHOD_POST, | ||
$url, | ||
[], | ||
$body | ||
); | ||
|
||
$response = $router->handle($request); | ||
|
||
Tools\JsonAssert::assertFixtureMatch( | ||
$fixture, | ||
(string) $response->getBody() | ||
); | ||
Assert::same($statusCode, $response->getStatusCode()); | ||
Assert::type(Http\Response::class, $response); | ||
} | ||
|
||
/** | ||
* @param string $url | ||
* @param string $body | ||
* @param int $statusCode | ||
* @param string $fixture | ||
* | ||
* @dataProvider ./../../../fixtures/Controllers/groupsUpdate.php | ||
*/ | ||
public function testUpdate(string $url, string $body, int $statusCode, string $fixture): void | ||
{ | ||
/** @var Router\Router $router */ | ||
$router = $this->getContainer()->getByType(Router\Router::class); | ||
|
||
$request = new ServerRequest( | ||
RequestMethodInterface::METHOD_PATCH, | ||
$url, | ||
[], | ||
$body | ||
); | ||
|
||
$response = $router->handle($request); | ||
|
||
Tools\JsonAssert::assertFixtureMatch( | ||
$fixture, | ||
(string) $response->getBody() | ||
); | ||
Assert::same($statusCode, $response->getStatusCode()); | ||
Assert::type(Http\Response::class, $response); | ||
} | ||
|
||
/** | ||
* @param string $url | ||
* @param int $statusCode | ||
* @param string $fixture | ||
* | ||
* @dataProvider ./../../../fixtures/Controllers/groupsDelete.php | ||
*/ | ||
public function testDelete(string $url, int $statusCode, string $fixture): void | ||
{ | ||
/** @var Router\Router $router */ | ||
$router = $this->getContainer()->getByType(Router\Router::class); | ||
|
||
$request = new ServerRequest( | ||
RequestMethodInterface::METHOD_DELETE, | ||
$url | ||
); | ||
|
||
$response = $router->handle($request); | ||
|
||
Tools\JsonAssert::assertFixtureMatch( | ||
$fixture, | ||
(string) $response->getBody() | ||
); | ||
Assert::same($statusCode, $response->getStatusCode()); | ||
Assert::type(Http\Response::class, $response); | ||
} | ||
|
||
} | ||
|
||
$test_case = new GroupsV1ControllerTest(); | ||
$test_case->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Fig\Http\Message\StatusCodeInterface; | ||
|
||
return [ | ||
'create' => [ | ||
'/v1/dashboards/272379d8-8351-44b6-ad8d-73a0abcb7f9c/groups', | ||
file_get_contents(__DIR__ . '/requests/groups.create.json'), | ||
StatusCodeInterface::STATUS_CREATED, | ||
__DIR__ . '/responses/groups.create.json', | ||
], | ||
'missingRequired' => [ | ||
'/v1/dashboards/272379d8-8351-44b6-ad8d-73a0abcb7f9c/groups', | ||
file_get_contents(__DIR__ . '/requests/groups.create.missing.required.json'), | ||
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY, | ||
__DIR__ . '/responses/missing.required.json', | ||
], | ||
'dashboardNotFound' => [ | ||
'/v1/dashboards/aa2379d8-8351-44b6-ad8d-73a0abcb7f9c/groups', | ||
file_get_contents(__DIR__ . '/requests/groups.create.json'), | ||
StatusCodeInterface::STATUS_NOT_FOUND, | ||
__DIR__ . '/responses/dashboards.notFound.json', | ||
], | ||
'invalidType' => [ | ||
'/v1/dashboards/272379d8-8351-44b6-ad8d-73a0abcb7f9c/groups', | ||
file_get_contents(__DIR__ . '/requests/groups.create.invalidType.json'), | ||
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY, | ||
__DIR__ . '/responses/groups.create.invalidType.json', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Fig\Http\Message\StatusCodeInterface; | ||
|
||
return [ | ||
'delete' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c', | ||
StatusCodeInterface::STATUS_NO_CONTENT, | ||
__DIR__ . '/responses/groups.delete.json', | ||
], | ||
'deleteUnknown' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/88f4a14f-7f78-4216-99b8-584ab9229f1c', | ||
StatusCodeInterface::STATUS_NOT_FOUND, | ||
__DIR__ . '/responses/groups.notFound.json', | ||
], | ||
'dashboardNotFound' => [ | ||
'/v1/dashboards/aa369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c', | ||
StatusCodeInterface::STATUS_NOT_FOUND, | ||
__DIR__ . '/responses/dashboards.notFound.json', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Fig\Http\Message\StatusCodeInterface; | ||
|
||
return [ | ||
'readAll' => [ | ||
'/v1/dashboards/272379d8-8351-44b6-ad8d-73a0abcb7f9c/groups', | ||
StatusCodeInterface::STATUS_OK, | ||
__DIR__ . '/responses/groups.index.json', | ||
], | ||
'readAllPaging' => [ | ||
'/v1/dashboards/272379d8-8351-44b6-ad8d-73a0abcb7f9c/groups?page[offset]=1&page[limit]=1', | ||
StatusCodeInterface::STATUS_OK, | ||
__DIR__ . '/responses/groups.index.paging.json', | ||
], | ||
'readOne' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c', | ||
StatusCodeInterface::STATUS_OK, | ||
__DIR__ . '/responses/groups.read.json', | ||
], | ||
'readOneUnknown' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/69786d15-fd0c-4d9f-9378-33287c2009af', | ||
StatusCodeInterface::STATUS_NOT_FOUND, | ||
__DIR__ . '/responses/groups.notFound.json', | ||
], | ||
'readOneUnknownDashboard' => [ | ||
'/v1/dashboards/bb369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/69786d15-fd0c-4d9f-9378-33287c2009af', | ||
StatusCodeInterface::STATUS_NOT_FOUND, | ||
__DIR__ . '/responses/dashboards.notFound.json', | ||
], | ||
'readRelationshipsWidgets' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c/relationships/widgets', | ||
StatusCodeInterface::STATUS_OK, | ||
__DIR__ . '/responses/groups.readRelationships.widgets.json', | ||
], | ||
'readRelationshipsDashboard' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c/relationships/dashboard', | ||
StatusCodeInterface::STATUS_OK, | ||
__DIR__ . '/responses/groups.readRelationships.dashboard.json', | ||
], | ||
'readRelationshipsUnknown' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c/relationships/unknown', | ||
StatusCodeInterface::STATUS_NOT_FOUND, | ||
__DIR__ . '/responses/relation.unknown.json', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Fig\Http\Message\StatusCodeInterface; | ||
|
||
return [ | ||
'update' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c', | ||
file_get_contents(__DIR__ . '/requests/groups.update.json'), | ||
StatusCodeInterface::STATUS_OK, | ||
__DIR__ . '/responses/groups.update.json', | ||
], | ||
'invalidType' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c', | ||
file_get_contents(__DIR__ . '/requests/groups.update.invalidType.json'), | ||
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY, | ||
__DIR__ . '/responses/groups.update.invalidType.json', | ||
], | ||
'idMismatch' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c', | ||
file_get_contents(__DIR__ . '/requests/groups.update.idMismatch.json'), | ||
StatusCodeInterface::STATUS_BAD_REQUEST, | ||
__DIR__ . '/responses/invalid.identifier.json', | ||
], | ||
'notFound' => [ | ||
'/v1/dashboards/ab369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/88f4a14f-7f78-4216-99b8-584ab9229f1c', | ||
file_get_contents(__DIR__ . '/requests/groups.update.notFound.json'), | ||
StatusCodeInterface::STATUS_NOT_FOUND, | ||
__DIR__ . '/responses/groups.notFound.json', | ||
], | ||
'dashboardNotFound' => [ | ||
'/v1/dashboards/bb369e71-ada6-4d1a-a5a8-b6ee5cd58296/groups/89f4a14f-7f78-4216-99b8-584ab9229f1c', | ||
file_get_contents(__DIR__ . '/requests/groups.update.json'), | ||
StatusCodeInterface::STATUS_NOT_FOUND, | ||
__DIR__ . '/responses/dashboards.notFound.json', | ||
], | ||
]; |
Oops, something went wrong.