Skip to content

Commit

Permalink
[API][Shop] Logging in after changing password implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lchrusciel committed Nov 3, 2020
1 parent 04a6676 commit eb4b918
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
7 changes: 2 additions & 5 deletions features/account/customer_account/changing_password.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ Feature: Changing a customer password
And I save my changes
Then I should be notified that my password has been successfully changed

@todo
@api @ui
Scenario: Logging to store after password change
Given I've changed my password from "whitehouse" to "blackhouse"
When I want to log in
And I specify the username as "francis@underwood.com"
And I specify the password as "blackhouse"
And I log in
When I log in as "francis@underwood.com" with "blackhouse" password
Then I should be logged in
22 changes: 21 additions & 1 deletion src/Sylius/Behat/Context/Setup/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@

namespace Sylius\Behat\Context\Setup;

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Bundle\ApiBundle\Command\ChangeShopUserPassword;
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\User\Model\UserInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
use Symfony\Component\Messenger\MessageBusInterface;

final class UserContext implements Context
{
Expand All @@ -35,16 +38,21 @@ final class UserContext implements Context
/** @var ObjectManager */
private $userManager;

/** @var MessageBusInterface */
private $messageBus;

public function __construct(
SharedStorageInterface $sharedStorage,
UserRepositoryInterface $userRepository,
ExampleFactoryInterface $userFactory,
ObjectManager $userManager
ObjectManager $userManager,
MessageBusInterface $messageBus
) {
$this->sharedStorage = $sharedStorage;
$this->userRepository = $userRepository;
$this->userFactory = $userFactory;
$this->userManager = $userManager;
$this->messageBus = $messageBus;
}

/**
Expand Down Expand Up @@ -166,4 +174,16 @@ private function prepareUserPasswordResetToken(UserInterface $user): void

$this->userManager->flush();
}

/**
* @Given /^(I)'ve changed my password from "([^"]+)" to "([^"]+)"$/
*/
public function iveChangedMyPasswordFromTo(UserInterface $user, string $currentPassword, string $newPassword): void
{
$changeShopUserPassword = new ChangeShopUserPassword($newPassword, $newPassword, $currentPassword);

$changeShopUserPassword->setShopUserId($user->getId());

$this->messageBus->dispatch($changeShopUserPassword);
}
}
9 changes: 9 additions & 0 deletions src/Sylius/Behat/Context/Ui/Shop/HomepageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@ public function iShouldNotSeeAndInTheMenu(string ...$menuItems): void
}
}
}

/**
* @Then I should be logged in
*/
public function iShouldBeLoggedIn(): void
{
$this->homePage->verify();
Assert::true($this->homePage->hasLogoutButton());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
<argument type="service" id="sylius.repository.shop_user" />
<argument type="service" id="sylius.fixture.example_factory.shop_user" />
<argument type="service" id="sylius.manager.shop_user" />
<argument type="service" id="sylius_default.bus" />
</service>

<service id="sylius.behat.context.setup.zone" class="Sylius\Behat\Context\Setup\ZoneContext">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ default:
- sylius.behat.context.setup.zone

- sylius.behat.context.ui.channel
- sylius.behat.context.ui.email
- sylius.behat.context.ui.shop.account
- sylius.behat.context.ui.shop.cart
- sylius.behat.context.ui.shop.checkout
Expand All @@ -42,7 +43,7 @@ default:
- sylius.behat.context.ui.shop.checkout.payment
- sylius.behat.context.ui.shop.checkout.shipping
- sylius.behat.context.ui.shop.currency
- sylius.behat.context.ui.email
- sylius.behat.context.ui.shop.homepage

filters:
tags: "@customer_account && @ui"

0 comments on commit eb4b918

Please sign in to comment.