Skip to content

Commit 8aadac8

Browse files
committed
MC-37399: Product Compare :: Atwix PR review and delivery
- add test coverage
1 parent e90810a commit 8aadac8

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/CompareList/CompareListTest.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Integration\Api\CustomerTokenServiceInterface;
1212
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
1314
use Magento\TestFramework\TestCase\GraphQlAbstract;
1415

1516
/**
@@ -83,11 +84,30 @@ public function testAddProductToCompareList()
8384
{
8485
$compareList = $this->createCompareList();
8586
$uid = $compareList['createCompareList']['uid'];
87+
$this->assertEquals(0, $compareList['createCompareList']['item_count'],'Incorrect count');
8688
$this->uidAssertion($uid);
8789
$response = $this->addProductsToCompareList($uid);
8890
$resultUid = $response['addProductsToCompareList']['uid'];
8991
$this->uidAssertion($resultUid);
9092
$this->itemsAssertion($response['addProductsToCompareList']['items']);
93+
$this->assertEquals(2, $response['addProductsToCompareList']['item_count'],'Incorrect count');
94+
$this->assertResponseFields(
95+
$response['addProductsToCompareList']['attributes'],
96+
[
97+
[
98+
'code'=> 'sku',
99+
'label'=> 'SKU'
100+
],
101+
[
102+
'code'=> 'description',
103+
'label'=> 'Description'
104+
],
105+
[
106+
'code'=> 'short_description',
107+
'label'=> 'Short Description'
108+
]
109+
]
110+
);
91111
}
92112

93113
/**
@@ -246,6 +266,61 @@ public function testAssignCompareListToCustomer()
246266
$this->itemsAssertion($customerAssignedResponse['customer']['compare_list']['items']);
247267
}
248268

269+
/**
270+
* Assign compare list of one customer to another customer
271+
*
272+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
273+
* @magentoApiDataFixture Magento/Customer/_files/two_customers.php
274+
*/
275+
public function testCompareListsNotAccessibleBetweenCustomers()
276+
{
277+
$uidCustomer1 = $this->createCompareListForCustomer('[email protected]', 'password');
278+
$uidcustomer2 = $this->createCompareListForCustomer('[email protected]', 'password');
279+
$assignCompareListToCustomer = <<<MUTATION
280+
mutation {
281+
assignCompareListToCustomer(uid: "{$uidCustomer1}"){
282+
result
283+
compare_list {
284+
uid
285+
items {
286+
uid
287+
}
288+
}
289+
}
290+
}
291+
MUTATION;
292+
293+
$expectedExceptionsMessage = 'GraphQL response contains errors: This customer is not authorized to access this list';
294+
$this->expectException(ResponseContainsErrorsException::class);
295+
$this->expectExceptionMessage($expectedExceptionsMessage);
296+
//customer2 not allowed to assign compareList belonging to customer1
297+
$this->graphQlMutation(
298+
$assignCompareListToCustomer,
299+
[],
300+
'',
301+
$this->getCustomerAuthHeaders('[email protected]', 'password')
302+
);
303+
304+
$deleteCompareList = <<<MUTATION
305+
mutation{
306+
deleteCompareList(uid:"{$uidcustomer2}") {
307+
result
308+
}
309+
}
310+
MUTATION;
311+
$expectedExceptionsMessage = 'GraphQL response contains errors: This customer is not authorized to access this list';
312+
$this->expectException(ResponseContainsErrorsException::class);
313+
$this->expectExceptionMessage($expectedExceptionsMessage);
314+
//customer1 not allowed to delete compareList belonging to customer2
315+
$this->graphQlMutation(
316+
$assignCompareListToCustomer,
317+
[],
318+
'',
319+
$this->getCustomerAuthHeaders('[email protected]', 'password')
320+
);
321+
322+
}
323+
249324
/**
250325
* Get customer Header
251326
*
@@ -271,12 +346,33 @@ private function createCompareList(): array
271346
mutation{
272347
createCompareList {
273348
uid
349+
item_count
350+
attributes{code label}
274351
}
275352
}
276353
MUTATION;
277354
return $this->graphQlMutation($mutation);
278355
}
279356

357+
private function createCompareListForCustomer(string $username, string $password): string
358+
{
359+
$compareListCustomer = <<<MUTATION
360+
mutation{
361+
createCompareList {
362+
uid
363+
}
364+
}
365+
MUTATION;
366+
$response = $this->graphQlMutation(
367+
$compareListCustomer,
368+
[],
369+
'',
370+
$this->getCustomerAuthHeaders($username, $password)
371+
);
372+
373+
return $response['createCompareList']['uid'];
374+
}
375+
280376
/**
281377
* Add products to compare list
282378
*
@@ -292,6 +388,8 @@ private function addProductsToCompareList($uid): array
292388
mutation{
293389
addProductsToCompareList(input: { uid: "{$uid}", products: [{$product1->getId()}, {$product2->getId()}]}) {
294390
uid
391+
item_count
392+
attributes{code label}
295393
items {
296394
product {
297395
sku

0 commit comments

Comments
 (0)