Skip to content

Commit 1e71392

Browse files
committed
MC-22216: Tests for the customerCart Query
- fixed existing tests to include cartId
1 parent 627a617 commit 1e71392

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public function testGetCart()
6565
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
6666

6767
self::assertArrayHasKey('cart', $response);
68+
self::assertArrayHasKey('cart_id', $response['cart']);
69+
self::assertEquals($maskedQuoteId, $response['cart']['cart_id']);
6870
self::assertArrayHasKey('items', $response['cart']);
6971
self::assertCount(2, $response['cart']['items']);
7072

@@ -255,6 +257,7 @@ private function getQuery(string $maskedQuoteId): string
255257
return <<<QUERY
256258
{
257259
cart(cart_id: "{$maskedQuoteId}") {
260+
cart_id
258261
items {
259262
id
260263
quantity

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ class GetCustomerCartTest extends GraphQlAbstract
2828
*/
2929
private $customerTokenService;
3030

31-
/** @var array */
32-
private $headers;
33-
3431
protected function setUp()
3532
{
3633
$objectManager = Bootstrap::getObjectManager();
@@ -74,8 +71,8 @@ public function testGetNewCustomerCart()
7471
{
7572
$customerToken = $this->generateCustomerToken();
7673
$customerCartQuery = $this->getCustomerCartQuery();
77-
$this->headers = ['Authorization' => 'Bearer ' . $customerToken];
78-
$response = $this->graphQlQuery($customerCartQuery, [], '', $this->headers);
74+
$headers = ['Authorization' => 'Bearer ' . $customerToken];
75+
$response = $this->graphQlQuery($customerCartQuery, [], '', $headers);
7976
$this->assertArrayHasKey('customerCart', $response);
8077
$this->assertArrayHasKey('cart_id', $response['customerCart']);
8178
$this->assertNotNull($response['customerCart']['cart_id']);
@@ -103,9 +100,9 @@ public function testGetCustomerCartWithNoCustomerToken()
103100
public function testGetCustomerCartAfterTokenRevoked()
104101
{
105102
$customerToken = $this->generateCustomerToken();
106-
$this->headers = ['Authorization' => 'Bearer ' . $customerToken];
103+
$headers = ['Authorization' => 'Bearer ' . $customerToken];
107104
$customerCartQuery = $this->getCustomerCartQuery();
108-
$response = $this->graphQlMutation($customerCartQuery, [], '', $this->headers);
105+
$response = $this->graphQlMutation($customerCartQuery, [], '', $headers);
109106
$this->assertArrayHasKey('customerCart', $response);
110107
$this->assertArrayHasKey('cart_id', $response['customerCart']);
111108
$this->assertNotNull($response['customerCart']['cart_id']);
@@ -114,7 +111,7 @@ public function testGetCustomerCartAfterTokenRevoked()
114111
$this->expectExceptionMessage(
115112
'The request is allowed for logged in customer'
116113
);
117-
$this->graphQlQuery($customerCartQuery, [], '', $this->headers);
114+
$this->graphQlQuery($customerCartQuery, [], '', $headers);
118115
}
119116

120117
/**
@@ -125,15 +122,15 @@ public function testGetCustomerCartAfterTokenRevoked()
125122
public function testRequestCustomerCartTwice()
126123
{
127124
$customerToken = $this->generateCustomerToken();
128-
$this->headers = ['Authorization' => 'Bearer ' . $customerToken];
125+
$headers = ['Authorization' => 'Bearer ' . $customerToken];
129126
$customerCartQuery = $this->getCustomerCartQuery();
130-
$response = $this->graphQlMutation($customerCartQuery, [], '', $this->headers);
127+
$response = $this->graphQlMutation($customerCartQuery, [], '', $headers);
131128
$this->assertArrayHasKey('customerCart', $response);
132129
$this->assertArrayHasKey('cart_id', $response['customerCart']);
133130
$this->assertNotNull($response['customerCart']['cart_id']);
134131
$cartId = $response['customerCart']['cart_id'];
135132
$customerCartQuery = $this->getCustomerCartQuery();
136-
$response2 = $this->graphQlQuery($customerCartQuery, [], '', $this->headers);
133+
$response2 = $this->graphQlQuery($customerCartQuery, [], '', $headers);
137134
$this->assertEquals($cartId, $response2['customerCart']['cart_id']);
138135
}
139136

@@ -173,6 +170,8 @@ public function testGetCustomerCartSecondStore()
173170
}
174171

175172
/**
173+
* Query to generate customer token
174+
*
176175
* @return string
177176
*/
178177
private function generateCustomerToken(): string
@@ -195,7 +194,12 @@ private function generateCustomerToken(): string
195194
return $response['generateCustomerToken']['token'];
196195
}
197196

198-
private function revokeCustomerToken()
197+
/**
198+
* Query to revoke customer token
199+
*
200+
* @return void
201+
*/
202+
private function revokeCustomerToken(): void
199203
{
200204
$query = <<<QUERY
201205
mutation{
@@ -210,7 +214,8 @@ private function revokeCustomerToken()
210214
}
211215

212216
/**
213-
* @param string $maskedQuoteId
217+
* Query customer cart
218+
*
214219
* @return string
215220
*/
216221
private function getCustomerCartQuery(): string
@@ -233,6 +238,8 @@ private function getCustomerCartQuery(): string
233238
}
234239

235240
/**
241+
* Create a header with customer token
242+
*
236243
* @param string $username
237244
* @param string $password
238245
* @return array

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/AddSimpleProductToCartTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function testAddSimpleProductToCart()
5050
self::assertEquals($quantity, $response['addSimpleProductsToCart']['cart']['items'][0]['quantity']);
5151
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
5252
self::assertArrayHasKey('prices', $response['addSimpleProductsToCart']['cart']['items'][0]);
53+
self::assertArrayHasKey('cart_id', $response['addSimpleProductsToCart']['cart']);
54+
self::assertEquals($maskedQuoteId, $response['addSimpleProductsToCart']['cart']['cart_id']);
5355

5456
self::assertArrayHasKey('price', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']);
5557
$price = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price'];
@@ -254,6 +256,7 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity):
254256
}
255257
) {
256258
cart {
259+
cart_id
257260
items {
258261
quantity
259262
product {

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/AddVirtualProductToCartTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public function testAddVirtualProductToCart()
4545
$response = $this->graphQlMutation($query);
4646

4747
self::assertArrayHasKey('cart', $response['addVirtualProductsToCart']);
48+
self::assertArrayHasKey('cart_id', $response['addVirtualProductsToCart']['cart']);
49+
self::assertEquals($maskedQuoteId, $response['addVirtualProductsToCart']['cart']['cart_id']);
4850
self::assertEquals($quantity, $response['addVirtualProductsToCart']['cart']['items'][0]['quantity']);
4951
self::assertEquals($sku, $response['addVirtualProductsToCart']['cart']['items'][0]['product']['sku']);
5052
}
@@ -227,6 +229,7 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity):
227229
}
228230
) {
229231
cart {
232+
cart_id
230233
items {
231234
quantity
232235
product {

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/ApplyCouponToCartTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function testApplyCouponToCart()
4141
$response = $this->graphQlMutation($query);
4242

4343
self::assertArrayHasKey('applyCouponToCart', $response);
44+
self::assertArrayHasKey('cart_id', $response['applyCouponToCart']['cart']);
45+
self::assertEquals($maskedQuoteId, $response['applyCouponToCart']['cart']['cart_id']);
4446
self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupon']['code']);
4547
}
4648

@@ -202,6 +204,7 @@ private function getQuery(string $maskedQuoteId, string $couponCode): string
202204
mutation {
203205
applyCouponToCart(input: {cart_id: "$maskedQuoteId", coupon_code: "$couponCode"}) {
204206
cart {
207+
cart_id
205208
applied_coupon {
206209
code
207210
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function testGetCart()
4444

4545
self::assertArrayHasKey('cart', $response);
4646
self::assertArrayHasKey('items', $response['cart']);
47+
self::assertArrayHasKey('cart_id', $response['cart']);
48+
self::assertEquals($maskedQuoteId, $response['cart']['cart_id']);
4749
self::assertCount(2, $response['cart']['items']);
4850

4951
self::assertNotEmpty($response['cart']['items'][0]['id']);
@@ -184,6 +186,7 @@ private function getQuery(string $maskedQuoteId): string
184186
return <<<QUERY
185187
{
186188
cart(cart_id: "{$maskedQuoteId}") {
189+
cart_id
187190
items {
188191
id
189192
quantity

0 commit comments

Comments
 (0)