mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Unit] Add contract tests regarding ShopUser password reset
This commit is contained in:
parent
c3b956e9bc
commit
f6978e18ad
5 changed files with 145 additions and 1 deletions
|
|
@ -0,0 +1,18 @@
|
|||
Sylius\Component\Core\Model\ShopUser:
|
||||
shop_user_{oliver, dave}:
|
||||
plainPassword: "sylius"
|
||||
roles: [ROLE_USER]
|
||||
enabled: true
|
||||
passwordResetToken: "valid_token"
|
||||
passwordRequestedAt: "<(new \\DateTime('last week'))>"
|
||||
customer: "@customer_<current()>"
|
||||
username: "<current()>\\@doe.com"
|
||||
usernameCanonical: "<current()>\\@doe.com"
|
||||
|
||||
Sylius\Component\Core\Model\Customer:
|
||||
customer_{oliver, dave}:
|
||||
firstName: "<current()>"
|
||||
lastName: "Doe"
|
||||
email: "<current()>\\@doe.com"
|
||||
emailCanonical: "<current()>\\@doe.com"
|
||||
birthday: "<(new \\DateTime())>"
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
Sylius\Component\Core\Model\ShopUser:
|
||||
shop_user_{oliver, dave}:
|
||||
plainPassword: "sylius"
|
||||
roles: [ROLE_USER]
|
||||
enabled: true
|
||||
passwordResetToken: "valid_token"
|
||||
passwordRequestedAt: "<(new \\DateTime())>"
|
||||
customer: "@customer_<current()>"
|
||||
username: "<current()>\\@doe.com"
|
||||
usernameCanonical: "<current()>\\@doe.com"
|
||||
|
||||
Sylius\Component\Core\Model\Customer:
|
||||
customer_{oliver, dave}:
|
||||
firstName: "<current()>"
|
||||
lastName: "Doe"
|
||||
email: "<current()>\\@doe.com"
|
||||
emailCanonical: "<current()>\\@doe.com"
|
||||
birthday: "<(new \\DateTime())>"
|
||||
|
|
@ -47,7 +47,7 @@ final class SendContactRequestTest extends JsonApiTestCase
|
|||
/** @test */
|
||||
public function it_sends_contact_request_as_logged_in_user(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['channel.yaml', 'authentication/customer.yaml']);
|
||||
$fixtures = $this->loadFixturesFromFiles(['channel.yaml', 'authentication/shop_user.yaml']);
|
||||
/** @var CustomerInterface $customer */
|
||||
$customer = $fixtures['customer_oliver'];
|
||||
|
||||
|
|
|
|||
108
tests/Api/Shop/ShopUsersTest.php
Normal file
108
tests/Api/Shop/ShopUsersTest.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* 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\Tests\Api\Shop;
|
||||
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\ContentType;
|
||||
use Sylius\Tests\Api\Utils\ShopUserLoginTrait;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class ShopUsersTest extends JsonApiTestCase
|
||||
{
|
||||
use ShopUserLoginTrait;
|
||||
|
||||
/** @test */
|
||||
public function it_sends_shop_user_password_reset_email(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['channel.yaml', 'authentication/shop_user.yaml']);
|
||||
|
||||
$this->client->request(
|
||||
method: Request::METHOD_POST,
|
||||
uri: '/api/v2/shop/reset-password',
|
||||
server: self::CONTENT_TYPE_HEADER,
|
||||
content: json_encode([
|
||||
'email' => 'api@example.com',
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertResponseCode($response, Response::HTTP_ACCEPTED);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_resets_shop_user_password_with_valid_token(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['channel.yaml', 'authentication/shop_user_with_reset_password_token.yaml']);
|
||||
|
||||
$validToken = 'valid_token';
|
||||
|
||||
$this->client->request(
|
||||
method: Request::METHOD_PATCH,
|
||||
uri: sprintf('/api/v2/shop/reset-password/%s', $validToken),
|
||||
server: ContentType::APPLICATION_JSON_MERGE_PATCH,
|
||||
content: json_encode([
|
||||
'newPassword' => 'newPassword',
|
||||
'confirmNewPassword' => 'newPassword',
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertResponseCode($response, Response::HTTP_ACCEPTED);
|
||||
}
|
||||
|
||||
|
||||
/** @test */
|
||||
public function it_prevents_shop_user_from_resetting_password_with_invalid_token(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['channel.yaml', 'authentication/shop_user_with_reset_password_token.yaml']);
|
||||
|
||||
$validToken = 'invalid_token';
|
||||
|
||||
$this->client->request(
|
||||
method: Request::METHOD_PATCH,
|
||||
uri: sprintf('/api/v2/shop/reset-password/%s', $validToken),
|
||||
server: ContentType::APPLICATION_JSON_MERGE_PATCH,
|
||||
content: json_encode([
|
||||
'newPassword' => 'newPassword',
|
||||
'confirmNewPassword' => 'newPassword',
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertResponseCode($response, Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
|
||||
/** @test */
|
||||
public function it_prevents_shop_user_from_resetting_password_with_expired_token(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['channel.yaml', 'authentication/shop_user_with_expired_reset_password_token.yaml']);
|
||||
|
||||
$validToken = 'valid_token';
|
||||
|
||||
$this->client->request(
|
||||
method: Request::METHOD_PATCH,
|
||||
uri: sprintf('/api/v2/shop/reset-password/%s', $validToken),
|
||||
server: ContentType::APPLICATION_JSON_MERGE_PATCH,
|
||||
content: json_encode([
|
||||
'newPassword' => 'newPassword',
|
||||
'confirmNewPassword' => 'newPassword',
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertResponseCode($response, Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue