Skip to content

Commit 8c34f6c

Browse files
committed
GraphQL-605: [Test coverage] Add simple product to cart
1 parent 8afaf80 commit 8c34f6c

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

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

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

31+
protected function setUp()
32+
{
33+
$objectManager = Bootstrap::getObjectManager();
34+
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
35+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
36+
}
37+
3138
/**
3239
* @magentoApiDataFixture Magento/Customer/_files/customer.php
3340
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
@@ -49,40 +56,39 @@ public function testAddSimpleProductToCart()
4956
/**
5057
* @magentoApiDataFixture Magento/Customer/_files/customer.php
5158
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
59+
*
60+
* @expectedException \Exception
61+
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
5262
*/
5363
public function testAddProductToNonExistentCart()
5464
{
5565
$sku = 'simple_product';
5666
$qty = 2;
5767
$maskedQuoteId = 'non_existent_masked_id';
58-
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
59-
60-
$this->expectExceptionMessage(
61-
"Could not find a cart with ID \"$maskedQuoteId\""
62-
);
6368

69+
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
6470
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
6571
}
6672

6773
/**
6874
* @magentoApiDataFixture Magento/Customer/_files/customer.php
6975
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
76+
*
77+
* @expectedException \Exception
78+
* @expectedExceptionMessage Could not find a product with SKU "simple_product"
7079
*/
7180
public function testNonExistentProductToCart()
7281
{
7382
$sku = 'simple_product';
7483
$qty = 2;
7584
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
76-
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
77-
78-
$this->expectExceptionMessage(
79-
"Could not find a product with SKU \"simple_product\""
80-
);
8185

86+
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
8287
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
8388
}
8489

8590
/**
91+
* _security
8692
* @magentoApiDataFixture Magento/Customer/_files/customer.php
8793
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
8894
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
@@ -102,9 +108,10 @@ public function testAddSimpleProductToGuestCart()
102108
}
103109

104110
/**
111+
* _security
105112
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
106113
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
107-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
114+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
108115
*/
109116
public function testAddSimpleProductToAnotherCustomerCart()
110117
{
@@ -120,15 +127,10 @@ public function testAddSimpleProductToAnotherCustomerCart()
120127
$this->graphQlMutation($query, [], '', $this->getHeaderMap('customer2@search.example.com'));
121128
}
122129

123-
protected function setUp()
124-
{
125-
$objectManager = Bootstrap::getObjectManager();
126-
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
127-
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
128-
}
129-
130130
/**
131131
* @param string $maskedQuoteId
132+
* @param string $sku
133+
* @param int $qty
132134
* @return string
133135
*/
134136
private function getQuery(string $maskedQuoteId, string $sku, int $qty): string
@@ -140,8 +142,8 @@ private function getQuery(string $maskedQuoteId, string $sku, int $qty): string
140142
cartItems: [
141143
{
142144
data: {
143-
qty: $qty
144-
sku: "$sku"
145+
qty: {$qty}
146+
sku: "{$sku}"
145147
}
146148
}
147149
]

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,17 @@ public function testAddProductToNonExistentCart()
6666

6767
/**
6868
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
69+
*
70+
* @expectedException \Exception
71+
* @expectedExceptionMessage Could not find a product with SKU "simple_product"
6972
*/
7073
public function testNonExistentProductToCart()
7174
{
7275
$sku = 'simple_product';
7376
$qty = 1;
7477
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
75-
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
76-
77-
$this->expectExceptionMessage(
78-
"Could not find a product with SKU \"simple_product\""
79-
);
8078

79+
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
8180
$this->graphQlMutation($query);
8281
}
8382

0 commit comments

Comments
 (0)