Skip to content

Commit 9be928c

Browse files
committed
API-functional tests for wrong SKU and wrong quantity
1 parent 1521ac2 commit 9be928c

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

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

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,87 @@ public function testAddSimpleProductWithOptions()
9898
}
9999

100100
/**
101+
* @param string $sku
102+
* @param string $message
103+
*
104+
* @dataProvider wrongSkuDataProvider
105+
*
101106
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
102-
* @group wip
103107
*/
104-
public function testAddProductWithWrongSku()
108+
public function testAddProductWithWrongSku(string $sku, string $message)
105109
{
106110
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
107-
$sku = 'non-existent';
108111

109112
$query = $this->getQuery($maskedQuoteId, 1, $sku, '');
110113
$response = $this->graphQlMutation($query);
111114

112115
self::assertArrayHasKey('userInputErrors', $response['addProductsToCart']);
113116
self::assertCount(1, $response['addProductsToCart']['userInputErrors']);
114117
self::assertEquals(
115-
'Could not find a product with SKU "' . $sku .'"',
118+
$message,
119+
$response['addProductsToCart']['userInputErrors'][0]['message']
120+
);
121+
}
122+
123+
/**
124+
* @param int $quantity
125+
* @param string $message
126+
*
127+
* @dataProvider wrongQuantityDataProvider
128+
*
129+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_without_custom_options.php
130+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
131+
*/
132+
public function testAddProductWithWrongQuantity(int $quantity, string $message)
133+
{
134+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
135+
$sku = 'simple-2';
136+
137+
$query = $this->getQuery($maskedQuoteId, $quantity, $sku, '');
138+
$response = $this->graphQlMutation($query);
139+
self::assertArrayHasKey('userInputErrors', $response['addProductsToCart']);
140+
self::assertCount(1, $response['addProductsToCart']['userInputErrors']);
141+
142+
self::assertEquals(
143+
$message,
116144
$response['addProductsToCart']['userInputErrors'][0]['message']
117145
);
118146
}
119147

148+
/**
149+
* @return array
150+
*/
151+
public function wrongSkuDataProvider(): array
152+
{
153+
return [
154+
'Non-existent SKU' => [
155+
'non-existent',
156+
'Could not find a product with SKU "non-existent"'
157+
],
158+
'Empty SKU' => [
159+
'',
160+
'Could not find a product with SKU ""'
161+
]
162+
];
163+
}
164+
165+
/**
166+
* @return array
167+
*/
168+
public function wrongQuantityDataProvider(): array
169+
{
170+
return [
171+
'More quantity than in stock' => [
172+
101,
173+
'The requested qty is not available'
174+
],
175+
'Quantity equals zero' => [
176+
0,
177+
'The product quantity should be greater than 0'
178+
]
179+
];
180+
}
181+
120182
/**
121183
* Returns GraphQl query string
122184
*

0 commit comments

Comments
 (0)