Skip to content

Commit b6f0bb3

Browse files
committed
Update functional api test of assignCustomer method to check if cart merged instead of exception in case if customer has active cart.
1 parent d0e2ced commit b6f0bb3

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,21 +310,20 @@ public function testAssignCustomerThrowsExceptionIfCartIsAssignedToDifferentStor
310310
}
311311

312312
/**
313-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
313+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
314314
* @magentoApiDataFixture Magento/Sales/_files/quote.php
315-
* @expectedException \Exception
316315
*/
317-
public function testAssignCustomerThrowsExceptionIfCustomerAlreadyHasActiveCart()
316+
public function testAssignCustomerCartMerged()
318317
{
319318
/** @var $customer \Magento\Customer\Model\Customer */
320319
$customer = $this->objectManager->create(\Magento\Customer\Model\Customer::class)->load(1);
321320
// Customer has a quote with reserved order ID test_order_1 (see fixture)
322321
/** @var $customerQuote \Magento\Quote\Model\Quote */
323322
$customerQuote = $this->objectManager->create(\Magento\Quote\Model\Quote::class)
324-
->load('test_order_1', 'reserved_order_id');
325-
$customerQuote->setIsActive(1)->save();
323+
->load('test_order_item_with_items', 'reserved_order_id');
326324
/** @var $quote \Magento\Quote\Model\Quote */
327325
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class)->load('test01', 'reserved_order_id');
326+
$expectedQuoteItemsQty = $customerQuote->getItemsQty() + $quote->getItemsQty();
328327

329328
$cartId = $quote->getId();
330329
$customerId = $customer->getId();
@@ -346,11 +345,11 @@ public function testAssignCustomerThrowsExceptionIfCustomerAlreadyHasActiveCart(
346345
'customerId' => $customerId,
347346
'storeId' => 1,
348347
];
349-
$this->_webApiCall($serviceInfo, $requestData);
348+
$this->assertTrue($this->_webApiCall( $serviceInfo, $requestData));
350349

351-
$this->expectExceptionMessage(
352-
"The customer can't be assigned to the cart because the customer already has an active cart."
353-
);
350+
$mergedQuote = $this->objectManager->create(\Magento\Quote\Model\Quote::class)->load('test01', 'reserved_order_id');
351+
352+
$this->assertEquals($expectedQuoteItemsQty, $mergedQuote->getItemsQty());
354353
}
355354

356355
/**

dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,20 @@ public function testAssignCustomerThrowsExceptionIfTargetCartIsNotAnonymous()
231231
}
232232

233233
/**
234-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
234+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
235235
* @magentoApiDataFixture Magento/Sales/_files/quote.php
236-
* @expectedException \Exception
237236
*/
238-
public function testAssignCustomerThrowsExceptionIfCustomerAlreadyHasActiveCart()
237+
public function testAssignCustomerCartMerged()
239238
{
240239
/** @var $customer \Magento\Customer\Model\Customer */
241240
$customer = $this->objectManager->create(\Magento\Customer\Model\Customer::class)->load(1);
242241
// Customer has a quote with reserved order ID test_order_1 (see fixture)
243242
/** @var $customerQuote \Magento\Quote\Model\Quote */
244243
$customerQuote = $this->objectManager->create(\Magento\Quote\Model\Quote::class)
245-
->load('test_order_1', 'reserved_order_id');
246-
$customerQuote->setIsActive(1)->save();
244+
->load('test_order_item_with_items', 'reserved_order_id');
247245
/** @var $quote \Magento\Quote\Model\Quote */
248246
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class)->load('test01', 'reserved_order_id');
247+
$expectedQuoteItemsQty = $customerQuote->getItemsQty() + $quote->getItemsQty();
249248

250249
$cartId = $quote->getId();
251250

@@ -284,11 +283,10 @@ public function testAssignCustomerThrowsExceptionIfCustomerAlreadyHasActiveCart(
284283
'customerId' => $customerId,
285284
'storeId' => 1,
286285
];
287-
$this->_webApiCall($serviceInfo, $requestData);
286+
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
287+
$mergedQuote = $this->objectManager->create(\Magento\Quote\Model\Quote::class)->load('test01', 'reserved_order_id');
288288

289-
$this->expectExceptionMessage(
290-
"The customer can't be assigned to the cart because the customer already has an active cart."
291-
);
289+
$this->assertEquals($expectedQuoteItemsQty, $mergedQuote->getItemsQty());
292290
}
293291

294292
/**

0 commit comments

Comments
 (0)