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

Commit 95f2c64

Browse files
committed
Cover GraphQlAuthenticationException "This account isn't confirmed. Verify and try again."
Ignore coverage for functionality that is related to the DB constraint violations. Reformat lines for LiveCodeTest Signed-off-by: Tomash Khamlai <[email protected]>
1 parent 586c9df commit 95f2c64

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

app/code/Magento/CustomerGraphQl/Model/Customer/GetCustomer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ public function execute(ContextInterface $context): CustomerInterface
7070

7171
try {
7272
$customer = $this->customerRepository->getById($currentUserId);
73+
// @codeCoverageIgnoreStart
7374
} catch (NoSuchEntityException $e) {
7475
throw new GraphQlNoSuchEntityException(
7576
__('Customer with id "%customer_id" does not exist.', ['customer_id' => $currentUserId]),
7677
$e
7778
);
7879
} catch (LocalizedException $e) {
7980
throw new GraphQlInputException(__($e->getMessage()));
81+
// @codeCoverageIgnoreEnd
8082
}
8183

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

8688
try {
8789
$confirmationStatus = $this->accountManagement->getConfirmationStatus($currentUserId);
90+
// @codeCoverageIgnoreStart
8891
} catch (LocalizedException $e) {
8992
throw new GraphQlInputException(__($e->getMessage()));
93+
// @codeCoverageIgnoreEnd
9094
}
9195

9296
if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) {

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\GraphQl\Customer;
99

10+
use Magento\Customer\Api\AccountManagementInterface;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
1012
use Magento\Customer\Model\CustomerAuthUpdate;
1113
use Magento\Customer\Model\CustomerRegistry;
1214
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -30,13 +32,25 @@ class GetCustomerTest extends GraphQlAbstract
3032
*/
3133
private $customerAuthUpdate;
3234

35+
/**
36+
* @var AccountManagementInterface
37+
*/
38+
private $accountManagement;
39+
40+
/**
41+
* @var CustomerRepositoryInterface
42+
*/
43+
private $customerRepository;
44+
3345
protected function setUp()
3446
{
3547
parent::setUp();
3648

3749
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
50+
$this->accountManagement = Bootstrap::getObjectManager()->get(AccountManagementInterface::class);
3851
$this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class);
3952
$this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class);
53+
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
4054
}
4155

4256
/**
@@ -57,7 +71,12 @@ public function testGetCustomer()
5771
}
5872
}
5973
QUERY;
60-
$response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
74+
$response = $this->graphQlQuery(
75+
$query,
76+
[],
77+
'',
78+
$this->getCustomerAuthHeaders($currentEmail, $currentPassword)
79+
);
6180

6281
$this->assertEquals(null, $response['customer']['id']);
6382
$this->assertEquals('John', $response['customer']['firstname']);
@@ -104,7 +123,28 @@ public function testGetCustomerIfAccountIsLocked()
104123
}
105124
}
106125
QUERY;
107-
$this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
126+
$this->graphQlQuery(
127+
$query,
128+
[],
129+
'',
130+
$this->getCustomerAuthHeaders($currentEmail, $currentPassword)
131+
);
132+
}
133+
134+
/**
135+
* @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
136+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
137+
* @expectedException \Exception
138+
* @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily
139+
*/
140+
public function testAccountIsNotConfirmed()
141+
{
142+
$confirmation_required = $this->accountManagement::ACCOUNT_CONFIRMATION_REQUIRED;
143+
$customerEmail = '[email protected]';
144+
$currentPassword = 'password';
145+
$customer = $this->customerRepository->getById(1)->setConfirmation($confirmation_required);
146+
$this->customerRepository->save($customer);
147+
$this->getCustomerAuthHeaders($customerEmail, $currentPassword);
108148
}
109149

110150
/**

0 commit comments

Comments
 (0)