Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
Cover GraphQlAuthenticationException "This account isn't confirmed. V…
Browse files Browse the repository at this point in the history
…erify and try again."

Ignore coverage for functionality that is related to the DB constraint violations.
Reformat lines for LiveCodeTest

Signed-off-by: Tomash Khamlai <tomash.khamlai@gmail.com>
  • Loading branch information
TomashKhamlai committed Oct 8, 2019
1 parent 586c9df commit 95f2c64
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ public function execute(ContextInterface $context): CustomerInterface

try {
$customer = $this->customerRepository->getById($currentUserId);
// @codeCoverageIgnoreStart
} catch (NoSuchEntityException $e) {
throw new GraphQlNoSuchEntityException(
__('Customer with id "%customer_id" does not exist.', ['customer_id' => $currentUserId]),
$e
);
} catch (LocalizedException $e) {
throw new GraphQlInputException(__($e->getMessage()));
// @codeCoverageIgnoreEnd
}

if (true === $this->authentication->isLocked($currentUserId)) {
Expand All @@ -85,8 +87,10 @@ public function execute(ContextInterface $context): CustomerInterface

try {
$confirmationStatus = $this->accountManagement->getConfirmationStatus($currentUserId);
// @codeCoverageIgnoreStart
} catch (LocalizedException $e) {
throw new GraphQlInputException(__($e->getMessage()));
// @codeCoverageIgnoreEnd
}

if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Magento\GraphQl\Customer;

use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\CustomerAuthUpdate;
use Magento\Customer\Model\CustomerRegistry;
use Magento\Integration\Api\CustomerTokenServiceInterface;
Expand All @@ -30,13 +32,25 @@ class GetCustomerTest extends GraphQlAbstract
*/
private $customerAuthUpdate;

/**
* @var AccountManagementInterface
*/
private $accountManagement;

/**
* @var CustomerRepositoryInterface
*/
private $customerRepository;

protected function setUp()
{
parent::setUp();

$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
$this->accountManagement = Bootstrap::getObjectManager()->get(AccountManagementInterface::class);
$this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class);
$this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class);
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
}

/**
Expand All @@ -57,7 +71,12 @@ public function testGetCustomer()
}
}
QUERY;
$response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
$response = $this->graphQlQuery(
$query,
[],
'',
$this->getCustomerAuthHeaders($currentEmail, $currentPassword)
);

$this->assertEquals(null, $response['customer']['id']);
$this->assertEquals('John', $response['customer']['firstname']);
Expand Down Expand Up @@ -104,7 +123,28 @@ public function testGetCustomerIfAccountIsLocked()
}
}
QUERY;
$this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
$this->graphQlQuery(
$query,
[],
'',
$this->getCustomerAuthHeaders($currentEmail, $currentPassword)
);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException \Exception
* @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily
*/
public function testAccountIsNotConfirmed()
{
$confirmation_required = $this->accountManagement::ACCOUNT_CONFIRMATION_REQUIRED;
$customerEmail = 'customer@example.com';
$currentPassword = 'password';
$customer = $this->customerRepository->getById(1)->setConfirmation($confirmation_required);
$this->customerRepository->save($customer);
$this->getCustomerAuthHeaders($customerEmail, $currentPassword);
}

/**
Expand Down

0 comments on commit 95f2c64

Please sign in to comment.