-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Account][API] Edititng customer profile with validation
- Loading branch information
Showing
10 changed files
with
279 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
<?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\Shop; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Sylius\Behat\Client\ApiClientInterface; | ||
use Sylius\Behat\Client\ResponseCheckerInterface; | ||
use Sylius\Behat\Service\SharedStorageInterface; | ||
use Sylius\Component\Core\Model\ShopUserInterface; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class AccountContext implements Context | ||
{ | ||
/** @var ApiClientInterface */ | ||
private $accountClient; | ||
|
||
/** @var SharedStorageInterface */ | ||
private $sharedStorage; | ||
|
||
/** @var ResponseCheckerInterface */ | ||
private $responseChecker; | ||
|
||
public function __construct( | ||
ApiClientInterface $accountClient, | ||
SharedStorageInterface $sharedStorage, | ||
ResponseCheckerInterface $responseChecker | ||
) { | ||
$this->accountClient = $accountClient; | ||
$this->sharedStorage = $sharedStorage; | ||
$this->responseChecker = $responseChecker; | ||
} | ||
|
||
/** | ||
* @When I want to modify my profile | ||
*/ | ||
public function iWantToModifyMyProfile(): void | ||
{ | ||
/** @var ShopUserInterface $shopUser */ | ||
$shopUser = $this->sharedStorage->get('user'); | ||
$customer = $shopUser->getCustomer(); | ||
|
||
$this->accountClient->buildUpdateRequest((string) $customer->getId()); | ||
} | ||
|
||
/** | ||
* @When I specify the first name as :firstName | ||
* @When I remove the first name | ||
*/ | ||
public function iSpecifyTheFirstName(string $firstName = ''): void | ||
{ | ||
$this->accountClient->addRequestData('firstName', $firstName); | ||
} | ||
|
||
/** | ||
* @When I specify the last name as :lastName | ||
* @When I remove the last name | ||
*/ | ||
public function iSpecifyTheLastName(string $lastName = ''): void | ||
{ | ||
$this->accountClient->addRequestData('lastName', $lastName); | ||
} | ||
|
||
/** | ||
* @When I specify the customer email as :email | ||
* @When I remove the customer email | ||
*/ | ||
public function iSpecifyCustomerTheEmail(string $email = ''): void | ||
{ | ||
$this->accountClient->addRequestData('email', $email); | ||
} | ||
|
||
/** | ||
* @When I save my changes | ||
* @When I try to save my changes | ||
*/ | ||
public function iSaveMyChanges(): void | ||
{ | ||
$this->accountClient->update(); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that it has been successfully edited | ||
*/ | ||
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void | ||
{ | ||
Assert::true($this->responseChecker->isUpdateSuccessful($this->accountClient->getLastResponse())); | ||
} | ||
|
||
/** | ||
* @Then my email should be :email | ||
* @Then my email should still be :email | ||
*/ | ||
public function myEmailShouldBe(string $email): void | ||
{ | ||
/** @var ShopUserInterface $shopUser */ | ||
$shopUser = $this->sharedStorage->get('user'); | ||
|
||
$response = $this->accountClient->show((string) $shopUser->getCustomer()->getId()); | ||
|
||
Assert::true($this->responseChecker->hasValue($response, 'email', $email)); | ||
} | ||
|
||
/** | ||
* @Then my name should be :name | ||
* @Then my name should still be :name | ||
*/ | ||
public function myNameShouldBe(string $name): void | ||
{ | ||
/** @var ShopUserInterface $shopUser */ | ||
$shopUser = $this->sharedStorage->get('user'); | ||
|
||
$response = $this->accountClient->show((string) $shopUser->getCustomer()->getId()); | ||
|
||
Assert::true($this->responseChecker->hasValue($response, 'fullName', $name)); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that the first name is required | ||
*/ | ||
public function iShouldBeNotifiedThatFirstNameIsRequired(): void | ||
{ | ||
$this->isViolationWithMessageInResponse( | ||
$this->accountClient->getLastResponse(), | ||
'First name must be at least 2 characters long.' | ||
); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that the last name is required | ||
*/ | ||
public function iShouldBeNotifiedThatLastNameIsRequired(): void | ||
{ | ||
$this->isViolationWithMessageInResponse( | ||
$this->accountClient->getLastResponse(), | ||
'Last name must be at least 2 characters long.' | ||
); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that the email is required | ||
*/ | ||
public function iShouldBeNotifiedThatEmailIsRequired(): void | ||
{ | ||
$this->isViolationWithMessageInResponse( | ||
$this->accountClient->getLastResponse(), | ||
'Please enter your email.' | ||
); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that the email is already used | ||
*/ | ||
public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed(): void | ||
{ | ||
$this->isViolationWithMessageInResponse( | ||
$this->accountClient->getLastResponse(), | ||
'This email is already used.' | ||
); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that the email is invalid | ||
*/ | ||
public function iShouldBeNotifiedThatElementIsInvalid(): void | ||
{ | ||
$this->isViolationWithMessageInResponse( | ||
$this->accountClient->getLastResponse(), | ||
'This email is invalid.' | ||
); | ||
} | ||
|
||
private function isViolationWithMessageInResponse(Response $response, string $message): bool | ||
{ | ||
$violations = $this->responseChecker->getResponseContent($response)['violations']; | ||
foreach ($violations as $violation) { | ||
if ($violation['message'] === $message) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Sylius/Behat/Resources/config/suites/api/account/customer.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This file is part of the Sylius package. | ||
# (c) Paweł Jędrzejewski | ||
|
||
default: | ||
suites: | ||
api_customer_account: | ||
contexts: | ||
- sylius.behat.context.hook.doctrine_orm | ||
|
||
- sylius.behat.context.transform.country | ||
- sylius.behat.context.transform.customer | ||
- sylius.behat.context.transform.user | ||
|
||
- sylius.behat.context.setup.currency | ||
- sylius.behat.context.setup.customer | ||
- sylius.behat.context.setup.shop_security | ||
- sylius.behat.context.setup.user | ||
- sylius.behat.context.setup.channel | ||
|
||
- sylius.behat.context.api.shop.account | ||
|
||
filters: | ||
tags: "@customer_account && @api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.