Skip to content

Commit

Permalink
[Api][Address] Add missing behats scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Oct 28, 2020
1 parent 8ae12f2 commit e823246
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
4 changes: 2 additions & 2 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ security:

- { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS }
- { path: "%sylius.security.new_api_route%/admin/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.new_api_route%/shop/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.new_api_user_account_regex%/.*", role: ROLE_USER }
- { path: "%sylius.security.new_api_route%/shop/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY }
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@address_book
Feature: Preventing not logged user from operations on the address book
In order to protect address book from unauthorised operation
As a Visitor
I want to not be able to operate on 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

@api
Scenario: Trying to add new address as a Visitor
When I want to add a new address to my address book
And I specify the address as "Lucifer Morningstar", "Seaside Fwy", "90802", "Los Angeles", "United States", "Arkansas"
And I try to add it
Then I should not be able to add it

@api
Scenario: Trying to view address as a Visitor
When I try to view details of address belongs to "John Doe"
Then I should not see any details of address

@api
Scenario: Trying to delete address as a Visitor
When I try to delete address belongs to "John Doe"
Then I should not be able to delete it
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,3 @@ Feature: Viewing 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"

@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
31 changes: 28 additions & 3 deletions src/Sylius/Behat/Context/Api/Shop/AddressContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function iSpecifyTheAddressAs(AddressInterface $address): void

/**
* @When I add it
* @When I try to add it
*/
public function iAddIt(): void
{
Expand Down Expand Up @@ -157,6 +158,14 @@ public function iDeleteTheAddress(string $fullName): void
$this->addressClient->delete($id);
}

/**
* @When /^I try to delete (address belongs to "([^"]+)")$/
*/
public function iDeleteTheAddressBelongsTo(AddressInterface $address): void
{
$this->addressClient->delete($this->iriConverter->getIriFromItem($address));
}

/**
* @When I set the address of :fullName as default
*/
Expand All @@ -170,11 +179,11 @@ public function iSetTheAddressOfAsDefault(string $fullName): void
}

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

/**
Expand Down Expand Up @@ -325,7 +334,23 @@ public function iShouldBeNotifiedThatAddressHasBeenSetAsDefault(): void
*/
public function iShouldNotSeeAnyDetailsOfAddress(): void
{
Assert::same($this->responseChecker->getError($this->client->getLastResponse()), 'Not Found');
Assert::same($this->responseChecker->getError($this->addressClient->getLastResponse()), 'JWT Token not found');
}

/**
* @Then I should not be able to add it
*/
public function iShouldNotBeAbleToDoIt(): void
{
Assert::false($this->responseChecker->isCreationSuccessful($this->addressClient->getLastResponse()));
}

/**
* @Then I should not be able to delete it
*/
public function iShouldNotBeAbleToDeleteIt(): void
{
Assert::false($this->responseChecker->isDeletionSuccessful($this->addressClient->getLastResponse()));
}

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

/**
* @Transform /^address of "([^"]+)"$/
* @Transform /^address belonging to "([^"]+)"$/
* @Transform /^address belongs to "([^"]+)"$/
*/
public function getByFullName(string $fullName): AddressInterface
{
Expand Down

0 comments on commit e823246

Please sign in to comment.