Skip to content

Commit

Permalink
Merge pull request spryker-shop#303 from spryker-shop/bugfix/cc-31028…
Browse files Browse the repository at this point in the history
…-add-missing-glue-tests

CC-31028 Integrated API E2E tests.
  • Loading branch information
DmitryLymarenko authored Nov 2, 2023
2 parents 895da85 + 3bc0135 commit 3f78640
Show file tree
Hide file tree
Showing 104 changed files with 13,796 additions and 10 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"ext-pgsql": "*",
"ext-readline": "*",
"ext-redis": "*",
"galbar/jsonpath": "^1.0.0",
"league/flysystem": "^2.5.0",
"spryker-eco/loggly": "^0.1.1",
"spryker-eco/new-relic": "^2.0.1",
Expand Down Expand Up @@ -155,6 +156,7 @@
"spryker/flysystem": "^2.2.0",
"spryker/flysystem-ftp-file-system": "^2.0.0",
"spryker/flysystem-local-file-system": "^2.0.0",
"spryker/glue-application-authorization-connector": "^1.1.0",
"spryker/glue-backend-api-application-authorization-connector": "^1.2.0",
"spryker/glue-backend-api-application-glue-json-api-convention-connector": "^1.0.0",
"spryker/glue-storefront-api-application-authorization-connector": "^1.0.2",
Expand Down
121 changes: 111 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Pyz/Glue/GlueApplication/GlueApplicationDependencyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
use Spryker\Glue\GlueApplication\Plugin\GlueApplication\FallbackStorefrontApiGlueApplicationBootstrapPlugin;
use Spryker\Glue\GlueApplication\Plugin\GlueApplication\HeadersValidateHttpRequestPlugin;
use Spryker\Glue\GlueApplication\Plugin\GlueApplication\PaginationParametersValidateHttpRequestPlugin;
use Spryker\Glue\GlueApplicationAuthorizationConnector\Plugin\GlueApplication\AuthorizationRestUserValidatorPlugin;
use Spryker\Glue\GlueApplicationAuthorizationConnector\Plugin\GlueApplication\AuthorizationRouterParameterExpanderPlugin;
use Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface;
use Spryker\Glue\GlueBackendApiApplication\Plugin\GlueApplication\BackendApiGlueApplicationBootstrapPlugin;
use Spryker\Glue\GlueBackendApiApplication\Plugin\GlueApplication\BackendRouterProviderPlugin;
Expand Down Expand Up @@ -313,6 +315,7 @@ protected function getRestUserValidatorPlugins(): array
return [
new CompanyUserRestUserValidatorPlugin(),
new AgentRestUserValidatorPlugin(),
new AuthorizationRestUserValidatorPlugin(),
];
}

Expand Down Expand Up @@ -771,6 +774,18 @@ protected function getApplicationPlugins(): array
];
}

/**
* @deprecated Will be removed without replacement.
*
* @return array<\Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\RouterParameterExpanderPluginInterface>
*/
protected function getRouterParameterExpanderPlugins(): array
{
return [
new AuthorizationRouterParameterExpanderPlugin(),
];
}

/**
* @return array<\Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\GlueApplicationBootstrapPluginInterface>
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

/**
* This file is part of the Spryker Commerce OS.
* For full license information, please view the LICENSE file that was distributed with this source code.
*/

namespace PyzTest\Glue\AgentAuth\RestApi;

use Codeception\Util\HttpCode;
use PyzTest\Glue\AgentAuth\AgentAuthRestApiTester;
use PyzTest\Glue\AgentAuth\RestApi\Fixtures\AgentAccessTokensRestApiFixtures;
use Spryker\Glue\AgentAuthRestApi\AgentAuthRestApiConfig;

/**
* Auto-generated group annotations
*
* @group PyzTest
* @group Glue
* @group AgentAuth
* @group RestApi
* @group AgentAccessTokensRestApiCest
* Add your own group annotations below this line
* @group EndToEnd
*/
class AgentAccessTokensRestApiCest
{
/**
* @var \PyzTest\Glue\AgentAuth\RestApi\Fixtures\AgentAccessTokensRestApiFixtures
*/
protected AgentAccessTokensRestApiFixtures $fixtures;

/**
* @param \PyzTest\Glue\AgentAuth\AgentAuthRestApiTester $I
*
* @return void
*/
public function loadFixtures(AgentAuthRestApiTester $I): void
{
/** @var \PyzTest\Glue\AgentAuth\RestApi\Fixtures\AgentAccessTokensRestApiFixtures $fixtures */
$fixtures = $I->loadFixtures(AgentAccessTokensRestApiFixtures::class);

$this->fixtures = $fixtures;
}

/**
* @depends loadFixtures
*
* @param \PyzTest\Glue\AgentAuth\AgentAuthRestApiTester $I
*
* @return void
*/
public function requestAccessTokenForExistingAgentUser(AgentAuthRestApiTester $I): void
{
// Act
$I->sendPOST(AgentAuthRestApiConfig::RESOURCE_AGENT_ACCESS_TOKENS, [
'data' => [
'type' => AgentAuthRestApiConfig::RESOURCE_AGENT_ACCESS_TOKENS,
'attributes' => [
'username' => $this->fixtures->getUserTransfer()->getUsername(),
'password' => AgentAccessTokensRestApiFixtures::TEST_PASSWORD,
],
],
]);

// Assert
$I->seeResponseCodeIs(HttpCode::CREATED);
$I->seeResponseHasAccessToken();
$I->seeResponseHasRefreshToken();
$I->seeResponseMatchesOpenApiSchema();
}

/**
* @depends loadFixtures
*
* @param \PyzTest\Glue\AgentAuth\AgentAuthRestApiTester $I
*
* @return void
*/
public function requestAccessTokenForNonExistingAgentUser(AgentAuthRestApiTester $I): void
{
// Act
$I->sendPOST(AgentAuthRestApiConfig::RESOURCE_AGENT_ACCESS_TOKENS, [
'data' => [
'type' => AgentAuthRestApiConfig::RESOURCE_AGENT_ACCESS_TOKENS,
'attributes' => [
'username' => 'NonExistingAgent',
'password' => AgentAccessTokensRestApiFixtures::TEST_PASSWORD,
],
],
]);

// Assert
$I->seeResponseCodeIs(HttpCode::UNAUTHORIZED);
$I->seeResponseDoesNotHaveAccessToken();
$I->seeResponseDoesNotHaveRefreshToken();
$I->seeResponseMatchesOpenApiSchema();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* This file is part of the Spryker Commerce OS.
* For full license information, please view the LICENSE file that was distributed with this source code.
*/

namespace PyzTest\Glue\AgentAuth\RestApi\Fixtures;

use Generated\Shared\Transfer\UserTransfer;
use PyzTest\Glue\AgentAuth\AgentAuthRestApiTester;
use SprykerTest\Shared\Testify\Fixtures\FixturesBuilderInterface;
use SprykerTest\Shared\Testify\Fixtures\FixturesContainerInterface;

class AgentAccessTokensRestApiFixtures implements FixturesBuilderInterface, FixturesContainerInterface
{
/**
* @var string
*/
public const TEST_PASSWORD = 'change123';

/**
* @var \Generated\Shared\Transfer\UserTransfer
*/
protected UserTransfer $userTransfer;

/**
* @param \PyzTest\Glue\AgentAuth\AgentAuthRestApiTester $I
*
* @return \SprykerTest\Shared\Testify\Fixtures\FixturesContainerInterface
*/
public function buildFixtures(AgentAuthRestApiTester $I): FixturesContainerInterface
{
$this->userTransfer = $this->createAgentUserTransfer($I);

return $this;
}

/**
* @return \Generated\Shared\Transfer\UserTransfer
*/
public function getUserTransfer(): UserTransfer
{
return $this->userTransfer;
}

/**
* @param \PyzTest\Glue\AgentAuth\AgentAuthRestApiTester $I
*
* @return \Generated\Shared\Transfer\UserTransfer
*/
protected function createAgentUserTransfer(AgentAuthRestApiTester $I): UserTransfer
{
return $I->haveRegisteredAgent([
UserTransfer::PASSWORD => static::TEST_PASSWORD,
]);
}
}
Loading

0 comments on commit 3f78640

Please sign in to comment.