Skip to content

Commit 2ec29ed

Browse files
committed
ACP2E-3255: [GRAPHQL] model value should be specified when getting customerCart
- Added the test coverage.
1 parent 0869449 commit 2ec29ed

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Quote\Customer;
9+
10+
use Exception;
11+
use Magento\Customer\Test\Fixture\Customer;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\ObjectManagerInterface;
14+
use Magento\Integration\Api\CustomerTokenServiceInterface;
15+
use Magento\Framework\Exception\AuthenticationException;
16+
use Magento\Quote\Model\Quote;
17+
use Magento\Quote\Model\ResourceModel\Quote\Collection;
18+
use Magento\TestFramework\Fixture\Config as ConfigFixture;
19+
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
20+
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
21+
use Magento\Store\Test\Fixture\Store as StoreFixture;
22+
use Magento\Store\Model\ScopeInterface;
23+
use Magento\TestFramework\Fixture\DataFixture;
24+
use Magento\TestFramework\Fixture\DataFixtureStorage;
25+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
26+
use Magento\TestFramework\Helper\Bootstrap;
27+
use Magento\TestFramework\TestCase\GraphQlAbstract;
28+
29+
/**
30+
* Test for create customer cart
31+
*/
32+
class CreateCustomerCart extends GraphQlAbstract
33+
{
34+
/**
35+
* @var ObjectManagerInterface
36+
*/
37+
private ObjectManagerInterface $objectManager;
38+
39+
/**
40+
* @var DataFixtureStorage
41+
*/
42+
private DataFixtureStorage $fixtures;
43+
44+
/**
45+
* @var CustomerTokenServiceInterface
46+
*/
47+
private CustomerTokenServiceInterface $customerTokenService;
48+
49+
/**
50+
* @inheritdoc
51+
* @throws LocalizedException
52+
*/
53+
protected function setUp(): void
54+
{
55+
$this->objectManager = Bootstrap::getObjectManager();
56+
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
57+
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
58+
}
59+
60+
/**
61+
* @inheritdoc
62+
*/
63+
protected function tearDown(): void
64+
{
65+
/** @var Quote $quote */
66+
$quoteCollection = $this->objectManager->create(Collection::class);
67+
foreach ($quoteCollection as $quote) {
68+
$quote->delete();
69+
}
70+
parent::tearDown();
71+
}
72+
73+
/**
74+
* Test to create empty cart for customer with billing and shipping address
75+
*
76+
* @return void
77+
* @throws AuthenticationException
78+
* @throws Exception
79+
*/
80+
#[
81+
ConfigFixture('customer/account_share/scope', 0),
82+
DataFixture(WebsiteFixture::class, ['code' => 'website2'], as: 'website2'),
83+
DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'group2'),
84+
DataFixture(StoreFixture::class, ['website_id' => '$website2.id$'], 'store2'),
85+
ConfigFixture('general/country/allow', 'US', ScopeInterface::SCOPE_WEBSITE, 'base'),
86+
ConfigFixture('general/country/allow', 'NL', ScopeInterface::SCOPE_WEBSITE, 'website2'),
87+
DataFixture(
88+
Customer::class,
89+
[
90+
'email' => 'john@doe.com',
91+
'password' => 'test@123',
92+
'addresses' => [
93+
[
94+
'country_id' => 'US',
95+
'region_id' => 32,
96+
'city' => 'Boston',
97+
'street' => ['10 Milk Street'],
98+
'postcode' => '02108',
99+
'telephone' => '1234567890',
100+
'default_billing' => true,
101+
'default_shipping' => true,
102+
],
103+
],
104+
],
105+
'customer'
106+
),
107+
]
108+
public function testToCreateEmptyCartForCustomerWithDefaultAddress()
109+
{
110+
$store = $this->fixtures->get('store2');
111+
$customerCartQuery = $this->getCustomerCartQuery();
112+
$headerMap = $this->getHeaderMap();
113+
$headerMap['Store'] = $store->getCode();
114+
$response = $this->graphQlMutation($customerCartQuery, [], '', $headerMap);
115+
self::assertArrayHasKey('customerCart', $response);
116+
self::assertArrayHasKey('id', $response['customerCart']);
117+
self::assertNotEmpty($response['customerCart']['id']);
118+
}
119+
120+
/**
121+
* Query customer cart
122+
*
123+
* @return string
124+
*/
125+
private function getCustomerCartQuery(): string
126+
{
127+
return <<<QUERY
128+
{
129+
customerCart {
130+
id
131+
}
132+
}
133+
QUERY;
134+
}
135+
136+
/**
137+
* Get Authentication header
138+
*
139+
* @return array
140+
* @throws AuthenticationException
141+
*/
142+
private function getHeaderMap(): array
143+
{
144+
$customerToken = $this->customerTokenService->createCustomerAccessToken('john@doe.com', 'test@123');
145+
return ['Authorization' => 'Bearer ' . $customerToken];
146+
}
147+
}

0 commit comments

Comments
 (0)