Skip to content

Commit 1c3a76b

Browse files
committed
MC-22216: Tests for the customerCart Query
- missing use case
1 parent 941caff commit 1c3a76b

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function testGetActiveCustomerCart()
5454
$this->assertNotEmpty($response['customerCart']['items']);
5555
$this->assertEquals(2, $response['customerCart']['total_quantity']);
5656
$this->assertArrayHasKey('id', $response['customerCart']);
57+
$this->assertNotEmpty($response['customerCart']['id']);
5758
$this->assertEquals($maskedQuoteId, $response['customerCart']['id']);
5859
$this->assertEquals(
5960
$quantity,
@@ -62,6 +63,26 @@ public function testGetActiveCustomerCart()
6263
);
6364
}
6465

66+
/**
67+
* Query for an existing customer cart with no masked quote id
68+
*
69+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
70+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
71+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart_without_maskedQuoteId.php
72+
*/
73+
public function testGetLoggedInCustomerCartWithoutMaskedQuoteId()
74+
{
75+
$customerCartQuery = $this->getCustomerCartQuery();
76+
$response = $this->graphQlQuery($customerCartQuery, [], '', $this->getHeaderMap());
77+
$this->assertArrayHasKey('customerCart', $response);
78+
$this->assertArrayHasKey('items', $response['customerCart']);
79+
$this->assertEmpty($response['customerCart']['items']);
80+
$this->assertEquals(0, $response['customerCart']['total_quantity']);
81+
$this->assertArrayHasKey('id', $response['customerCart']);
82+
$this->assertNotEmpty($response['customerCart']['id']);
83+
$this->assertNotNull($response['customerCart']['id']);
84+
}
85+
6586
/**
6687
* Query for customer cart for a user with no existing active cart
6788
*
@@ -76,6 +97,7 @@ public function testGetNewCustomerCart()
7697
$this->assertArrayHasKey('customerCart', $response);
7798
$this->assertArrayHasKey('id', $response['customerCart']);
7899
$this->assertNotNull($response['customerCart']['id']);
100+
$this->assertNotEmpty($response['customerCart']['id']);
79101
$this->assertEmpty($response['customerCart']['items']);
80102
$this->assertEquals(0, $response['customerCart']['total_quantity']);
81103
}
@@ -106,6 +128,7 @@ public function testGetCustomerCartAfterTokenRevoked()
106128
$this->assertArrayHasKey('customerCart', $response);
107129
$this->assertArrayHasKey('id', $response['customerCart']);
108130
$this->assertNotNull($response['customerCart']['id']);
131+
$this->assertNotEmpty($response['customerCart']['id']);
109132
$this->revokeCustomerToken();
110133
$customerCartQuery = $this->getCustomerCartQuery();
111134
$this->expectExceptionMessage(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
use Magento\Quote\Api\CartManagementInterface;
9+
use Magento\Quote\Api\CartRepositoryInterface;
10+
use Magento\Quote\Model\QuoteIdMaskFactory;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
/** @var CartManagementInterface $cartManagement */
14+
$cartManagement = Bootstrap::getObjectManager()->get(CartManagementInterface::class);
15+
/** @var CartRepositoryInterface $cartRepository */
16+
$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class);
17+
/** @var QuoteIdMaskFactory $quoteIdMaskFactory */
18+
$quoteIdMaskFactory = Bootstrap::getObjectManager()->get(QuoteIdMaskFactory::class);
19+
20+
$cartId = $cartManagement->createEmptyCartForCustomer(1);
21+
$cart = $cartRepository->get($cartId);
22+
$cartRepository->save($cart);

0 commit comments

Comments
 (0)