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

Test coverage for exceptions in \Magento\CustomerGraphQl\Model\Customer\GetCustomer #994

Merged
merged 4 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed


/**
* @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