10
10
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
11
use Magento \Integration \Api \CustomerTokenServiceInterface ;
12
12
use Magento \TestFramework \Helper \Bootstrap ;
13
+ use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
13
14
use Magento \TestFramework \TestCase \GraphQlAbstract ;
14
15
15
16
/**
@@ -83,11 +84,30 @@ public function testAddProductToCompareList()
83
84
{
84
85
$ compareList = $ this ->createCompareList ();
85
86
$ uid = $ compareList ['createCompareList ' ]['uid ' ];
87
+ $ this ->assertEquals (0 , $ compareList ['createCompareList ' ]['item_count ' ],'Incorrect count ' );
86
88
$ this ->uidAssertion ($ uid );
87
89
$ response = $ this ->addProductsToCompareList ($ uid );
88
90
$ resultUid = $ response ['addProductsToCompareList ' ]['uid ' ];
89
91
$ this ->uidAssertion ($ resultUid );
90
92
$ 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
+ );
91
111
}
92
112
93
113
/**
@@ -246,6 +266,61 @@ public function testAssignCompareListToCustomer()
246
266
$ this ->itemsAssertion ($ customerAssignedResponse ['customer ' ]['compare_list ' ]['items ' ]);
247
267
}
248
268
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
+
249
324
/**
250
325
* Get customer Header
251
326
*
@@ -271,12 +346,33 @@ private function createCompareList(): array
271
346
mutation{
272
347
createCompareList {
273
348
uid
349
+ item_count
350
+ attributes{code label}
274
351
}
275
352
}
276
353
MUTATION ;
277
354
return $ this ->graphQlMutation ($ mutation );
278
355
}
279
356
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
+
280
376
/**
281
377
* Add products to compare list
282
378
*
@@ -292,6 +388,8 @@ private function addProductsToCompareList($uid): array
292
388
mutation{
293
389
addProductsToCompareList(input: { uid: " {$ uid }", products: [ {$ product1 ->getId ()}, {$ product2 ->getId ()}]}) {
294
390
uid
391
+ item_count
392
+ attributes{code label}
295
393
items {
296
394
product {
297
395
sku
0 commit comments