Skip to content

Commit

Permalink
[Api][Address] fix addresItemProvider and and missing scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Oct 27, 2020
1 parent 7e9ecdf commit 8ae12f2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ Feature: Viewing my address book

Background:
Given the store operates on a single channel in "United States"
And there is a customer "John Doe" identified by an email "doe@example.com" and a password "banana"
And this customer has an address "John Doe", "Banana Street", "90232", "New York", "United States", "Kansas" in their address book
And I am a logged in customer with name "Lucifer Morningstar"
And I have an address "Lucifer Morningstar", "Seaside Fwy", "90802", "Los Angeles", "United States", "Arkansas" in my address book

@ui @api
Scenario: Viewing all addresses
Given I have an address "Lucifer Morningstar", "Seaside Fwy", "90802", "Los Angeles", "United States", "Arkansas" in my address book
When I browse my address book
Then I should have a single address in my address book

@ui @api
Scenario: Inability to view the addresses of other customers
Given there is a customer "John Doe" identified by an email "doe@example.com" and a password "banana"
And this customer has an address "John Doe", "Banana Street", "90232", "New York", "United States", "Kansas" in their address book
And I have an address "Lucifer Morningstar", "Seaside Fwy", "90802", "Los Angeles", "United States", "Arkansas" in my address book
Scenario: Inability to view the addresses of other customers in address book
When I browse my address book
Then I should have a single address in my address book
And this address should be assigned to "Lucifer Morningstar"
And I should not see the address assigned to "John Doe"

@ui @api
Scenario: Viewing an empty address book
When I browse my address book
Then there should be no addresses
@api
Scenario: Inability to view details of an address belonging to other customer
When I try to view details of address belonging to "John Doe"
Then I should not see any details of address
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@address_book
Feature: Viewing empty address book
In order to see only added addresses
As a Customer
I want to be able to see empty address book

Background:
Given the store operates on a single channel in "United States"
And I am a logged in customer with name "Lucifer Morningstar"

@ui @api
Scenario: Viewing an empty address book
When I browse my address book
Then there should be no addresses
22 changes: 22 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/AddressContext.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\ResponseCheckerInterface;
Expand All @@ -35,6 +36,9 @@ final class AddressContext implements Context
/** @var AdminToShopIriConverterInterface */
private $adminToShopIriConverter;

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

/** @var SharedStorageInterface */
private $sharedStorage;

Expand All @@ -43,12 +47,14 @@ public function __construct(
ApiClientInterface $customerClient,
ResponseCheckerInterface $responseChecker,
AdminToShopIriConverterInterface $adminToShopIriConverter,
IriConverterInterface $iriConverter,
SharedStorageInterface $sharedStorage
) {
$this->addressClient = $addressClient;
$this->customerClient = $customerClient;
$this->responseChecker = $responseChecker;
$this->adminToShopIriConverter = $adminToShopIriConverter;
$this->iriConverter = $iriConverter;
$this->sharedStorage = $sharedStorage;
}

Expand Down Expand Up @@ -163,6 +169,14 @@ public function iSetTheAddressOfAsDefault(string $fullName): void
$this->customerClient->update();
}

/**
* @When /^I try to view details of (address belonging to "([^"]+)")$/
*/
public function iTryToViewDetailsOfAddressBelongingTo(AddressInterface $address): void
{
$this->client->showByIri($this->iriConverter->getIriFromItem($address));
}

/**
* @Then /^I should(?:| still) have a single address in my address book$/
* @Then /^I should(?:| still) have (\d+) addresses in my address book$/
Expand Down Expand Up @@ -306,6 +320,14 @@ public function iShouldBeNotifiedThatAddressHasBeenSetAsDefault(): void
Assert::true($this->responseChecker->isUpdateSuccessful($this->addressClient->getLastResponse()));
}

/**
* @Then I should not see any details of address
*/
public function iShouldNotSeeAnyDetailsOfAddress(): void
{
Assert::same($this->responseChecker->getError($this->client->getLastResponse()), 'Not Found');
}

private function addressBookHasAddress(array $addressBook, AddressInterface $addressToCompare): bool
{
foreach ($addressBook as $address) {
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Transform/AddressContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function getByStreet($street)

/**
* @Transform /^address of "([^"]+)"$/
* @Transform /^address belonging to "([^"]+)"$/
*/
public function getByFullName(string $fullName): AddressInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<argument type="service" id="sylius.behat.api_platform_client.shop.account" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="sylius.admin_to_shop_iri_converter" />
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>
</services>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getItem(string $resourceClass, $id, string $operationName = null
in_array('ROLE_USER', $user->getRoles(), true) &&
$customer !== null
) {
return $this->addressRepository->findOneByCustomer($id, $customer);
return $this->addressRepository->findOneByCustomer((string) $id, $customer);
}

if ($user instanceof AdminUserInterface && in_array('ROLE_API_ACCESS', $user->getRoles(), true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<service id="sylius.api.item_data_provider.address" class="Sylius\Bundle\ApiBundle\DataProvider\AddressItemDataProvider">
<argument type="service" id="sylius.repository.address" />
<argument type="service" id="sylius.api.context.user" />
<tag name="api_platform.collection_data_provider" priority="10" />
<tag name="api_platform.item_data_provider" priority="10" />
</service>

<service id="sylius.api.collection_data_provider.country" class="Sylius\Bundle\ApiBundle\DataProvider\CountryCollectionDataProvider">
Expand Down

0 comments on commit 8ae12f2

Please sign in to comment.