This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Customer): adjust customer password change request to API ch…
…anges BREAKING CHANGE: Before: ``` CustomerPasswordResetRequest::ofIdVersionTokenAndPassword($id, $version, $token, $newPassword) ``` After: ``` CustomerPasswordResetRequest::ofTokenAndPassword($token, $newPassword) ```
- Loading branch information
Jens Schulze
committed
Mar 23, 2016
1 parent
1b0b930
commit 318e93f
Showing
6 changed files
with
167 additions
and
29 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
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
146 changes: 146 additions & 0 deletions
146
tests/integration/Customer/CustomerLoginRequestTest.php
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,146 @@ | ||
<?php | ||
/** | ||
* @author @jayS-de <jens.schulze@commercetools.de> | ||
*/ | ||
|
||
|
||
namespace Commercetools\Core\Customer; | ||
|
||
use Commercetools\Core\ApiTestCase; | ||
use Commercetools\Core\Model\Customer\CustomerDraft; | ||
use Commercetools\Core\Request\Customers\CustomerByTokenGetRequest; | ||
use Commercetools\Core\Request\Customers\CustomerCreateRequest; | ||
use Commercetools\Core\Request\Customers\CustomerDeleteRequest; | ||
use Commercetools\Core\Request\Customers\CustomerLoginRequest; | ||
use Commercetools\Core\Request\Customers\CustomerPasswordChangeRequest; | ||
use Commercetools\Core\Request\Customers\CustomerPasswordResetRequest; | ||
use Commercetools\Core\Request\Customers\CustomerPasswordTokenRequest; | ||
|
||
class CustomerLoginRequestTest extends ApiTestCase | ||
{ | ||
/** | ||
* @return CustomerDraft | ||
*/ | ||
protected function getDraft($name) | ||
{ | ||
$draft = CustomerDraft::ofEmailNameAndPassword( | ||
'test-' . $this->getTestRun() . '-email', | ||
'test-' . $this->getTestRun() . '-' . $name, | ||
'test-' . $this->getTestRun() . '-lastName', | ||
'test-' . $this->getTestRun() . '-password' | ||
); | ||
|
||
return $draft; | ||
} | ||
|
||
protected function createCustomer(CustomerDraft $draft) | ||
{ | ||
$request = CustomerCreateRequest::ofDraft($draft); | ||
$response = $request->executeWithClient($this->getClient()); | ||
$result = $request->mapResponse($response); | ||
|
||
$this->cleanupRequests[] = $this->deleteRequest = CustomerDeleteRequest::ofIdAndVersion( | ||
$result->getCustomer()->getId(), | ||
$result->getCustomer()->getVersion() | ||
); | ||
return $result->getCustomer(); | ||
} | ||
|
||
public function testLoginSuccess() | ||
{ | ||
$draft = $this->getDraft('email'); | ||
$customer = $this->createCustomer($draft); | ||
|
||
$request = CustomerLoginRequest::ofEmailAndPassword($customer->getEmail(), $draft->getPassword()); | ||
$response = $request->executeWithClient($this->getClient()); | ||
$result = $request->mapResponse($response); | ||
|
||
$this->assertSame($customer->getId(), $result->getCustomer()->getId()); | ||
} | ||
|
||
public function testLoginFailure() | ||
{ | ||
$draft = $this->getDraft('email'); | ||
$customer = $this->createCustomer($draft); | ||
|
||
$request = CustomerLoginRequest::ofEmailAndPassword($customer->getEmail(), $this->getTestRun()); | ||
$response = $request->executeWithClient($this->getClient()); | ||
|
||
$this->assertTrue($response->isError()); | ||
} | ||
|
||
public function testChangePasswordSuccess() | ||
{ | ||
$draft = $this->getDraft('email'); | ||
$customer = $this->createCustomer($draft); | ||
|
||
$request = CustomerPasswordChangeRequest::ofIdVersionAndPasswords( | ||
$customer->getId(), | ||
$customer->getVersion(), | ||
$draft->getPassword(), | ||
$this->getTestRun() | ||
); | ||
$response = $request->executeWithClient($this->getClient()); | ||
$result = $request->mapResponse($response); | ||
$this->deleteRequest->setVersion($result->getVersion()); | ||
|
||
$this->assertSame($customer->getId(), $result->getId()); | ||
} | ||
|
||
public function testChangePasswordFailure() | ||
{ | ||
$draft = $this->getDraft('email'); | ||
$customer = $this->createCustomer($draft); | ||
|
||
$request = CustomerPasswordChangeRequest::ofIdVersionAndPasswords( | ||
$customer->getId(), | ||
$customer->getVersion(), | ||
$this->getTestRun(), | ||
$draft->getPassword() | ||
); | ||
$response = $request->executeWithClient($this->getClient()); | ||
$this->assertTrue($response->isError()); | ||
} | ||
|
||
public function testPasswordReset() | ||
{ | ||
$draft = $this->getDraft('email'); | ||
$customer = $this->createCustomer($draft); | ||
|
||
$request = CustomerPasswordTokenRequest::ofEmail( | ||
$customer->getEmail() | ||
); | ||
$response = $request->executeWithClient($this->getClient()); | ||
$result = $request->mapResponse($response); | ||
|
||
$token = $result->getValue(); | ||
$this->assertNotEmpty($token); | ||
|
||
$request = CustomerByTokenGetRequest::ofToken( | ||
$token | ||
); | ||
$response = $request->executeWithClient($this->getClient()); | ||
$result = $request->mapResponse($response); | ||
$this->assertSame($customer->getId(), $result->getId()); | ||
|
||
$request = CustomerPasswordResetRequest::ofTokenAndPassword( | ||
$token, | ||
$this->getTestRun() | ||
); | ||
$response = $request->executeWithClient($this->getClient()); | ||
$result = $request->mapResponse($response); | ||
$this->deleteRequest->setVersion($result->getVersion()); | ||
|
||
$this->assertSame($customer->getId(), $result->getId()); | ||
|
||
$request = CustomerLoginRequest::ofEmailAndPassword($customer->getEmail(), $this->getTestRun()); | ||
$response = $request->executeWithClient($this->getClient()); | ||
$result = $request->mapResponse($response); | ||
|
||
$this->assertSame($customer->getId(), $result->getCustomer()->getId()); | ||
|
||
$request = CustomerLoginRequest::ofEmailAndPassword($customer->getEmail(), $draft->getPassword()); | ||
$response = $request->executeWithClient($this->getClient()); | ||
$this->assertTrue($response->isError()); | ||
} | ||
} |
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