[API][Channel] Minor fixes for adding and browsing channels PR after review

This commit is contained in:
Grzegorz Sadowski 2020-05-10 21:36:31 +02:00
parent aea199b90f
commit 18833cc0fb
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
7 changed files with 59 additions and 49 deletions

View file

@ -12,19 +12,20 @@ Feature: Adding a new channel
@ui @api
Scenario: Adding a new channel
Given I want to create a new channel
When I specify its code as "MOBILE"
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 select the "Order items based" as tax calculation strategy
And I add it
Then I should be notified that it has been successfully created
And the channel "Mobile channel" should appear in the registry
@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"
When I want to create a new channel
And I specify its code as "MOBILE"
And I name it "Mobile channel"
And I describe it as "Main distribution channel for mobile apps"
And I set its hostname as "m.avengers-gear.com"
@ -33,6 +34,7 @@ Feature: Adding a new channel
And I choose "Euro" as the base currency
And I choose "English (United States)" as a default locale
And I choose "United States" and "Poland" as operating countries
And I select the "Order items based" as tax calculation strategy
And I allow to skip shipping step if only one shipping method is available
And I allow to skip payment step if only one payment method is available
And I add it

View file

@ -12,11 +12,12 @@ Feature: Adding a new channel with shop billing data
@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"
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 select the "Order items based" as tax calculation strategy
And I specify company as "Ragnarok"
And I specify tax ID as "1100110011"
And I specify shop billing address as "Pacific Coast Hwy", "90806" "Los Angeles", "United States"

View file

@ -18,6 +18,7 @@ Feature: Adding a new channel with menu taxon
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 select the "Order items based" as tax calculation strategy
And I specify menu taxon as "Clothes"
And I add it
Then I should be notified that it has been successfully created

View file

@ -18,6 +18,7 @@ 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\Formatter\StringInflector;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
@ -30,7 +31,7 @@ final class ManagingChannelsContext implements Context
private $client;
/** @var ApiClientInterface */
private $billingDataClient;
private $shopBillingDatasClient;
/** @var ResponseCheckerInterface */
private $responseChecker;
@ -39,29 +40,26 @@ final class ManagingChannelsContext implements Context
private $iriConverter;
/** @var array */
private $billingData = [];
private $shopBillingData = [];
public function __construct(
ApiClientInterface $client,
ApiClientInterface $billingDataClient,
ApiClientInterface $shopBillingDatasClient,
ResponseCheckerInterface $responseChecker,
IriConverterInterface $iriConverter
) {
$this->client = $client;
$this->billingDataClient = $billingDataClient;
$this->shopBillingDatasClient = $shopBillingDatasClient;
$this->responseChecker = $responseChecker;
$this->iriConverter = $iriConverter;
}
/**
* @Given I want to create a new channel
* @When 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');
}
/**
@ -70,7 +68,7 @@ final class ManagingChannelsContext implements Context
* @When I set its :field as :value
* @When I define its :field as :value
*/
public function iSpecifyItsCodeAs(string $field, string $value): void
public function iSpecifyItsAs(string $field, string $value): void
{
$this->client->addRequestData($field, $value);
}
@ -147,7 +145,7 @@ final class ManagingChannelsContext implements Context
*/
public function iSpecifyCompanyAs(string $company): void
{
$this->billingData['company'] = $company;
$this->shopBillingData['company'] = $company;
}
/**
@ -155,7 +153,7 @@ final class ManagingChannelsContext implements Context
*/
public function iSpecifyTaxIdAs(string $taxId): void
{
$this->billingData['taxId'] = $taxId;
$this->shopBillingData['taxId'] = $taxId;
}
/**
@ -167,10 +165,18 @@ final class ManagingChannelsContext implements Context
string $city,
CountryInterface $country
): void {
$this->billingData['street'] = $street;
$this->billingData['city'] = $city;
$this->billingData['postcode'] = $postcode;
$this->billingData['countryCode'] = $country->getCode();
$this->shopBillingData['street'] = $street;
$this->shopBillingData['city'] = $city;
$this->shopBillingData['postcode'] = $postcode;
$this->shopBillingData['countryCode'] = $country->getCode();
}
/**
* @When I select the :taxCalculationStrategy as tax calculation strategy
*/
public function iSelectTaxCalculationStrategy(string $taxCalculationStrategy): void
{
$this->client->addRequestData('taxCalculationStrategy', StringInflector::nameToLowercaseCode($taxCalculationStrategy));
}
/**
@ -236,13 +242,13 @@ final class ManagingChannelsContext implements Context
private function createBillingData(): void
{
if (!empty($this->billingData)) {
$this->billingDataClient->buildCreateRequest();
foreach ($this->billingData as $field => $value) {
$this->billingDataClient->addRequestData($field, $value);
if (!empty($this->shopBillingData)) {
$this->shopBillingDatasClient->buildCreateRequest();
foreach ($this->shopBillingData as $field => $value) {
$this->shopBillingDatasClient->addRequestData($field, $value);
}
$this->billingDataClient->create();
$iri = $this->responseChecker->getValue($this->billingDataClient->getLastResponse(), '@id');
$this->shopBillingDatasClient->create();
$iri = $this->responseChecker->getValue($this->shopBillingDatasClient->getLastResponse(), '@id');
$this->client->addRequestData('shopBillingData', $iri);
}
}

View file

@ -55,14 +55,14 @@ final class LocaleContext implements Context
/**
* @Transform :locale
*/
public function getProductByName(string $localeName): LocaleInterface
public function getLocaleByName(string $name): LocaleInterface
{
$locale = $this->localeRepository->findOneByCode($this->localeNameConverter->convertNameToCode($localeName));
$locale = $this->localeRepository->findOneBy(['code' => $this->localeNameConverter->convertNameToCode($name)]);
Assert::isInstanceOf(
$locale,
LocaleInterface::class,
sprintf('Cannot find "%s" locale.', $localeName)
sprintf('Cannot find "%s" locale.', $name)
);
return $locale;

View file

@ -57,7 +57,7 @@ final class ManagingChannelsContext implements Context
}
/**
* @Given I want to create a new channel
* @When I want to create a new channel
*/
public function iWantToCreateANewChannel()
{

View file

@ -42,25 +42,25 @@
<property name="id" identifier="false" writable="false" />
<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="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" />
<subresource resourceClass="Sylius\Component\Core\Model\ShopBillingData" collection="false" />
</property>
<property name="menuTaxon" writable="true" readable="true"/>
<property name="menuTaxon" writable="true" readable="true" />
</resource>
</resources>