Skip to content

Commit b39f0d8

Browse files
committed
MC-20639: MyAccount :: Order Details :: Refund (creditMemo) Details by Order Number
- additional test for tax and discount
1 parent f32984d commit b39f0d8

File tree

1 file changed

+129
-1
lines changed

1 file changed

+129
-1
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/CreditmemoTest.php

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function testCreditMemoForLoggedInCustomerQuery(): void
122122
'total_shipping' => [
123123
'value' => 0
124124
],
125+
'total_tax' => [],
125126
'shipping_handling' => [
126127
'amount_including_tax' => [
127128
'value' => 0
@@ -167,6 +168,7 @@ public function testCreditMemoForBundledProductsWithPartialRefund()
167168
$this->setPaymentMethod($cartId, $paymentMethod);
168169
$orderNumber = $this->placeOrder($cartId);
169170
$this->prepareInvoice($orderNumber, 2);
171+
// Create a credit memo
170172
$order = $this->order->loadByIncrementId($orderNumber);
171173
/** @var Order\Item $orderItem */
172174
$orderItem = current($order->getAllItems());
@@ -188,7 +190,6 @@ public function testCreditMemoForBundledProductsWithPartialRefund()
188190

189191
$this->creditMemoService->refund($creditMemo, true);
190192
$response = $this->getCustomerOrderWithCreditMemoQuery();
191-
$i = 0;
192193
$expectedCreditMemoData = [
193194
[
194195
'comments' => [
@@ -218,6 +219,7 @@ public function testCreditMemoForBundledProductsWithPartialRefund()
218219
'total_shipping' => [
219220
'value' => 10
220221
],
222+
'total_tax' => [],
221223
'shipping_handling' => [
222224
'amount_including_tax' => [
223225
'value' => 10
@@ -251,6 +253,129 @@ public function testCreditMemoForBundledProductsWithPartialRefund()
251253
}
252254
}
253255

256+
/**
257+
* Test customer order with credit memo details for bundle products with taxes and discounts
258+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
259+
* @magentoApiDataFixture Magento/Bundle/_files/bundle_product_two_dropdown_options.php
260+
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
261+
* @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off_with_discount_on_shipping.php
262+
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_calculation_shipping_excludeTax_order_display_settings.php
263+
*/
264+
public function testCreditMemoForBundleProductWithTaxesAndDiscounts()
265+
{
266+
$quantity = 2;
267+
$bundleSku = 'bundle-product-two-dropdown-options';
268+
$optionsAndSelectionData = $this->getBundleOptionAndSelectionData($bundleSku);
269+
270+
$cartId = $this->createEmptyCart();
271+
$this->addBundleProductQuery($cartId, $quantity, $bundleSku, $optionsAndSelectionData);
272+
$this->setBillingAddress($cartId);
273+
$shippingMethod = $this->setShippingAddress($cartId);
274+
$paymentMethod = $this->setShippingMethod($cartId, $shippingMethod);
275+
$this->setPaymentMethod($cartId, $paymentMethod);
276+
$orderNumber = $this->placeOrder($cartId);
277+
$this->prepareInvoice($orderNumber, 2);
278+
279+
$order = $this->order->loadByIncrementId($orderNumber);
280+
/** @var Order\Item $orderItem */
281+
$orderItem = current($order->getAllItems());
282+
$orderItem->setQtyRefunded(1);
283+
$order->addItem($orderItem);
284+
$order->save();
285+
286+
$creditMemo = $this->creditMemoFactory->createByOrder($order, $order->getData());
287+
$creditMemo->setOrder($order);
288+
$creditMemo->setState(1);
289+
$creditMemo->setSubtotal(15);
290+
$creditMemo->setBaseSubTotal(15);
291+
$creditMemo->setShippingAmount(10);
292+
$creditMemo->setTaxAmount(1.69);
293+
$creditMemo->setBaseGrandTotal(24.19);
294+
$creditMemo->setGrandTotal(24.19);
295+
$creditMemo->setAdjustment(0.00);
296+
$creditMemo->setDiscountAmount(-2.5);
297+
$creditMemo->setDiscountDescription('Discount Label for 10% off');
298+
$creditMemo->addComment("Test comment for refund with taxes and discount", false, true);
299+
$creditMemo->save();
300+
301+
$this->creditMemoService->refund($creditMemo, true);
302+
//$this->prepareCreditmemoAndRefund($orderNumber);
303+
$response = $this->getCustomerOrderWithCreditMemoQuery();
304+
$expectedCreditMemoData = [
305+
[
306+
'comments' => [
307+
['message' => 'Test comment for refund with taxes and discount']
308+
],
309+
'items' => [
310+
[
311+
'product_name' => 'Bundle Product With Two dropdown options',
312+
'product_sku' => 'bundle-product-two-dropdown-options-simple1-simple2',
313+
'product_sale_price' => [
314+
'value' => 15
315+
],
316+
'quantity_refunded' => 1
317+
],
318+
319+
],
320+
'total' => [
321+
'subtotal' => [
322+
'value' => 15
323+
],
324+
'grand_total' => [
325+
'value' => 24.19
326+
],
327+
'base_grand_total' => [
328+
'value' => 24.19
329+
],
330+
'total_shipping' => [
331+
'value' => 10
332+
],
333+
'total_tax' => [
334+
'value'=> 1.69
335+
],
336+
'shipping_handling' => [
337+
'amount_including_tax' => [
338+
'value' => 10.75
339+
],
340+
'amount_excluding_tax' => [
341+
'value' => 10
342+
],
343+
'total_amount' => [
344+
'value' => 10
345+
],
346+
'taxes'=> [
347+
0 => [
348+
'amount'=>['value' => 1.69],
349+
'title' => 'US-TEST-*-Rate-1',
350+
'rate' => 7.5
351+
]
352+
],
353+
'discounts' => [
354+
0 => ['amount'=>['value'=> 2.5],
355+
'label' => 'Discount Label for 10% off'
356+
]
357+
],
358+
],
359+
'adjustment' => [
360+
'value' => 0
361+
]
362+
]
363+
]
364+
];
365+
$firstOrderItem = current($response['customer']['orders']['items'] ?? []);
366+
367+
$creditMemos = $firstOrderItem['credit_memos'] ?? [];
368+
$this->assertResponseFields($creditMemos, $expectedCreditMemoData);
369+
$this->deleteOrder();
370+
$searchCriteria = $this->searchCriteriaBuilder->addFilter('increment_id', $orderNumber)
371+
->create();
372+
$creditmemoRepository = Bootstrap::getObjectManager()->get(CreditmemoRepositoryInterface::class);
373+
$creditmemos = $creditmemoRepository->getList($searchCriteria)->getItems();
374+
foreach ($creditmemos as $creditmemo) {
375+
$creditmemoRepository->delete($creditmemo);
376+
}
377+
}
378+
254379
/**
255380
* @return string
256381
*/
@@ -633,6 +758,9 @@ private function getCustomerOrderWithCreditMemoQuery(): array
633758
total_shipping {
634759
value
635760
}
761+
total_tax {
762+
value
763+
}
636764
shipping_handling {
637765
amount_including_tax{value}
638766
amount_excluding_tax{value}

0 commit comments

Comments
 (0)