Skip to content

Commit eb5edd0

Browse files
33383 GraphQL: test coverage
1 parent 777725e commit eb5edd0

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Customer;
9+
10+
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Framework\Exception\AuthenticationException;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\TestCase\GraphQlAbstract;
14+
use Magento\Integration\Api\CustomerTokenServiceInterface;
15+
16+
/**
17+
* Delete custom tests
18+
*/
19+
class DeleteCustomerTest extends GraphQlAbstract
20+
{
21+
/**
22+
* @var CustomerTokenServiceInterface
23+
*/
24+
private $customerTokenService;
25+
26+
/**
27+
* @var CustomerRepositoryInterface
28+
*/
29+
private $customerRepository;
30+
31+
/**
32+
* @var LockCustomer
33+
*/
34+
private $lockCustomer;
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
protected function setUp(): void
40+
{
41+
parent::setUp();
42+
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
43+
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
44+
$this->lockCustomer = Bootstrap::getObjectManager()->get(LockCustomer::class);
45+
}
46+
47+
/**
48+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
49+
*/
50+
public function testDeleteCustomer()
51+
{
52+
$response = $this->graphQlMutation($this->getMutation(), [], '', $this->getHeaderMap());
53+
$this->assertArrayHasKey('deleteCustomer', $response);
54+
$this->assertTrue($response['deleteCustomer']);
55+
}
56+
57+
/**
58+
*/
59+
public function testDeleteCustomerIfUserIsNotAuthorized()
60+
{
61+
$this->expectException(\Exception::class);
62+
$this->expectExceptionMessage('The current customer isn\'t authorized.');
63+
$this->graphQlMutation($this->getMutation());
64+
}
65+
66+
/**
67+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
68+
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
69+
*/
70+
public function testDeleteCustomerIfAccountIsLocked()
71+
{
72+
$this->lockCustomer->execute(1);
73+
$response = $this->graphQlMutation($this->getMutation(), [], '', $this->getHeaderMap());
74+
$this->assertArrayHasKey('deleteCustomer', $response);
75+
$this->assertTrue($response['deleteCustomer']);
76+
}
77+
78+
/**
79+
* Retrieve deleteCustomer mutation
80+
*
81+
* @return string
82+
*/
83+
private function getMutation()
84+
{
85+
return <<<MUTATION
86+
mutation {
87+
deleteCustomer
88+
}
89+
MUTATION;
90+
}
91+
92+
/**
93+
* Retrieve customer authorization headers
94+
*
95+
* @param string $username
96+
* @param string $password
97+
* @return array
98+
* @throws AuthenticationException
99+
*/
100+
private function getHeaderMap(string $username = 'customer@example.com', string $password = 'password'): array
101+
{
102+
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password);
103+
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
104+
return $headerMap;
105+
}
106+
}

0 commit comments

Comments
 (0)