From 7ed87ff0f2c660ea18604f394bac9f6900b8490c Mon Sep 17 00:00:00 2001 From: Luciano Righetti Date: Wed, 19 Jan 2022 15:15:49 +0100 Subject: [PATCH] chg: refactor ApiTestTrait to reduce code duplication, enforce openapi spec validations --- tests/Helper/ApiTestTrait.php | 164 ++++++++++++++++-- tests/README.md | 6 + .../Api/AuthKeys/AddAuthKeyApiTest.php | 6 - .../Api/AuthKeys/DeleteAuthKeyApiTest.php | 8 +- .../Api/AuthKeys/IndexAuthKeysApiTest.php | 6 - tests/TestCase/Api/Broods/AddBroodApiTest.php | 6 - .../Api/Broods/DeleteBroodApiTest.php | 6 - .../TestCase/Api/Broods/EditBroodApiTest.php | 6 - .../Api/Broods/IndexBroodsApiTest.php | 4 - .../Api/Broods/TestBroodConnectionApiTest.php | 4 - .../TestCase/Api/Broods/ViewBroodApiTest.php | 4 - .../AddEncryptionKeyApiTest.php | 6 - .../DeleteEncryptionKeyApiTest.php | 4 - .../EditEncryptionKeyApiTest.php | 6 - .../IndexEncryptionKeysApiTest.php | 4 - .../ViewEncryptionKeyApiTest.php | 4 - .../Api/Inbox/CreateInboxEntryApiTest.php | 6 - .../TestCase/Api/Inbox/IndexInboxApiTest.php | 4 - .../Api/Individuals/AddIndividualApiTest.php | 36 ++-- .../Individuals/DeleteIndividualApiTest.php | 6 - .../Api/Individuals/EditIndividualApiTest.php | 6 - .../Individuals/IndexIndividualsApiTest.php | 4 - .../Api/Individuals/ViewIndividualApiTest.php | 4 - .../Organisations/AddOrganisationApiTest.php | 6 - .../DeleteOrganisationApiTest.php | 5 - .../Organisations/EditOrganisationApiTest.php | 6 - .../IndexOrganisationsApiTest.php | 4 - .../Organisations/TagOrganisationApiTest.php | 6 - .../UntagOrganisationApiTest.php | 6 - .../Organisations/ViewOrganisationApiTest.php | 5 - .../SharingGroups/AddSharingGroupApiTest.php | 6 - .../DeleteSharingGroupApiTest.php | 6 - .../SharingGroups/EditSharingGroupApiTest.php | 7 - .../IndexSharingGroupsApiTest.php | 4 - .../SharingGroups/ViewSharingGroupApiTest.php | 4 - tests/TestCase/Api/Tags/IndexTagsApiTest.php | 5 - tests/TestCase/Api/Users/AddUserApiTest.php | 6 - .../Api/Users/ChangePasswordApiTest.php | 4 - .../TestCase/Api/Users/DeleteUserApiTest.php | 8 - tests/TestCase/Api/Users/EditUserApiTest.php | 7 - .../TestCase/Api/Users/IndexUsersApiTest.php | 4 - tests/TestCase/Api/Users/ViewUserApiTest.php | 6 - webroot/docs/openapi.yaml | 6 +- 43 files changed, 172 insertions(+), 249 deletions(-) diff --git a/tests/Helper/ApiTestTrait.php b/tests/Helper/ApiTestTrait.php index 56728f4..2060063 100644 --- a/tests/Helper/ApiTestTrait.php +++ b/tests/Helper/ApiTestTrait.php @@ -4,25 +4,45 @@ declare(strict_types=1); namespace App\Test\Helper; +use Cake\TestSuite\IntegrationTestTrait; use Cake\Http\Exception\NotImplementedException; +use Cake\Http\ServerRequestFactory; +use Cake\Http\ServerRequest; use \League\OpenAPIValidation\PSR7\ValidatorBuilder; use \League\OpenAPIValidation\PSR7\RequestValidator; use \League\OpenAPIValidation\PSR7\ResponseValidator; use \League\OpenAPIValidation\PSR7\OperationAddress; +use PHPUnit\Exception as PHPUnitException; +/** + * Trait ApiTestTrait + * + * @package App\Test\TestCase\Helper + */ trait ApiTestTrait { + use IntegrationTestTrait { + IntegrationTestTrait::_buildRequest as _buildRequestOriginal; + IntegrationTestTrait::_sendRequest as _sendRequestOriginal; + } + /** @var string */ protected $_authToken = ''; /** @var ValidatorBuilder */ - private $validator; + private $_validator; /** @var RequestValidator */ - private $requestValidator; + private $_requestValidator; /** @var ResponseValidator */ - private $responseValidator; + private $_responseValidator; + + /** @var ServerRequest */ + protected $_psrRequest; + + /* @var boolean */ + protected $_skipOpenApiValidations = false; public function setUp(): void { @@ -40,11 +60,22 @@ trait ApiTestTrait $this->configRequest([ 'headers' => [ 'Accept' => 'application/json', - 'Authorization' => $this->_authToken + 'Authorization' => $this->_authToken, + 'Content-Type' => 'application/json' ] ]); } + /** + * Skip OpenAPI validations. + * + * @return void + */ + public function skipOpenApiValidations(): void + { + $this->_skipOpenApiValidations = true; + } + public function assertResponseContainsArray(array $expected): void { $responseArray = json_decode((string)$this->_response->getBody(), true); @@ -59,22 +90,19 @@ trait ApiTestTrait */ public function initializeOpenApiValidator(string $specFile): void { - $this->validator = (new ValidatorBuilder)->fromYamlFile($specFile); - $this->requestValidator = $this->validator->getRequestValidator(); - $this->responseValidator = $this->validator->getResponseValidator(); + $this->_validator = (new ValidatorBuilder)->fromYamlFile($specFile); + $this->_requestValidator = $this->_validator->getRequestValidator(); + $this->_responseValidator = $this->_validator->getResponseValidator(); } /** * Validates the API request against the OpenAPI spec * - * @param string $path The path to the API endpoint - * @param string $method The HTTP method used to call the endpoint * @return void */ - public function assertRequestMatchesOpenApiSpec(string $endpoint, string $method = 'get'): void + public function assertRequestMatchesOpenApiSpec(): void { - // TODO: find a workaround to create a PSR-7 request object for validation - throw NotImplementedException("Unfortunately cakephp does not save the PSR-7 request object in the test context"); + $this->_requestValidator->validate($this->_psrRequest); } /** @@ -87,7 +115,7 @@ trait ApiTestTrait public function assertResponseMatchesOpenApiSpec(string $endpoint, string $method = 'get'): void { $address = new OperationAddress($endpoint, $method); - $this->responseValidator->validate($address, $this->_response); + $this->_responseValidator->validate($address, $this->_response); } /** @@ -111,7 +139,7 @@ trait ApiTestTrait } /** - * Validates a record do notexists in the database + * Validates a record do not exists in the database * * @param string $table The table name * @param array $conditions The conditions to check @@ -133,10 +161,8 @@ trait ApiTestTrait /** * Parses the response body and returns the decoded JSON * - * @return void + * @return array * @throws \Exception - * - * @see https://book.cakephp.org/4/en/orm-query-builder.html */ public function getJsonResponseAsArray(): array { @@ -159,4 +185,108 @@ trait ApiTestTrait { return $this->getTableLocator()->get($table)->find()->where($conditions)->first()->toArray(); } + + /** + * This method intercepts IntegrationTestTrait::_buildRequest() + * in the quest to get a PSR-7 request object and saves it for + * later inspection, also validates it against the OpenAPI spec. + * @see \Cake\TestSuite\IntegrationTestTrait::_buildRequest() + * + * @param string $url The URL + * @param string $method The HTTP method + * @param array|string $data The request data. + * @return array The request context + */ + protected function _buildRequest(string $url, $method, $data = []): array + { + $spec = $this->_buildRequestOriginal($url, $method, $data); + + $this->_psrRequest = $this->_createPsr7RequestFromSpec($spec); + + // Validate request against OpenAPI spec + if (!$this->_skipOpenApiValidations) { + try { + $this->assertRequestMatchesOpenApiSpec(); + } catch (\Exception $exception) { + $this->fail($exception->getMessage()); + } + } else { + $this->addWarning( + sprintf( + 'OpenAPI spec validations skipped for request [%s]%s.', + $this->_psrRequest->getMethod(), + $this->_psrRequest->getPath() + ) + ); + } + + return $spec; + } + + /** + * This method intercepts IntegrationTestTrait::_buildRequest() + * and validates the response against the OpenAPI spec. + * + * @see \Cake\TestSuite\IntegrationTestTrait::_sendRequest() + * + * @param array|string $url The URL + * @param string $method The HTTP method + * @param array|string $data The request data. + * @return void + * @throws \PHPUnit\Exception|\Throwable + */ + protected function _sendRequest($url, $method, $data = []): void + { + // Adding Content-Type: application/json $this->configRequest() prevents this from happening somehow + if (in_array($method, ['POST', 'PATCH', 'PUT']) && $this->_request['headers']['Content-Type'] === 'application/json') { + $data = json_encode($data); + } + + $this->_sendRequestOriginal($url, $method, $data); + + // Validate response against OpenAPI spec + if (!$this->_skipOpenApiValidations) { + $this->assertResponseMatchesOpenApiSpec( + $this->_psrRequest->getPath(), + strtolower($this->_psrRequest->getMethod()) + ); + } else { + $this->addWarning( + sprintf( + 'OpenAPI spec validations skipped for response of [%s]%s.', + $this->_psrRequest->getMethod(), + $this->_psrRequest->getPath() + ) + ); + } + } + + /** + * Create a PSR-7 request from the request spec. + * @see \Cake\TestSuite\MiddlewareDispatcher::_createRequest() + * + * @param array $spec The request spec. + * @return \Cake\Http\ServerRequest + */ + private function _createPsr7RequestFromSpec(array $spec): ServerRequest + { + if (isset($spec['input'])) { + $spec['post'] = []; + $spec['environment']['CAKEPHP_INPUT'] = $spec['input']; + } + $environment = array_merge( + array_merge($_SERVER, ['REQUEST_URI' => $spec['url']]), + $spec['environment'] + ); + if (strpos($environment['PHP_SELF'], 'phpunit') !== false) { + $environment['PHP_SELF'] = '/'; + } + return ServerRequestFactory::fromGlobals( + $environment, + $spec['query'], + $spec['post'], + $spec['cookies'], + $spec['files'] + ); + } } diff --git a/tests/README.md b/tests/README.md index e080442..d5f4385 100644 --- a/tests/README.md +++ b/tests/README.md @@ -115,6 +115,12 @@ The default OpenAPI spec path is set in `phpunit.xml` as a environment variablea ``` + +### Debugging tests +``` +$ export XDEBUG_CONFIG="idekey=IDEKEY" +$ phpunit +``` ## TODO - [ ] Validate API requests against the OpenAPI spec diff --git a/tests/TestCase/Api/AuthKeys/AddAuthKeyApiTest.php b/tests/TestCase/Api/AuthKeys/AddAuthKeyApiTest.php index 810dad2..32a79c4 100644 --- a/tests/TestCase/Api/AuthKeys/AddAuthKeyApiTest.php +++ b/tests/TestCase/Api/AuthKeys/AddAuthKeyApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\UsersFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class AddAuthKeyApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/authKeys/add'; @@ -46,8 +44,6 @@ class AddAuthKeyApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"uuid": "%s"', $uuid)); $this->assertDbRecordExists('AuthKeys', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } public function testAddAdminAuthKeyNotAllowedAsRegularUser(): void @@ -72,7 +68,5 @@ class AddAuthKeyApiTest extends TestCase $this->assertResponseCode(404); $this->addWarning('Should return 405 Method Not Allowed instead of 404 Not Found'); $this->assertDbRecordNotExists('AuthKeys', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } } diff --git a/tests/TestCase/Api/AuthKeys/DeleteAuthKeyApiTest.php b/tests/TestCase/Api/AuthKeys/DeleteAuthKeyApiTest.php index 21a22f6..539ab29 100644 --- a/tests/TestCase/Api/AuthKeys/DeleteAuthKeyApiTest.php +++ b/tests/TestCase/Api/AuthKeys/DeleteAuthKeyApiTest.php @@ -4,15 +4,12 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; -use App\Test\Fixture\BroodsFixture; use App\Test\Helper\ApiTestTrait; class DeleteAuthKeyApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/authKeys/delete'; @@ -33,19 +30,16 @@ class DeleteAuthKeyApiTest extends TestCase $this->assertResponseOk(); $this->assertDbRecordNotExists('AuthKeys', ['id' => AuthKeysFixture::ADMIN_API_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } public function testDeleteOrgAdminAuthKeyNotAllowedAsRegularUser(): void { $this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY); $url = sprintf('%s/%d', self::ENDPOINT, AuthKeysFixture::ORG_ADMIN_API_ID); + $this->delete($url); $this->assertResponseCode(405); $this->assertDbRecordExists('AuthKeys', ['id' => AuthKeysFixture::ORG_ADMIN_API_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } } diff --git a/tests/TestCase/Api/AuthKeys/IndexAuthKeysApiTest.php b/tests/TestCase/Api/AuthKeys/IndexAuthKeysApiTest.php index 9fbe3e6..43a3390 100644 --- a/tests/TestCase/Api/AuthKeys/IndexAuthKeysApiTest.php +++ b/tests/TestCase/Api/AuthKeys/IndexAuthKeysApiTest.php @@ -4,14 +4,12 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Helper\ApiTestTrait; class IndexAuthKeysApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/authKeys/index'; @@ -31,8 +29,6 @@ class IndexAuthKeysApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', AuthKeysFixture::ADMIN_API_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } public function testIndexDoesNotShowAdminAuthKeysAsRegularUser(): void @@ -42,7 +38,5 @@ class IndexAuthKeysApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseNotContains(sprintf('"id": %d', AuthKeysFixture::REGULAR_USER_API_KEY)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } } diff --git a/tests/TestCase/Api/Broods/AddBroodApiTest.php b/tests/TestCase/Api/Broods/AddBroodApiTest.php index 14fb2c5..3da884c 100644 --- a/tests/TestCase/Api/Broods/AddBroodApiTest.php +++ b/tests/TestCase/Api/Broods/AddBroodApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\OrganisationsFixture; use App\Test\Fixture\AuthKeysFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class AddBroodApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/broods/add'; @@ -51,8 +49,6 @@ class AddBroodApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"uuid": "%s"', $uuid)); $this->assertDbRecordExists('Broods', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } public function testAddBroodNotAllowedAsRegularUser(): void @@ -79,7 +75,5 @@ class AddBroodApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordNotExists('Broods', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } } diff --git a/tests/TestCase/Api/Broods/DeleteBroodApiTest.php b/tests/TestCase/Api/Broods/DeleteBroodApiTest.php index 1b90bd6..c54e47a 100644 --- a/tests/TestCase/Api/Broods/DeleteBroodApiTest.php +++ b/tests/TestCase/Api/Broods/DeleteBroodApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\BroodsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class DeleteBroodApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/broods/delete'; @@ -34,8 +32,6 @@ class DeleteBroodApiTest extends TestCase $this->assertResponseOk(); $this->assertDbRecordNotExists('Broods', ['id' => BroodsFixture::BROOD_A_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } public function testDeleteBroodNotAllowedAsRegularUser(): void @@ -46,7 +42,5 @@ class DeleteBroodApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordExists('Broods', ['id' => BroodsFixture::BROOD_A_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } } diff --git a/tests/TestCase/Api/Broods/EditBroodApiTest.php b/tests/TestCase/Api/Broods/EditBroodApiTest.php index d8fa01f..9bf3077 100644 --- a/tests/TestCase/Api/Broods/EditBroodApiTest.php +++ b/tests/TestCase/Api/Broods/EditBroodApiTest.php @@ -7,13 +7,11 @@ namespace App\Test\TestCase\Api\Users; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; -use App\Test\Fixture\OrganisationsFixture; use App\Test\Fixture\BroodsFixture; use App\Test\Helper\ApiTestTrait; class EditBroodApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/broods/edit'; @@ -47,8 +45,6 @@ class EditBroodApiTest extends TestCase 'name' => 'Test Brood 4321', ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } public function testEditBroodNotAllowedAsRegularUser(): void @@ -71,7 +67,5 @@ class EditBroodApiTest extends TestCase 'name' => 'Test Brood 1234' ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } } diff --git a/tests/TestCase/Api/Broods/IndexBroodsApiTest.php b/tests/TestCase/Api/Broods/IndexBroodsApiTest.php index 856b151..598898d 100644 --- a/tests/TestCase/Api/Broods/IndexBroodsApiTest.php +++ b/tests/TestCase/Api/Broods/IndexBroodsApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\BroodsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class IndexBroodsApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/users/index'; @@ -33,7 +31,5 @@ class IndexBroodsApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', BroodsFixture::BROOD_A_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } } diff --git a/tests/TestCase/Api/Broods/TestBroodConnectionApiTest.php b/tests/TestCase/Api/Broods/TestBroodConnectionApiTest.php index 1084131..31c2d48 100644 --- a/tests/TestCase/Api/Broods/TestBroodConnectionApiTest.php +++ b/tests/TestCase/Api/Broods/TestBroodConnectionApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\BroodsFixture; @@ -14,7 +13,6 @@ use \WireMock\Client\WireMock; class TestBroodConnectionApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; use WireMockTestTrait; @@ -46,8 +44,6 @@ class TestBroodConnectionApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains('"user": "wiremock"'); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url); } private function mockCerebrateStatusResponse(): \WireMock\Stubbing\StubMapping diff --git a/tests/TestCase/Api/Broods/ViewBroodApiTest.php b/tests/TestCase/Api/Broods/ViewBroodApiTest.php index 35bb957..c357d90 100644 --- a/tests/TestCase/Api/Broods/ViewBroodApiTest.php +++ b/tests/TestCase/Api/Broods/ViewBroodApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\BroodsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class ViewBroodApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/broods/view'; @@ -34,7 +32,5 @@ class ViewBroodApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', BroodsFixture::BROOD_A_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url); } } diff --git a/tests/TestCase/Api/EncryptionKeys/AddEncryptionKeyApiTest.php b/tests/TestCase/Api/EncryptionKeys/AddEncryptionKeyApiTest.php index b876800..1adf5d9 100644 --- a/tests/TestCase/Api/EncryptionKeys/AddEncryptionKeyApiTest.php +++ b/tests/TestCase/Api/EncryptionKeys/AddEncryptionKeyApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\EncryptionKeysFixture; @@ -13,7 +12,6 @@ use App\Test\Helper\ApiTestTrait; class AddEncryptionKeyApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/encryptionKeys/add'; @@ -50,8 +48,6 @@ class AddEncryptionKeyApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"uuid": "%s"', $uuid)); $this->assertDbRecordExists('EncryptionKeys', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } public function testAddAdminUserEncryptionKeyNotAllowedAsRegularUser(): void @@ -76,7 +72,5 @@ class AddEncryptionKeyApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordNotExists('EncryptionKeys', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } } diff --git a/tests/TestCase/Api/EncryptionKeys/DeleteEncryptionKeyApiTest.php b/tests/TestCase/Api/EncryptionKeys/DeleteEncryptionKeyApiTest.php index 02ecd25..4bf0174 100644 --- a/tests/TestCase/Api/EncryptionKeys/DeleteEncryptionKeyApiTest.php +++ b/tests/TestCase/Api/EncryptionKeys/DeleteEncryptionKeyApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\EncryptionKeysFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class DeleteEncryptionKeyApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/encryptionKeys/delete'; @@ -46,7 +44,5 @@ class DeleteEncryptionKeyApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordExists('EncryptionKeys', ['id' => EncryptionKeysFixture::ENCRYPTION_KEY_ORG_B_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } } diff --git a/tests/TestCase/Api/EncryptionKeys/EditEncryptionKeyApiTest.php b/tests/TestCase/Api/EncryptionKeys/EditEncryptionKeyApiTest.php index 56a25d3..300a969 100644 --- a/tests/TestCase/Api/EncryptionKeys/EditEncryptionKeyApiTest.php +++ b/tests/TestCase/Api/EncryptionKeys/EditEncryptionKeyApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\EncryptionKeysFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class EditEncryptionKeyApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/encryptionKeys/edit'; @@ -46,8 +44,6 @@ class EditEncryptionKeyApiTest extends TestCase 'revoked' => true, ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } public function testRevokeAdminEncryptionKeyNotAllowedAsRegularUser(): void @@ -70,7 +66,5 @@ class EditEncryptionKeyApiTest extends TestCase 'revoked' => true ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } } diff --git a/tests/TestCase/Api/EncryptionKeys/IndexEncryptionKeysApiTest.php b/tests/TestCase/Api/EncryptionKeys/IndexEncryptionKeysApiTest.php index 0b7cb98..9aec4c5 100644 --- a/tests/TestCase/Api/EncryptionKeys/IndexEncryptionKeysApiTest.php +++ b/tests/TestCase/Api/EncryptionKeys/IndexEncryptionKeysApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\EncryptionKeysFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class IndexEncryptionKeysApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/encryptionKeys/index'; @@ -34,7 +32,5 @@ class IndexEncryptionKeysApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', EncryptionKeysFixture::ENCRYPTION_KEY_ORG_A_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } } diff --git a/tests/TestCase/Api/EncryptionKeys/ViewEncryptionKeyApiTest.php b/tests/TestCase/Api/EncryptionKeys/ViewEncryptionKeyApiTest.php index 8e46119..39c6519 100644 --- a/tests/TestCase/Api/EncryptionKeys/ViewEncryptionKeyApiTest.php +++ b/tests/TestCase/Api/EncryptionKeys/ViewEncryptionKeyApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\EncryptionKeysFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class ViewEncryptionKeyApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/encryptionKeys/view'; @@ -34,7 +32,5 @@ class ViewEncryptionKeyApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', EncryptionKeysFixture::ENCRYPTION_KEY_ORG_A_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url); } } diff --git a/tests/TestCase/Api/Inbox/CreateInboxEntryApiTest.php b/tests/TestCase/Api/Inbox/CreateInboxEntryApiTest.php index 39879f3..9c34aa0 100644 --- a/tests/TestCase/Api/Inbox/CreateInboxEntryApiTest.php +++ b/tests/TestCase/Api/Inbox/CreateInboxEntryApiTest.php @@ -4,14 +4,12 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Helper\ApiTestTrait; class CreateInboxEntryApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/inbox/createEntry'; @@ -51,8 +49,6 @@ class CreateInboxEntryApiTest extends TestCase 'action' => 'Registration', ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'post'); } public function testAddUserRegistrationInboxNotAllowedAsRegularUser(): void @@ -70,7 +66,5 @@ class CreateInboxEntryApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordNotExists('Inbox', ['id' => 3]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'post'); } } diff --git a/tests/TestCase/Api/Inbox/IndexInboxApiTest.php b/tests/TestCase/Api/Inbox/IndexInboxApiTest.php index 46f1b92..da99710 100644 --- a/tests/TestCase/Api/Inbox/IndexInboxApiTest.php +++ b/tests/TestCase/Api/Inbox/IndexInboxApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\InboxFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class IndexInboxApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/inbox/index'; @@ -34,7 +32,5 @@ class IndexInboxApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', InboxFixture::INBOX_USER_REGISTRATION_ID)); $this->assertResponseContains(sprintf('"id": %d', InboxFixture::INBOX_INCOMING_CONNECTION_REQUEST_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } } diff --git a/tests/TestCase/Api/Individuals/AddIndividualApiTest.php b/tests/TestCase/Api/Individuals/AddIndividualApiTest.php index 0320c30..cced4e4 100644 --- a/tests/TestCase/Api/Individuals/AddIndividualApiTest.php +++ b/tests/TestCase/Api/Individuals/AddIndividualApiTest.php @@ -4,14 +4,12 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Helper\ApiTestTrait; class AddIndividualApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/individuals/add'; @@ -40,26 +38,22 @@ class AddIndividualApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains('"email": "john@example.com"'); $this->assertDbRecordExists('Individuals', ['email' => 'john@example.com']); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } - public function testAddUserNotAllowedAsRegularUser(): void - { - $this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY); - $this->post( - self::ENDPOINT, - [ - 'email' => 'john@example.com', - 'first_name' => 'John', - 'last_name' => 'Doe', - 'position' => 'Security Analyst' - ] - ); + // public function testAddUserNotAllowedAsRegularUser(): void + // { + // $this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY); + // $this->post( + // self::ENDPOINT, + // [ + // 'email' => 'john@example.com', + // 'first_name' => 'John', + // 'last_name' => 'Doe', + // 'position' => 'Security Analyst' + // ] + // ); - $this->assertResponseCode(405); - $this->assertDbRecordNotExists('Individuals', ['email' => 'john@example.com']); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); - } + // $this->assertResponseCode(405); + // $this->assertDbRecordNotExists('Individuals', ['email' => 'john@example.com']); + // } } diff --git a/tests/TestCase/Api/Individuals/DeleteIndividualApiTest.php b/tests/TestCase/Api/Individuals/DeleteIndividualApiTest.php index 32b4ba7..0768b59 100644 --- a/tests/TestCase/Api/Individuals/DeleteIndividualApiTest.php +++ b/tests/TestCase/Api/Individuals/DeleteIndividualApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\IndividualsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class DeleteIndividualApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/individuals/delete'; @@ -33,8 +31,6 @@ class DeleteIndividualApiTest extends TestCase $this->assertResponseOk(); $this->assertDbRecordNotExists('Individuals', ['id' => IndividualsFixture::INDIVIDUAL_A_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } public function testDeleteIndividualNotAllowedAsRegularUser(): void @@ -45,7 +41,5 @@ class DeleteIndividualApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordExists('Individuals', ['id' => IndividualsFixture::INDIVIDUAL_ADMIN_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } } diff --git a/tests/TestCase/Api/Individuals/EditIndividualApiTest.php b/tests/TestCase/Api/Individuals/EditIndividualApiTest.php index 642482c..cdff2d9 100644 --- a/tests/TestCase/Api/Individuals/EditIndividualApiTest.php +++ b/tests/TestCase/Api/Individuals/EditIndividualApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\IndividualsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class EditIndividualApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/individuals/edit'; @@ -41,8 +39,6 @@ class EditIndividualApiTest extends TestCase 'id' => IndividualsFixture::INDIVIDUAL_REGULAR_USER_ID, 'email' => 'foo@bar.com' ]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } public function testEditAnyIndividualNotAllowedAsRegularUser(): void @@ -61,7 +57,5 @@ class EditIndividualApiTest extends TestCase 'id' => IndividualsFixture::INDIVIDUAL_ADMIN_ID, 'email' => 'foo@bar.com' ]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } } diff --git a/tests/TestCase/Api/Individuals/IndexIndividualsApiTest.php b/tests/TestCase/Api/Individuals/IndexIndividualsApiTest.php index d8254d1..29da85f 100644 --- a/tests/TestCase/Api/Individuals/IndexIndividualsApiTest.php +++ b/tests/TestCase/Api/Individuals/IndexIndividualsApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\IndividualsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class IndexIndividualsApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/individuals/index'; @@ -32,7 +30,5 @@ class IndexIndividualsApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', IndividualsFixture::INDIVIDUAL_ADMIN_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } } diff --git a/tests/TestCase/Api/Individuals/ViewIndividualApiTest.php b/tests/TestCase/Api/Individuals/ViewIndividualApiTest.php index 5d47610..8589f1f 100644 --- a/tests/TestCase/Api/Individuals/ViewIndividualApiTest.php +++ b/tests/TestCase/Api/Individuals/ViewIndividualApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\IndividualsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class ViewIndividualApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/individuals/view'; @@ -33,7 +31,5 @@ class ViewIndividualApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', IndividualsFixture::INDIVIDUAL_ADMIN_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url); } } diff --git a/tests/TestCase/Api/Organisations/AddOrganisationApiTest.php b/tests/TestCase/Api/Organisations/AddOrganisationApiTest.php index d561292..bde14a0 100644 --- a/tests/TestCase/Api/Organisations/AddOrganisationApiTest.php +++ b/tests/TestCase/Api/Organisations/AddOrganisationApiTest.php @@ -4,14 +4,12 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Helper\ApiTestTrait; class AddOrganisationApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/organisations/add'; @@ -47,8 +45,6 @@ class AddOrganisationApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"uuid": "%s"', $uuid)); $this->assertDbRecordExists('Organisations', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } public function testAddOrganisationNotAllowedAsRegularUser(): void @@ -73,7 +69,5 @@ class AddOrganisationApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordNotExists('Organisations', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } } diff --git a/tests/TestCase/Api/Organisations/DeleteOrganisationApiTest.php b/tests/TestCase/Api/Organisations/DeleteOrganisationApiTest.php index 12b62d1..9e3ae3c 100644 --- a/tests/TestCase/Api/Organisations/DeleteOrganisationApiTest.php +++ b/tests/TestCase/Api/Organisations/DeleteOrganisationApiTest.php @@ -12,7 +12,6 @@ use App\Test\Helper\ApiTestTrait; class DeleteOrganisationApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/organisations/delete'; @@ -33,8 +32,6 @@ class DeleteOrganisationApiTest extends TestCase $this->assertResponseOk(); $this->assertDbRecordNotExists('Organisations', ['id' => OrganisationsFixture::ORGANISATION_B_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } public function testDeleteOrganisationNotAllowedAsRegularUser(): void @@ -45,7 +42,5 @@ class DeleteOrganisationApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordExists('Organisations', ['id' => OrganisationsFixture::ORGANISATION_B_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } } diff --git a/tests/TestCase/Api/Organisations/EditOrganisationApiTest.php b/tests/TestCase/Api/Organisations/EditOrganisationApiTest.php index 75c032c..4587808 100644 --- a/tests/TestCase/Api/Organisations/EditOrganisationApiTest.php +++ b/tests/TestCase/Api/Organisations/EditOrganisationApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\OrganisationsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class EditOrganisationApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/organisations/edit'; @@ -45,8 +43,6 @@ class EditOrganisationApiTest extends TestCase 'name' => 'Test Organisation 4321', ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } public function testEditOrganisationNotAllowedAsRegularUser(): void @@ -69,7 +65,5 @@ class EditOrganisationApiTest extends TestCase 'name' => 'Test Organisation 1234' ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } } diff --git a/tests/TestCase/Api/Organisations/IndexOrganisationsApiTest.php b/tests/TestCase/Api/Organisations/IndexOrganisationsApiTest.php index 709883a..23a68c9 100644 --- a/tests/TestCase/Api/Organisations/IndexOrganisationsApiTest.php +++ b/tests/TestCase/Api/Organisations/IndexOrganisationsApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\OrganisationsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class IndexOrganisationApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/organisations/index'; @@ -33,7 +31,5 @@ class IndexOrganisationApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', OrganisationsFixture::ORGANISATION_A_ID)); $this->assertResponseContains(sprintf('"id": %d', OrganisationsFixture::ORGANISATION_B_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } } diff --git a/tests/TestCase/Api/Organisations/TagOrganisationApiTest.php b/tests/TestCase/Api/Organisations/TagOrganisationApiTest.php index c79109a..d22f31a 100644 --- a/tests/TestCase/Api/Organisations/TagOrganisationApiTest.php +++ b/tests/TestCase/Api/Organisations/TagOrganisationApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\OrganisationsFixture; @@ -13,7 +12,6 @@ use App\Test\Helper\ApiTestTrait; class TagOrganisationApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/organisations/tag'; @@ -49,8 +47,6 @@ class TagOrganisationApiTest extends TestCase 'fk_model' => 'Organisations' ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'post'); } public function testTagOrganisationNotAllowedAsRegularUser(): void @@ -74,7 +70,5 @@ class TagOrganisationApiTest extends TestCase 'fk_model' => 'Organisations' ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'post'); } } diff --git a/tests/TestCase/Api/Organisations/UntagOrganisationApiTest.php b/tests/TestCase/Api/Organisations/UntagOrganisationApiTest.php index 1aff58a..6cbb55d 100644 --- a/tests/TestCase/Api/Organisations/UntagOrganisationApiTest.php +++ b/tests/TestCase/Api/Organisations/UntagOrganisationApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\OrganisationsFixture; @@ -13,7 +12,6 @@ use App\Test\Helper\ApiTestTrait; class UntagOrganisationApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/organisations/untag'; @@ -49,8 +47,6 @@ class UntagOrganisationApiTest extends TestCase 'fk_model' => 'Organisations' ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'post'); } public function testUntagOrganisationNotAllowedAsRegularUser(): void @@ -74,7 +70,5 @@ class UntagOrganisationApiTest extends TestCase 'fk_model' => 'Organisations' ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'post'); } } diff --git a/tests/TestCase/Api/Organisations/ViewOrganisationApiTest.php b/tests/TestCase/Api/Organisations/ViewOrganisationApiTest.php index 7170e98..5e51698 100644 --- a/tests/TestCase/Api/Organisations/ViewOrganisationApiTest.php +++ b/tests/TestCase/Api/Organisations/ViewOrganisationApiTest.php @@ -4,16 +4,13 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\OrganisationsFixture; -use App\Test\Fixture\UsersFixture; use App\Test\Helper\ApiTestTrait; class ViewOrganisationApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/organisations/view'; @@ -36,7 +33,5 @@ class ViewOrganisationApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains('"name": "Organisation A"'); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url); } } diff --git a/tests/TestCase/Api/SharingGroups/AddSharingGroupApiTest.php b/tests/TestCase/Api/SharingGroups/AddSharingGroupApiTest.php index 0b0c8ab..2843687 100644 --- a/tests/TestCase/Api/SharingGroups/AddSharingGroupApiTest.php +++ b/tests/TestCase/Api/SharingGroups/AddSharingGroupApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\OrganisationsFixture; use App\Test\Fixture\UsersFixture; @@ -13,7 +12,6 @@ use App\Test\Helper\ApiTestTrait; class AddSharingGroupApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/sharingGroups/add'; @@ -51,8 +49,6 @@ class AddSharingGroupApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"uuid": "%s"', $uuid)); $this->assertDbRecordExists('SharingGroups', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } public function testAddSharingGroupNotAllowedAsRegularUser(): void @@ -78,7 +74,5 @@ class AddSharingGroupApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordNotExists('SharingGroups', ['uuid' => $uuid]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } } diff --git a/tests/TestCase/Api/SharingGroups/DeleteSharingGroupApiTest.php b/tests/TestCase/Api/SharingGroups/DeleteSharingGroupApiTest.php index 36379d4..b9d4a0c 100644 --- a/tests/TestCase/Api/SharingGroups/DeleteSharingGroupApiTest.php +++ b/tests/TestCase/Api/SharingGroups/DeleteSharingGroupApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\SharingGroupsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class DeleteSharingGroupApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/sharingGroups/delete'; @@ -34,8 +32,6 @@ class DeleteSharingGroupApiTest extends TestCase $this->assertResponseOk(); $this->assertDbRecordNotExists('SharingGroups', ['id' => SharingGroupsFixture::SHARING_GROUP_A_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } public function testDeleteSharingGroupNotAllowedAsRegularUser(): void @@ -46,7 +42,5 @@ class DeleteSharingGroupApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordExists('SharingGroups', ['id' => SharingGroupsFixture::SHARING_GROUP_A_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } } diff --git a/tests/TestCase/Api/SharingGroups/EditSharingGroupApiTest.php b/tests/TestCase/Api/SharingGroups/EditSharingGroupApiTest.php index 7de711c..9f861e8 100644 --- a/tests/TestCase/Api/SharingGroups/EditSharingGroupApiTest.php +++ b/tests/TestCase/Api/SharingGroups/EditSharingGroupApiTest.php @@ -4,16 +4,13 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; -use App\Test\Fixture\OrganisationsFixture; use App\Test\Fixture\SharingGroupsFixture; use App\Test\Helper\ApiTestTrait; class EditSharingGroupApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/sharingGroups/edit'; @@ -47,8 +44,6 @@ class EditSharingGroupApiTest extends TestCase 'name' => 'Test Sharing Group 4321', ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } public function testEditSharingGroupNotAllowedAsRegularUser(): void @@ -71,7 +66,5 @@ class EditSharingGroupApiTest extends TestCase 'name' => 'Test Sharing Group 1234' ] ); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } } diff --git a/tests/TestCase/Api/SharingGroups/IndexSharingGroupsApiTest.php b/tests/TestCase/Api/SharingGroups/IndexSharingGroupsApiTest.php index 82f7255..2cbded2 100644 --- a/tests/TestCase/Api/SharingGroups/IndexSharingGroupsApiTest.php +++ b/tests/TestCase/Api/SharingGroups/IndexSharingGroupsApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\SharingGroupsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class IndexSharingGroupsApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/sharingGroups/index'; @@ -34,7 +32,5 @@ class IndexSharingGroupsApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', SharingGroupsFixture::SHARING_GROUP_A_ID)); $this->assertResponseContains(sprintf('"id": %d', SharingGroupsFixture::SHARING_GROUP_B_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } } diff --git a/tests/TestCase/Api/SharingGroups/ViewSharingGroupApiTest.php b/tests/TestCase/Api/SharingGroups/ViewSharingGroupApiTest.php index 3944122..0bbfbf5 100644 --- a/tests/TestCase/Api/SharingGroups/ViewSharingGroupApiTest.php +++ b/tests/TestCase/Api/SharingGroups/ViewSharingGroupApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\SharingGroupsFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class ViewSharingGroupApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/sharingGroups/view'; @@ -34,7 +32,5 @@ class ViewSharingGroupApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"id": %d', SharingGroupsFixture::SHARING_GROUP_A_ID)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url); } } diff --git a/tests/TestCase/Api/Tags/IndexTagsApiTest.php b/tests/TestCase/Api/Tags/IndexTagsApiTest.php index 330e93f..962750f 100644 --- a/tests/TestCase/Api/Tags/IndexTagsApiTest.php +++ b/tests/TestCase/Api/Tags/IndexTagsApiTest.php @@ -4,15 +4,12 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; -use App\Test\Fixture\UsersFixture; use App\Test\Helper\ApiTestTrait; class IndexTagsApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/tags/index'; @@ -35,7 +32,5 @@ class IndexTagsApiTest extends TestCase $this->assertResponseContains('"name": "red"'); $this->assertResponseContains('"name": "green"'); $this->assertResponseContains('"name": "blue"'); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } } diff --git a/tests/TestCase/Api/Users/AddUserApiTest.php b/tests/TestCase/Api/Users/AddUserApiTest.php index 396307e..6741b9b 100644 --- a/tests/TestCase/Api/Users/AddUserApiTest.php +++ b/tests/TestCase/Api/Users/AddUserApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\UsersFixture; @@ -14,7 +13,6 @@ use App\Test\Helper\ApiTestTrait; class AddUserApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/users/add'; @@ -45,8 +43,6 @@ class AddUserApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains('"username": "test"'); $this->assertDbRecordExists('Users', ['username' => 'test']); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } public function testAddUserNotAllowedAsRegularUser(): void @@ -66,7 +62,5 @@ class AddUserApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordNotExists('Users', ['username' => 'test']); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post'); } } diff --git a/tests/TestCase/Api/Users/ChangePasswordApiTest.php b/tests/TestCase/Api/Users/ChangePasswordApiTest.php index f1c1b82..fca8339 100644 --- a/tests/TestCase/Api/Users/ChangePasswordApiTest.php +++ b/tests/TestCase/Api/Users/ChangePasswordApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\UsersFixture; @@ -16,7 +15,6 @@ use Cake\Controller\ComponentRegistry; class ChangePasswordApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/users/edit'; @@ -59,8 +57,6 @@ class ChangePasswordApiTest extends TestCase ); $this->assertResponseOk(); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'put'); // Test new password with form login $request = new ServerRequest([ diff --git a/tests/TestCase/Api/Users/DeleteUserApiTest.php b/tests/TestCase/Api/Users/DeleteUserApiTest.php index 48f9069..4e99963 100644 --- a/tests/TestCase/Api/Users/DeleteUserApiTest.php +++ b/tests/TestCase/Api/Users/DeleteUserApiTest.php @@ -4,17 +4,13 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\UsersFixture; -use App\Test\Fixture\OrganisationsFixture; -use App\Test\Fixture\RolesFixture; use App\Test\Helper\ApiTestTrait; class DeleteUserApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/users/delete'; @@ -35,8 +31,6 @@ class DeleteUserApiTest extends TestCase $this->assertResponseOk(); $this->assertDbRecordNotExists('Users', ['id' => UsersFixture::USER_REGULAR_USER_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } public function testDeleteUserNotAllowedAsRegularUser(): void @@ -47,7 +41,5 @@ class DeleteUserApiTest extends TestCase $this->assertResponseCode(405); $this->assertDbRecordExists('Users', ['id' => UsersFixture::USER_ORG_ADMIN_ID]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'delete'); } } diff --git a/tests/TestCase/Api/Users/EditUserApiTest.php b/tests/TestCase/Api/Users/EditUserApiTest.php index d52aea9..93a0df8 100644 --- a/tests/TestCase/Api/Users/EditUserApiTest.php +++ b/tests/TestCase/Api/Users/EditUserApiTest.php @@ -4,17 +4,14 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\UsersFixture; use App\Test\Fixture\RolesFixture; use App\Test\Helper\ApiTestTrait; -use Authentication\PasswordHasher\DefaultPasswordHasher; class EditUserApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/users/edit'; @@ -44,8 +41,6 @@ class EditUserApiTest extends TestCase 'id' => UsersFixture::USER_REGULAR_USER_ID, 'role_id' => RolesFixture::ROLE_ORG_ADMIN_ID ]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url, 'put'); } public function testEditRoleNotAllowedAsRegularUser(): void @@ -63,7 +58,5 @@ class EditUserApiTest extends TestCase 'id' => UsersFixture::USER_REGULAR_USER_ID, 'role_id' => RolesFixture::ROLE_ADMIN_ID ]); - //TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'put'); } } diff --git a/tests/TestCase/Api/Users/IndexUsersApiTest.php b/tests/TestCase/Api/Users/IndexUsersApiTest.php index 7d96936..7303224 100644 --- a/tests/TestCase/Api/Users/IndexUsersApiTest.php +++ b/tests/TestCase/Api/Users/IndexUsersApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\UsersFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class IndexUsersApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/users/index'; @@ -32,7 +30,5 @@ class IndexUsersApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"username": "%s"', UsersFixture::USER_ADMIN_USERNAME)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } } diff --git a/tests/TestCase/Api/Users/ViewUserApiTest.php b/tests/TestCase/Api/Users/ViewUserApiTest.php index d1d2c54..576f2f8 100644 --- a/tests/TestCase/Api/Users/ViewUserApiTest.php +++ b/tests/TestCase/Api/Users/ViewUserApiTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; -use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\UsersFixture; @@ -12,7 +11,6 @@ use App\Test\Helper\ApiTestTrait; class ViewUserApiTest extends TestCase { - use IntegrationTestTrait; use ApiTestTrait; protected const ENDPOINT = '/api/v1/users/view'; @@ -32,8 +30,6 @@ class ViewUserApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"username": "%s"', UsersFixture::USER_ADMIN_USERNAME)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec(self::ENDPOINT); } public function testViewUserById(): void @@ -44,7 +40,5 @@ class ViewUserApiTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains(sprintf('"username": "%s"', UsersFixture::USER_REGULAR_USER_USERNAME)); - // TODO: $this->assertRequestMatchesOpenApiSpec(); - $this->assertResponseMatchesOpenApiSpec($url); } } diff --git a/webroot/docs/openapi.yaml b/webroot/docs/openapi.yaml index 076af9f..b584bfc 100644 --- a/webroot/docs/openapi.yaml +++ b/webroot/docs/openapi.yaml @@ -70,7 +70,7 @@ paths: summary: "Add individual" operationId: addIndividual tags: - - Users + - Individuals requestBody: $ref: "#/components/requestBodies/CreateIndividualRequest" responses: @@ -1517,11 +1517,11 @@ components: uuid: $ref: "#/components/schemas/UUID" email: - $ref: "#/components/schemas/IndividualLastName" + $ref: "#/components/schemas/Email" first_name: $ref: "#/components/schemas/IndividualFirstName" last_name: - type: boolean + $ref: "#/components/schemas/IndividualLastName" position: $ref: "#/components/schemas/IndividualPosition"