adding and browsing channel

This commit is contained in:
Olivier ALLAIN 2020-05-03 21:16:10 +02:00 committed by Grzegorz Sadowski
parent c62740f3fb
commit aea199b90f
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
15 changed files with 465 additions and 11 deletions

View file

@ -10,7 +10,7 @@ Feature: Adding a new channel
And the store operates in "United States" and "Poland"
And I am logged in as an administrator
@ui
@ui @api
Scenario: Adding a new channel
Given I want to create a new channel
When I specify its code as "MOBILE"
@ -21,7 +21,7 @@ Feature: Adding a new channel
Then I should be notified that it has been successfully created
And the channel "Mobile channel" should appear in the registry
@ui
@ui @api
Scenario: Adding a new channel with additional fields
Given I want to create a new channel
When I specify its code as "MOBILE"

View file

@ -10,7 +10,7 @@ Feature: Adding a new channel with shop billing data
And the store operates in "United States"
And I am logged in as an administrator
@ui
@ui @api
Scenario: Adding a new channel with shop billing data
Given I want to create a new channel
When I specify its code as "MOBILE"

View file

@ -11,11 +11,13 @@ Feature: Adding a new channel with menu taxon
And the store classifies its products as "Clothes" and "Guns"
And I am logged in as an administrator
@ui @javascript
@ui @javascript @api
Scenario: Adding a new channel with menu taxon
When I want to create a new channel
And I specify its code as "MOBILE"
And I name it "Mobile channel"
And I choose "Euro" as the base currency
And I choose "English (United States)" as a default locale
And I specify menu taxon as "Clothes"
And I add it
Then I should be notified that it has been successfully created

View file

@ -9,7 +9,7 @@ Feature: Browsing channels
And the store operates on another channel named "Mobile Channel"
And I am logged in as an administrator
@ui
@ui @api
Scenario: Browsing defined channels
When I want to browse channels
Then I should see 2 channels in the list

View file

@ -0,0 +1,249 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Behat\Context\Api\Admin;
use ApiPlatform\Core\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Webmozart\Assert\Assert;
final class ManagingChannelsContext implements Context
{
/** @var ApiClientInterface */
private $client;
/** @var ApiClientInterface */
private $billingDataClient;
/** @var ResponseCheckerInterface */
private $responseChecker;
/** @var IriConverterInterface */
private $iriConverter;
/** @var array */
private $billingData = [];
public function __construct(
ApiClientInterface $client,
ApiClientInterface $billingDataClient,
ResponseCheckerInterface $responseChecker,
IriConverterInterface $iriConverter
) {
$this->client = $client;
$this->billingDataClient = $billingDataClient;
$this->responseChecker = $responseChecker;
$this->iriConverter = $iriConverter;
}
/**
* @Given I want to create a new channel
*/
public function iWantToCreateANewChannel(): void
{
$this->client->buildCreateRequest();
// @see https://github.com/Sylius/Sylius/issues/11414
$this->client->addRequestData('taxCalculationStrategy', 'order_items_based');
}
/**
* @When I specify its :field as :value
* @When I :field it :value
* @When I set its :field as :value
* @When I define its :field as :value
*/
public function iSpecifyItsCodeAs(string $field, string $value): void
{
$this->client->addRequestData($field, $value);
}
/**
* @When I choose :currency as the base currency
*/
public function iChooseAsTheBaseCurrency(CurrencyInterface $currency): void
{
$this->client->addRequestData('baseCurrency', $this->iriConverter->getIriFromItem($currency));
}
/**
* @When I choose :locale as a default locale
*/
public function iChooseAsADefaultLocale(LocaleInterface $locale): void
{
$this->client->addRequestData('defaultLocale', $this->iriConverter->getIriFromItem($locale));
}
/**
* @When I describe it as :description
*/
public function iDescribeItAs(string $description): void
{
$this->client->addRequestData('description', $description);
}
/**
* @When I set its contact email as :contactEmail
*/
public function iSetItsContactEmailAs(string $contactEmail): void
{
$this->client->addRequestData('contactEmail', $contactEmail);
}
/**
* @When I choose :country and :otherCountry as operating countries
*/
public function iChooseAndAsOperatingCountries(CountryInterface $country, CountryInterface $otherCountry): void
{
$this->client->addRequestData('countries', [
$this->iriConverter->getIriFromItem($country),
$this->iriConverter->getIriFromItem($otherCountry),
]);
}
/**
* @When I allow to skip shipping step if only one shipping method is available
*/
public function iAllowToSkipShippingStepIfOnlyOneShippingMethodIsAvailable(): void
{
$this->client->addRequestData('skippingShippingStepAllowed', true);
}
/**
* @When I allow to skip payment step if only one payment method is available
*/
public function iAllowToSkipPaymentStepIfOnlyOnePaymentMethodIsAvailable(): void
{
$this->client->addRequestData('skippingPaymentStepAllowed', true);
}
/**
* @When I specify menu taxon as :taxon
*/
public function iSpecifyMenuTaxonAs(TaxonInterface $taxon): void
{
$this->client->addRequestData('menuTaxon', $this->iriConverter->getIriFromItem($taxon));
}
/**
* @When I specify company as :company
*/
public function iSpecifyCompanyAs(string $company): void
{
$this->billingData['company'] = $company;
}
/**
* @When I specify tax ID as :taxId
*/
public function iSpecifyTaxIdAs(string $taxId): void
{
$this->billingData['taxId'] = $taxId;
}
/**
* @When I specify shop billing address as :street, :postcode :city, :country
*/
public function specifyShopBillingAddressAs(
string $street,
string $postcode,
string $city,
CountryInterface $country
): void {
$this->billingData['street'] = $street;
$this->billingData['city'] = $city;
$this->billingData['postcode'] = $postcode;
$this->billingData['countryCode'] = $country->getCode();
}
/**
* @When I add it
*/
public function iAddIt(): void
{
$this->createBillingData();
$this->client->create();
}
/**
* @When I want to browse channels
*/
public function iWantToBrowseChannels(): void
{
$this->client->index();
}
/**
* @Then I should be notified that it has been successfully created
*/
public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void
{
Assert::true(
$this->responseChecker->isCreationSuccessful($this->client->getLastResponse()),
'Channel could not be created'
);
}
/**
* @Then the channel :name should appear in the registry
* @Then the channel :name should be in the registry
*/
public function theChannelShouldAppearInTheRegistry(string $name): void
{
Assert::true(
$this->responseChecker->hasItemWithValue($this->client->index(),'name', $name),
sprintf('Channel with name %s does not exist', $name)
);
}
/**
* @Then the channel :channel should have :taxon as a menu taxon
*/
public function theChannelShouldHaveAsAMenuTaxon(ChannelInterface $channel, TaxonInterface $taxon): void
{
Assert::same(
$this->responseChecker->getValue($this->client->show($channel->getCode()), 'menuTaxon'),
$this->iriConverter->getIriFromItem($taxon),
sprintf('Channel %s does not have %s menu taxon', $channel->getName(), $taxon->getName())
);
}
/**
* @Then I should see :count channels in the list
*/
public function iShouldSeeChannelsInTheList(int $count): void
{
Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), $count);
}
private function createBillingData(): void
{
if (!empty($this->billingData)) {
$this->billingDataClient->buildCreateRequest();
foreach ($this->billingData as $field => $value) {
$this->billingDataClient->addRequestData($field, $value);
}
$this->billingDataClient->create();
$iri = $this->responseChecker->getValue($this->billingDataClient->getLastResponse(), '@id');
$this->client->addRequestData('shopBillingData', $iri);
}
}
}

View file

@ -40,6 +40,7 @@ final class CountryContext implements Context
* @Transform /^"([^"]+)" as shipping country$/
* @Transform /^"([^"]+)" as billing country$/
* @Transform :country
* @Transform :otherCountry
*/
public function getCountryByName($countryName)
{

View file

@ -15,15 +15,22 @@ namespace Sylius\Behat\Context\Transform;
use Behat\Behat\Context\Context;
use Sylius\Component\Locale\Converter\LocaleConverterInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Webmozart\Assert\Assert;
final class LocaleContext implements Context
{
/** @var LocaleConverterInterface */
private $localeNameConverter;
public function __construct(LocaleConverterInterface $localeNameConverter)
/** @var RepositoryInterface */
private $localeRepository;
public function __construct(LocaleConverterInterface $localeNameConverter, RepositoryInterface $localeRepository)
{
$this->localeNameConverter = $localeNameConverter;
$this->localeRepository = $localeRepository;
}
/**
@ -32,7 +39,7 @@ final class LocaleContext implements Context
* @Transform /^"([^"]+)" locale$/
* @Transform /^in the "([^"]+)" locale$/
*/
public function castToLocaleCode($localeName)
public function castToLocaleCode(string $localeName): string
{
return $this->localeNameConverter->convertNameToCode($localeName);
}
@ -40,8 +47,24 @@ final class LocaleContext implements Context
/**
* @Transform :localeName
*/
public function castToLocaleName($localeCode)
public function castToLocaleName(string $localeCode): string
{
return $this->localeNameConverter->convertCodeToName($localeCode);
}
/**
* @Transform :locale
*/
public function getProductByName(string $localeName): LocaleInterface
{
$locale = $this->localeRepository->findOneByCode($this->localeNameConverter->convertNameToCode($localeName));
Assert::isInstanceOf(
$locale,
LocaleInterface::class,
sprintf('Cannot find "%s" locale.', $localeName)
);
return $locale;
}
}

View file

@ -25,6 +25,12 @@
<argument>avatar-images</argument>
</service>
<service id="sylius.behat.api_platform_client.channel" class="Sylius\Behat\Client\ApiPlatformClient">
<argument type="service" id="test.client" />
<argument type="service" id="sylius.behat.shared_storage" />
<argument>channels</argument>
</service>
<service id="sylius.behat.api_platform_client.country" class="Sylius\Behat\Client\ApiPlatformClient">
<argument type="service" id="test.client" />
<argument type="service" id="sylius.behat.shared_storage" />
@ -97,6 +103,12 @@
<argument>shipping-methods</argument>
</service>
<service id="sylius.behat.api_platform_client.shop_billing_data" class="Sylius\Behat\Client\ApiPlatformClient">
<argument type="service" id="test.client" />
<argument type="service" id="sylius.behat.shared_storage" />
<argument>shop-billing-datas</argument>
</service>
<service id="sylius.behat.api_platform_client.tax_category" class="Sylius\Behat\Client\ApiPlatformClient">
<argument type="service" id="test.client" />
<argument type="service" id="sylius.behat.shared_storage" />

View file

@ -31,6 +31,13 @@
<argument type="service" id="behat.mink.parameters" />
</service>
<service id="sylius.behat.context.api.admin.managing_channels" class="Sylius\Behat\Context\Api\Admin\ManagingChannelsContext">
<argument type="service" id="sylius.behat.api_platform_client.channel" />
<argument type="service" id="sylius.behat.api_platform_client.shop_billing_data" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="api_platform.iri_converter" />
</service>
<service id="sylius.behat.context.api.admin.managing_countries" class="Sylius\Behat\Context\Api\Admin\ManagingCountriesContext">
<argument type="service" id="sylius.behat.api_platform_client.country" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />

View file

@ -64,6 +64,7 @@
<service id="sylius.behat.context.transform.locale" class="Sylius\Behat\Context\Transform\LocaleContext">
<argument type="service" id="sylius.locale_converter" />
<argument type="service" id="sylius.repository.locale" />
</service>
<service id="sylius.behat.context.transform.order" class="Sylius\Behat\Context\Transform\OrderContext">

View file

@ -6,6 +6,7 @@ imports:
- suites/api/account/customer_registration.yml
- suites/api/account/login.yml
- suites/api/admin/login.yml
- suites/api/channel/managing_channels.yml
- suites/api/currency/managing_currencies.yml
- suites/api/currency/managing_exchange_rates.yml
- suites/api/homepage/viewing_products.yml

View file

@ -0,0 +1,33 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski
default:
suites:
api_managing_channels:
contexts:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.transform.address
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.country
- sylius.behat.context.transform.currency
- sylius.behat.context.transform.locale
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.taxon
- sylius.behat.context.transform.zone
- sylius.behat.context.setup.admin_api_security
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.currency
- sylius.behat.context.setup.geographical
- sylius.behat.context.setup.locale
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.taxonomy
- sylius.behat.context.setup.zone
- sylius.behat.context.api.admin.managing_channels
filters:
tags: "@managing_channels && @api"
javascript: false

View file

@ -22,7 +22,14 @@
</attribute>
</attribute>
<collectionOperations />
<collectionOperations>
<collectionOperation name="get">
<attribute name="security">is_granted('ROLE_API_ACCESS')</attribute>
</collectionOperation>
<collectionOperation name="post">
<attribute name="security">is_granted('ROLE_API_ACCESS')</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations>
<itemOperation name="get">
@ -34,7 +41,26 @@
</itemOperations>
<property name="id" identifier="false" writable="false" />
<property name="code" identifier="true" writable="false" readable="true" />
<property name="code" identifier="true" required="true" />
<property name="name" writable="true" readable="true"/>
<property name="description" writable="true" readable="true"/>
<property name="hostname" writable="true" readable="true"/>
<property name="color" writable="true" readable="true"/>
<property name="baseCurrency" writable="true" readable="true"/>
<property name="defaultLocale" writable="true" readable="true"/>
<property name="defaultTaxZone" writable="true" readable="true"/>
<property name="taxCalculationStrategy" writable="true" readable="true"/>
<property name="currencies" writable="true" readable="true"/>
<property name="locales" writable="true" readable="true"/>
<property name="countries" writable="true" readable="true"/>
<property name="themeName" writable="true" readable="true"/>
<property name="contactEmail" writable="true" readable="true"/>
<property name="skippingShippingStepAllowed" writable="true" readable="true"/>
<property name="skippingPaymentStepAllowed" writable="true" readable="true"/>
<property name="accountVerificationRequired" writable="true" readable="true"/>
<property name="shopBillingData" readable="true" writable="true">
<subresource resourceClass="Sylius\Component\Core\Model\ShopBillingData" collection="true" />
</property>
<property name="menuTaxon" writable="true" readable="true"/>
</resource>
</resources>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" ?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
<resource class="%sylius.model.shop_billing_data.class%" shortName="ShopBillingData">
<attribute name="normalization_context">
<attribute name="groups">
<attribute>shop_billing_data:read</attribute>
</attribute>
</attribute>
<attribute name="validation_groups">sylius</attribute>
<collectionOperations>
<collectionOperation name="post">
<attribute name="security">is_granted('ROLE_API_ACCESS')</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations>
<itemOperation name="get">
<attribute name="security">is_granted('ROLE_API_ACCESS')</attribute>
</itemOperation>
<itemOperation name="put">
<attribute name="security">is_granted('ROLE_API_ACCESS')</attribute>
<attribute name="denormalization_context">
<attribute name="groups">shop_billing_data:update</attribute>
</attribute>
</itemOperation>
</itemOperations>
<property name="id" identifier="true" writable="false" />
<property name="company" writable="true" readable="true"/>
<property name="taxId" writable="true" readable="true"/>
<property name="countryCode" writable="true" readable="true"/>
<property name="street" writable="true" readable="true"/>
<property name="city" writable="true" readable="true"/>
<property name="postcode" writable="true" readable="true"/>
</resource>
</resources>

View file

@ -19,9 +19,59 @@
<attribute name="code">
<group>channel:read</group>
</attribute>
<attribute name="name">
<group>channel:read</group>
</attribute>
<attribute name="description">
<group>channel:read</group>
</attribute>
<attribute name="hostname">
<group>channel:read</group>
</attribute>
<attribute name="color">
<group>channel:read</group>
</attribute>
<attribute name="baseCurrency">
<group>channel:read</group>
</attribute>
<attribute name="defaultLocale">
<group>channel:read</group>
</attribute>
<attribute name="defaultTaxZone">
<group>channel:read</group>
</attribute>
<attribute name="taxCalculationStrategy">
<group>channel:read</group>
</attribute>
<attribute name="currencies">
<group>channel:read</group>
</attribute>
<attribute name="locales">
<group>channel:read</group>
</attribute>
<attribute name="countries">
<group>channel:read</group>
</attribute>
<attribute name="themeName">
<group>channel:read</group>
</attribute>
<attribute name="contactEmail">
<group>channel:read</group>
</attribute>
<attribute name="skippingShippingStepAllowed">
<group>channel:read</group>
</attribute>
<attribute name="skippingPaymentStepAllowed">
<group>channel:read</group>
</attribute>
<attribute name="accountVerificationRequired">
<group>channel:read</group>
</attribute>
<attribute name="shopBillingData">
<group>channel:read</group>
</attribute>
<attribute name="menuTaxon">
<group>channel:read</group>
</attribute>
</class>
</serializer>