diff --git a/tests/API/Endpoints/ApiTokenEnpointTest.php b/tests/API/Endpoints/ApiTokenEnpointTest.php new file mode 100644 index 00000000..1050eb1c --- /dev/null +++ b/tests/API/Endpoints/ApiTokenEnpointTest.php @@ -0,0 +1,40 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Tests\API\Endpoints; + +use App\Tests\API\AuthenticatedApiTestCase; + +class ApiTokenEnpointTest extends AuthenticatedApiTestCase +{ + public function testGetCurrentToken(): void + { + $response = self::createAuthenticatedClient()->request('GET', '/api/tokens/current'); + self::assertResponseIsSuccessful(); + + self::assertJsonContains([ + 'name' => 'admin', + 'level' => 3, + ]); + } +} \ No newline at end of file diff --git a/tests/API/Endpoints/CategoryEndpointTest.php b/tests/API/Endpoints/CategoryEndpointTest.php index d35f26d4..68f4fd2d 100644 --- a/tests/API/Endpoints/CategoryEndpointTest.php +++ b/tests/API/Endpoints/CategoryEndpointTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace App\Tests\Endpoints; +namespace App\Tests\API\Endpoints; use App\Tests\API\Endpoints\CrudEndpointTestCase; diff --git a/tests/API/Endpoints/CrudEndpointTestCase.php b/tests/API/Endpoints/CrudEndpointTestCase.php index f60c2a50..2431f836 100644 --- a/tests/API/Endpoints/CrudEndpointTestCase.php +++ b/tests/API/Endpoints/CrudEndpointTestCase.php @@ -44,6 +44,16 @@ abstract class CrudEndpointTestCase extends AuthenticatedApiTestCase return $basePath . $id; } + /** + * Returns the id of the created element from the response. + * @param ResponseInterface $response + * @return int + */ + protected function getIdOfCreatedElement(ResponseInterface $response): int + { + return $response->toArray(true)['id']; + } + protected function _testGetCollection(): ResponseInterface { $response = self::createAuthenticatedClient()->request('GET', $this->getBasePath()); diff --git a/tests/API/Endpoints/OrderdetailsEndpointTest.php b/tests/API/Endpoints/OrderdetailsEndpointTest.php new file mode 100644 index 00000000..92823103 --- /dev/null +++ b/tests/API/Endpoints/OrderdetailsEndpointTest.php @@ -0,0 +1,76 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Tests\API\Endpoints; + +use App\Tests\API\Endpoints\CrudEndpointTestCase; + +class OrderdetailsEndpointTest extends CrudEndpointTestCase +{ + + protected function getBasePath(): string + { + return '/api/orderdetails'; + } + + public function testGetCollection(): void + { + $this->_testGetCollection(); + self::assertJsonContains([ + 'hydra:totalItems' => 2, + ]); + } + + public function testGetItem(): void + { + $this->_testGetItem(1); + $this->_testGetItem(2); + } + + public function testCreateItem(): void + { + $this->_testPostItem([ + 'supplier' => '/api/suppliers/1', + 'part' => '/api/parts/2', + ]); + } + + public function testUpdateItem(): void + { + $response = $this->_testPostItem([ + 'supplier' => '/api/suppliers/1', + 'part' => '/api/parts/2', + ]); + + $id = $this->getIdOfCreatedElement($response); + + $this->_testPatchItem($id, [ + 'supplierpartnr' => 'API test', + ]); + } + + public function testDeleteItem(): void + { + $this->_testDeleteItem(2); + } +} \ No newline at end of file diff --git a/tests/API/Endpoints/ParametersEndpointTest.php b/tests/API/Endpoints/ParametersEndpointTest.php new file mode 100644 index 00000000..733df59a --- /dev/null +++ b/tests/API/Endpoints/ParametersEndpointTest.php @@ -0,0 +1,62 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Tests\API\Endpoints; + +class ParametersEndpointTest extends CrudEndpointTestCase +{ + + protected function getBasePath(): string + { + return '/api/parameters'; + } + + public function testElementLifecycle(): void + { + //Type should be automatically guessed from the element + $this->_testPostItem([ + 'name' => 'test', + 'element' => '/api/parts/1', + ]); + + //Or manually set + $response = $this->_testPostItem([ + 'name' => 'test', + 'element' => '/api/footprints/1', + '_type' => 'Footprint' + ]); + + $id = $this->getIdOfCreatedElement($response); + + //Check if the new item is in the database + $this->_testGetItem($id); + + //Check if we can change the item + $this->_testPatchItem($id, [ + 'name' => 'test2', + ]); + + //Check if we can delete the item + $this->_testDeleteItem($id); + } +} \ No newline at end of file diff --git a/tests/API/Endpoints/PartAssociationsEndpointTest.php b/tests/API/Endpoints/PartAssociationsEndpointTest.php new file mode 100644 index 00000000..62408dbb --- /dev/null +++ b/tests/API/Endpoints/PartAssociationsEndpointTest.php @@ -0,0 +1,62 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Tests\API\Endpoints; + +use App\Tests\API\Endpoints\CrudEndpointTestCase; + +class PartAssociationsEndpointTest extends CrudEndpointTestCase +{ + + protected function getBasePath(): string + { + return '/api/part_associations'; + } + + public function testGetCollection(): void + { + $this->_testGetCollection(); + self::assertJsonContains([ + 'hydra:totalItems' => 0, + ]); + } + + public function testLifeCycle(): void + { + $response = $this->_testPostItem([ + "owner" => '/api/parts/1', + "other" => '/api/parts/2', + 'type' => 1, + ]); + + $id = $this->getIdOfCreatedElement($response); + + $this->_testGetItem($id); + + $this->_testPatchItem($id, [ + 'comment' => 'Test comment' + ]); + + $this->_testDeleteItem($id); + } +} \ No newline at end of file diff --git a/tests/API/Endpoints/PartLotsEndpointTest.php b/tests/API/Endpoints/PartLotsEndpointTest.php new file mode 100644 index 00000000..38aa6b18 --- /dev/null +++ b/tests/API/Endpoints/PartLotsEndpointTest.php @@ -0,0 +1,71 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Tests\API\Endpoints; + +use App\Tests\API\Endpoints\CrudEndpointTestCase; + +class PartLotsEndpointTest extends CrudEndpointTestCase +{ + + protected function getBasePath(): string + { + return '/api/part_lots'; + } + + public function testGetCollection(): void + { + $this->_testGetCollection(); + self::assertJsonContains([ + 'hydra:totalItems' => 2, + ]); + } + + public function testGetItem(): void + { + $this->_testGetItem(1); + $this->_testGetItem(2); + } + + public function testCreateItem(): void + { + $this->_testPostItem([ + 'name' => 'API test', + 'part' => '/api/parts/1', + 'storage_location' => '/api/storage_locations/1', + 'amount' => 100, + ]); + } + + public function testUpdateItem(): void + { + $this->_testPatchItem(1, [ + 'amount' => 220 + ]); + } + + public function testDeleteItem(): void + { + $this->_testDeleteItem(1); + } +} \ No newline at end of file diff --git a/tests/API/Endpoints/PricedetailsEndpointTest.php b/tests/API/Endpoints/PricedetailsEndpointTest.php new file mode 100644 index 00000000..8895365f --- /dev/null +++ b/tests/API/Endpoints/PricedetailsEndpointTest.php @@ -0,0 +1,72 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Tests\API\Endpoints; + +use App\Tests\API\Endpoints\CrudEndpointTestCase; + +class PricedetailsEndpointTest extends CrudEndpointTestCase +{ + + protected function getBasePath(): string + { + return '/api/pricedetails'; + } + + public function testGetCollection(): void + { + $this->_testGetCollection(); + self::assertJsonContains([ + 'hydra:totalItems' => 4, + ]); + } + + public function testGetItem(): void + { + $this->_testGetItem(1); + $this->_testGetItem(2); + $this->_testGetItem(3); + } + + public function testCreateItem(): void + { + $this->_testPostItem([ + 'price' => '2.0', + 'orderdetail' => '/api/orderdetails/1', + 'min_discount_quantity' => 1000, + ]); + } + + public function testUpdateItem(): void + { + $this->_testPatchItem(1, [ + 'price' => '3.5', + 'min_discount_quantity' => 10, + ]); + } + + public function testDeleteItem(): void + { + $this->_testDeleteItem(1); + } +} \ No newline at end of file diff --git a/tests/API/Endpoints/ProjectBOMEntriesEndpointTest.php b/tests/API/Endpoints/ProjectBOMEntriesEndpointTest.php new file mode 100644 index 00000000..cafb57dc --- /dev/null +++ b/tests/API/Endpoints/ProjectBOMEntriesEndpointTest.php @@ -0,0 +1,66 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Tests\API\Endpoints; + +class ProjectBOMEntriesEndpointTest extends CrudEndpointTestCase +{ + + protected function getBasePath(): string + { + return '/api/project_bom_entries'; + } + + public function testGetCollection(): void + { + $this->_testGetCollection(); + } + + public function testItemLifecycle(): void + { + $response = $this->_testPostItem([ + 'project' => '/api/projects/1', + 'part' => '/api/parts/1', + 'quantity' => 1, + ]); + + $new_id = $this->getIdOfCreatedElement($response); + + //Check if the new item is in the database + $this->_testGetItem($new_id); + + //Check if we can change the item + $this->_testPatchItem($new_id, [ + 'quantity' => 2, + ]); + + //Check if we can delete the item + $this->_testDeleteItem($new_id); + } + + public function testGetBomOfProject(): void + { + $response = self::createAuthenticatedClient()->request('GET', '/api/projects/1/bom'); + self::assertResponseIsSuccessful(); + } +} \ No newline at end of file diff --git a/tests/API/Endpoints/UsersEndpointTest.php b/tests/API/Endpoints/UsersEndpointTest.php new file mode 100644 index 00000000..0f075a7c --- /dev/null +++ b/tests/API/Endpoints/UsersEndpointTest.php @@ -0,0 +1,43 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Tests\API\Endpoints; + +class UsersEndpointTest extends CrudEndpointTestCase +{ + + protected function getBasePath(): string + { + return '/api/users'; + } + + public function testGetCollection(): void + { + $this->_testGetCollection(); + } + + public function testGetItem(): void + { + $this->_testGetItem(1); + } +} \ No newline at end of file