Skip to content

Commit

Permalink
add api delete address book
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed Oct 8, 2020
1 parent 91f26cd commit b566cd5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Removing an address from my book
And I am a logged in customer
And I have an address "Lucifer Morningstar", "Seaside Fwy", "90802", "Los Angeles", "United States", "Arkansas" in my address book

@ui
@ui @api
Scenario:
When I browse my address book
And I delete the "Lucifer Morningstar" address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Feature: Removing an address from my book
And my default address is of "Lucifer Morningstar"

@ui
Scenario: Viewing address created after placing an order
Scenario: Deleting address created after placing an order
Given I have product "PHP T-Shirt" in the cart
And I am at the checkout addressing step
When I specify the first and last name as "Mike Ross" for billing address
Expand All @@ -25,3 +25,18 @@ Feature: Removing an address from my book
And I delete the "Mike Ross" address
Then I should be notified that the address has been successfully deleted
And I should have a single address in my address book

@api
Scenario: Deleting address created after placing an order
Given I have product "PHP T-Shirt" in the cart
And I am at the checkout addressing step
And my billing address is fulfilled automatically through default address
When I specify the first and last name as "Mike Ross" for billing address
And I complete the addressing step
And I proceed with "Free" shipping method and "Offline" payment
And I confirm my order
And I browse my address book
And I delete the "Mike Ross" address
Then I should be notified that the address has been successfully deleted
Then I browse my address book
And I should have a single address in my address book
36 changes: 36 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 Down Expand Up @@ -89,9 +90,29 @@ public function iShouldNotSeeTheAddressAssignedTo(string $fullName): void
*/
public function thereShouldBeNoAddresses(): void
{
$this->client->index();

Assert::same(count($this->responseChecker->getCollection($this->client->getLastResponse())), 0);
}

/**
* @Then I delete the :fullName address
*/
public function iDeleteTheAddress(string $fullName): void
{
$id = $this->getAddressIdFromAddressBookByFullName($fullName);

$this->client->delete($id);
}

/**
* @Then I should be notified that the address has been successfully deleted
*/
public function iShouldBeNotifiedThatAddressHasBeenDeleted(): void
{
Assert::true($this->responseChecker->isDeletionSuccessful($this->client->getLastResponse()));
}

private function addressBookHasAddress(array $addressBook, AddressInterface $addressToCompare): bool
{
foreach ($addressBook as $address) {
Expand All @@ -111,4 +132,19 @@ private function addressBookHasAddress(array $addressBook, AddressInterface $add

return false;
}

private function getAddressIdFromAddressBookByFullName(string $fullName): ?string
{
Assert::notNull($fullName);
$fullNameArray = explode(' ',$fullName);

$addresses = $this->responseChecker->getCollection($this->client->getLastResponse());
/** @var AddressInterface $address */
foreach ($addresses as $address){
if ($fullNameArray[0] === $address['firstName'] && $fullNameArray[1] === $address['lastName']) {
$addressIriStringArray = explode('/', $address['@id']);
return end($addressIriStringArray);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<argument type="service" id="sylius.behat.api_platform_client.shop.address" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="api_platform.iri_converter" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<attribute name="method">GET</attribute>
<attribute name="path">/shop/addresses/{id}</attribute>
</itemOperation>
<itemOperation name="shop_delete">
<attribute name="method">DELETE</attribute>
<attribute name="path">/shop/addresses/{id}</attribute>
</itemOperation>
</itemOperations>

<property name="id" identifier="true" writable="false" />
Expand Down

0 comments on commit b566cd5

Please sign in to comment.