Skip to content

Commit

Permalink
Implement another endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed Apr 29, 2021
1 parent f7b6f2d commit 8392bcd
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/Sylius/Behat/Context/Api/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Behat\Context\Api\Shop;

use ApiPlatform\Core\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\Request;
Expand All @@ -23,7 +24,6 @@
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Product\Model\ProductOptionInterface;
use Sylius\Component\Product\Resolver\ProductVariantResolverInterface;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -195,17 +195,17 @@ public function iAddThisProductWithToTheCart(
*/
public function iChangeQuantityToInMyCart(ProductInterface $product, int $quantity, string $tokenValue): void
{
$itemId = $this->geOrderItemIdForProductInCart($product, $tokenValue);
$this->changeQuantityOfOrderItem($itemId, $quantity, $tokenValue);
$itemResponse = $this->getOrderItemResponseFromProductInCart($product, $tokenValue);
$this->changeQuantityOfOrderItem((string) $itemResponse['id'], $quantity, $tokenValue);
}

/**
* @When /^I remove (product "[^"]+") from the (cart)$/
*/
public function iRemoveProductFromTheCart(ProductInterface $product, string $tokenValue): void
{
$itemId = $this->geOrderItemIdForProductInCart($product, $tokenValue);
$this->removeOrderItemFromCart($itemId, $tokenValue);
$itemResponse = $this->getOrderItemResponseFromProductInCart($product, $tokenValue);
$this->removeOrderItemFromCart((string) $itemResponse['id'], $tokenValue);
}

/**
Expand Down Expand Up @@ -535,7 +535,7 @@ public function thisItemShouldHaveOptionValue(ProductInterface $product, string
private function pickupCart(?string $localeCode = null): string
{
$this->cartsClient->buildCreateRequest();
$this->cartsClient->addRequestData('localeCode', $localeCode);
$this->cartsClient->addRequestData('locale', $localeCode);
$tokenValue = $this->responseChecker->getValue($this->cartsClient->create(), 'tokenValue');

$this->sharedStorage->set('cart_token', $tokenValue);
Expand Down Expand Up @@ -614,14 +614,14 @@ private function getProductVariantForItem(array $item): Response
return $this->cartsClient->getLastResponse();
}

private function geOrderItemIdForProductInCart(ProductInterface $product, string $tokenValue): ?string
private function getOrderItemResponseFromProductInCart(ProductInterface $product, string $tokenValue): ?array
{
$items = $this->responseChecker->getValue($this->cartsClient->show($tokenValue), 'items');

foreach ($items as $item) {
$response = $this->getProductForItem($item);
if ($this->responseChecker->hasValue($response, 'code', $product->getCode())) {
return (string) $item['id'];
return $item;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public function iProceededWithShippingMethod(ShippingMethodInterface $shippingMe
sprintf('shipments/%s', $this->getCart()['shipments'][0]['id'])
);

$request->setContent(['shippingMethodCode' => $shippingMethod->getCode()]);
$request->setContent(['shippingMethod' => $this->iriConverter->getIriFromItem($shippingMethod)]);

$this->ordersClient->executeCustomRequest($request);
}
Expand Down
19 changes: 13 additions & 6 deletions src/Sylius/Behat/Context/Api/Shop/LoginContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

namespace Sylius\Behat\Context\Api\Shop;

use ApiPlatform\Core\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ApiSecurityClientInterface;
use Sylius\Behat\Client\Request;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Symfony\Component\HttpFoundation\Request as HTTPRequest;
use Webmozart\Assert\Assert;

Expand All @@ -29,15 +31,20 @@ final class LoginContext implements Context
/** @var ApiClientInterface */
private $apiClient;

/** @var IriConverterInterface */
private $iriConverter;

/** @var Request|null */
private $request;

public function __construct(
ApiSecurityClientInterface $apiSecurityClient,
ApiClientInterface $apiClient
ApiClientInterface $apiClient,
IriConverterInterface $iriConverter
) {
$this->apiSecurityClient = $apiSecurityClient;
$this->apiClient = $apiClient;
$this->iriConverter = $iriConverter;
}

/**
Expand Down Expand Up @@ -65,13 +72,13 @@ public function iWantToResetPassword(): void
}

/**
* @When I reset password for email :email in :localeCode locale
* @When I reset password for email :email in :locale locale
*/
public function iResetPasswordForEmailInLocale(string $email, string $localeCode): void
public function iResetPasswordForEmailInLocale(string $email, LocaleInterface $locale): void
{
$this->iWantToResetPassword();
$this->iSpecifyTheEmail($email);
$this->addLocaleCode($localeCode);
$this->addLocale($this->iriConverter->getIriFromItem($locale));
$this->iResetIt();
}

Expand Down Expand Up @@ -221,8 +228,8 @@ public function iShouldNotBeAbleToLogInAsWithPassword(string $email, string $pas
$this->iShouldNotBeLoggedIn();
}

private function addLocaleCode(string $localeCode): void
private function addLocale(string $locale): void
{
$this->request->updateContent(['localeCode' => $localeCode]);
$this->request->updateContent(['locale' => $locale]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<service id="sylius.behat.context.api.shop.login" class="Sylius\Behat\Context\Api\Shop\LoginContext">
<argument type="service" id="sylius.behat.client.shop_api_platform_security_client" />
<argument type="service" id="sylius.behat.api_platform_client.shop.account" />
<argument type="service" id="api_platform.iri_converter" />
</service>

<service id="sylius.behat.context.api.shop.product" class="Sylius\Behat\Context\Api\Shop\ProductContext">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ public function __construct(RouterInterface $router, IdentifierConverterInterfac
$this->identifierConverter = $identifierConverter;
}

public function getIdentifier(string $iri): string
public function getIdentifier(?string $iri): ?string
{
if ($iri === null || $iri === '') {
return null;
}

try {
$parameters = $this->router->match($iri);
} catch (RoutingExceptionInterface $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

interface ItemIriToIdentifierConverterInterface
{
public function getIdentifier(string $iri): string;
public function getIdentifier(?string $iri): ?string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<collectionOperations>
<collectionOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="path">admin/locales</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:locale:read</attribute>
</attribute>
Expand All @@ -31,19 +32,37 @@

<collectionOperation name="admin_post">
<attribute name="method">POST</attribute>
<attribute name="path">admin/locales</attribute>
<attribute name="denormalization_context">
<attribute name="groups">admin:locale:create</attribute>
</attribute>
</collectionOperation>

<collectionOperation name="shop_get">
<attribute name="method">GET</attribute>
<attribute name="path">shop/locales</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:locale:read</attribute>
</attribute>
</collectionOperation>
</collectionOperations>

<itemOperations>
<itemOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="path">admin/locales/{code}</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:locale:read</attribute>
</attribute>
</itemOperation>

<itemOperation name="shop_get">
<attribute name="method">GET</attribute>
<attribute name="path">shop/locales/{code}</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:locale:read</attribute>
</attribute>
</itemOperation>
</itemOperations>

<property name="id" identifier="false" writable="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<attribute name="email">
<group>shop:reset_password:create</group>
</attribute>
<attribute name="localeCode">
<attribute name="localeCode" serialized-name="locale">
<group>shop:reset_password:create</group>
</attribute>
</class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<attribute name="email">
<group>shop:resend_verification_email:create</group>
</attribute>
<attribute name="localeCode">
<attribute name="localeCode" serialized-name="locale">
<group>shop:resend_verification_email:create</group>
</attribute>
</class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Bundle\ApiBundle\Command\Cart\PickupCart">
<attribute name="localeCode">
<attribute name="localeCode" serialized-name="locale">
<group>shop:order:create</group>
</attribute>
</class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod">
<attribute name="shippingMethodCode">
<attribute name="shippingMethodCode" serialized-name="shippingMethod">
<group>shop:cart:select_shipping_method</group>
</attribute>
</class>
Expand Down
4 changes: 4 additions & 0 deletions src/Sylius/Bundle/ApiBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
<argument key="Sylius\Bundle\ApiBundle\Command\AddProductReview">product</argument>
<argument key="Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod">paymentMethod</argument>
<argument key="Sylius\Bundle\ApiBundle\Command\Account\ChangePaymentMethod">paymentMethod</argument>
<argument key="Sylius\Bundle\ApiBundle\Command\RequestResetPasswordToken">locale</argument>
<argument key="Sylius\Bundle\ApiBundle\Command\ResendVerificationEmail">locale</argument>
<argument key="Sylius\Bundle\ApiBundle\Command\Cart\PickupCart">locale</argument>
<argument key="Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod">shippingMethod</argument>
</argument>
</service>

Expand Down

0 comments on commit 8392bcd

Please sign in to comment.