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 2 commits
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
TomashKhamlai marked this conversation as resolved.
Show resolved Hide resolved
}

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);
lenaorobei marked this conversation as resolved.
Show resolved Hide resolved
$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,43 @@ 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 This account isn't confirmed. Verify and try again.
*/
public function testAccountIsNotConfirmed()
{
$confirmation_required = $this->accountManagement::ACCOUNT_CONFIRMATION_REQUIRED;
lenaorobei marked this conversation as resolved.
Show resolved Hide resolved
$customerEmail = 'customer@example.com';
$currentPassword = 'password';
$headersMap = $this->getCustomerAuthHeaders($customerEmail, $currentPassword);
$customer = $this->customerRepository->getById(1)->setConfirmation($confirmation_required);
lenaorobei marked this conversation as resolved.
Show resolved Hide resolved
$this->customerRepository->save($customer);
$query = <<<QUERY
query {
customer {
firstname
lastname
email
}
}
QUERY;
$this->graphQlQuery(
$query,
[],
'',
$headersMap
);
}

/**
Expand Down