Skip to content

Commit 8f05913

Browse files
committed
MC-20636: MyAccount :: Order Details :: Order Details by Order Number
- CR and test fixes for taxes
1 parent 10020ad commit 8f05913

File tree

1 file changed

+80
-102
lines changed

1 file changed

+80
-102
lines changed

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

Lines changed: 80 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
use Magento\Bundle\Model\Selection;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Catalog\Model\Product;
13-
use Magento\CatalogInventory\Api\Data\StockItemInterface;
1413
use Magento\Framework\Api\SearchCriteriaBuilder;
1514
use Magento\Framework\Exception\AuthenticationException;
1615
use Magento\GraphQl\GetCustomerAuthenticationHeader;
1716
use Magento\Sales\Api\OrderRepositoryInterface;
18-
use Magento\Sales\Model\Order;
1917
use Magento\Sales\Model\ResourceModel\Order\Collection;
2018
use Magento\TestFramework\Helper\Bootstrap;
2119
use Magento\TestFramework\TestCase\GraphQlAbstract;
@@ -143,24 +141,10 @@ public function testGetCustomerOrderWithBundleProduct()
143141
{
144142
$qty = 1;
145143
$bundleSku = 'bundle-product-two-dropdown-options';
146-
/** @var Product $bundleProduct */
147-
$bundleProduct = $this->productRepository->get($bundleSku);
148-
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
149-
$typeInstance = $bundleProduct->getTypeInstance();
150-
/** @var $option \Magento\Bundle\Model\Option */
151-
$option1 = $typeInstance->getOptionsCollection($bundleProduct)->getFirstItem();
152-
$option2 = $typeInstance->getOptionsCollection($bundleProduct)->getLastItem();
153-
$optionId1 =(int) $option1->getId();
154-
$optionId2 =(int) $option2->getId();
155-
/** @var Selection $selection */
156-
$selection1 = $typeInstance->getSelectionsCollection([$option1->getId()], $bundleProduct)->getFirstItem();
157-
$selectionId1 = (int)$selection1->getSelectionId();
158-
159-
$selection2 = $typeInstance->getSelectionsCollection([$option2->getId()], $bundleProduct)->getLastItem();
160-
$selectionId2 = (int)$selection2->getSelectionId();
144+
$optionsAndSelectionData = $this->getBundleOptionAndSelectionData($bundleSku);
161145

162146
$cartId = $this->createEmptyCart();
163-
$this->addBundleProductToCart($cartId, $qty, $bundleSku, $optionId1, $selectionId1, $optionId2, $selectionId2);
147+
$this->addBundleProductQuery($cartId, $qty, $bundleSku, $optionsAndSelectionData);
164148
$this->setBillingAddress($cartId);
165149
$shippingMethod = $this->setShippingAddress($cartId);
166150
$paymentMethod = $this->setShippingMethod($cartId, $shippingMethod);
@@ -221,23 +205,10 @@ public function testGetCustomerOrderWithBundleProductWithTaxesAndDiscounts()
221205
{
222206
$qty = 4;
223207
$bundleSku = 'bundle-product-two-dropdown-options';
224-
/** @var Product $bundleProduct */
225-
$bundleProduct = $this->productRepository->get($bundleSku);
226-
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
227-
$typeInstance = $bundleProduct->getTypeInstance();
228-
/** @var $option \Magento\Bundle\Model\Option */
229-
$option1 = $typeInstance->getOptionsCollection($bundleProduct)->getFirstItem();
230-
$option2 = $typeInstance->getOptionsCollection($bundleProduct)->getLastItem();
231-
$optionId1 =(int) $option1->getId();
232-
$optionId2 =(int) $option2->getId();
233-
/** @var Selection $selection */
234-
$selection1 = $typeInstance->getSelectionsCollection([$option1->getId()], $bundleProduct)->getFirstItem();
235-
$selectionId1 = (int)$selection1->getSelectionId();
236-
$selection2 = $typeInstance->getSelectionsCollection([$option2->getId()], $bundleProduct)->getLastItem();
237-
$selectionId2 = (int)$selection2->getSelectionId();
208+
$optionsAndSelectionData = $this->getBundleOptionAndSelectionData($bundleSku);
238209

239210
$cartId = $this->createEmptyCart();
240-
$this->addBundleProductToCart($cartId, $qty, $bundleSku, $optionId1, $selectionId1, $optionId2, $selectionId2);
211+
$this->addBundleProductQuery($cartId, $qty, $bundleSku, $optionsAndSelectionData);
241212
$this->setBillingAddress($cartId);
242213
$shippingMethod = $this->setShippingAddress($cartId);
243214
$paymentMethod = $this->setShippingMethod($cartId, $shippingMethod);
@@ -909,38 +880,28 @@ private function assertTotalsWithTaxesAndDiscountsOnShippingAndTotal(array $cust
909880
20,
910881
$customerOrderItem['total']['total_shipping']['value']
911882
);
912-
$this->assertEquals(
913-
1.35,
914-
$customerOrderItem['total']['taxes'][0]['amount']['value']
915-
);
916-
$this->assertEquals(
917-
'USD',
918-
$customerOrderItem['total']['taxes'][0]['amount']['currency']
919-
);
920-
$this->assertEquals(
921-
'US-TEST-*-Rate-1',
922-
$customerOrderItem['total']['taxes'][0]['title']
923-
);
924-
$this->assertEquals(
925-
7.5,
926-
$customerOrderItem['total']['taxes'][0]['rate']
927-
);
928-
$this->assertEquals(
929-
2.7,
930-
$customerOrderItem['total']['taxes'][1]['amount']['value']
931-
);
932-
$this->assertEquals(
933-
'USD',
934-
$customerOrderItem['total']['taxes'][1]['amount']['currency']
935-
);
936-
$this->assertEquals(
937-
'US-TEST-*-Rate-1',
938-
$customerOrderItem['total']['taxes'][1]['title']
939-
);
940-
$this->assertEquals(
941-
7.5,
942-
$customerOrderItem['total']['taxes'][1]['rate']
943-
);
883+
$this->assertCount(2, $customerOrderItem['total']['taxes']);
884+
$expectedProductAndShippingTaxes =
885+
[
886+
[
887+
'amount' => [
888+
'value' => 2.7,
889+
'currency' => 'USD'
890+
],
891+
'title' => 'US-TEST-*-Rate-1',
892+
'rate' => 7.5
893+
],
894+
[
895+
'amount' => [
896+
'value' => 1.35,
897+
'currency' => 'USD'
898+
],
899+
900+
'title' => 'US-TEST-*-Rate-1',
901+
'rate' => 7.5
902+
]
903+
];
904+
$this->assertEquals($expectedProductAndShippingTaxes, $customerOrderItem['total']['taxes']);
944905
$this->assertEquals(
945906
21.5,
946907
$customerOrderItem['total']['shipping_handling']['amount_including_tax']['value']
@@ -970,10 +931,7 @@ private function assertTotalsWithTaxesAndDiscountsOnShippingAndTotal(array $cust
970931
2,
971932
$customerOrderItem['total']['shipping_handling']['discounts'][0]['amount']['value']
972933
);
973-
$this->assertEquals(
974-
'USD',
975-
$customerOrderItem['total']['shipping_handling']['discounts'][0]['amount']['currency']
976-
);
934+
977935
$this->assertEquals(
978936
'null',
979937
$customerOrderItem['total']['shipping_handling']['discounts'][0]['label']
@@ -982,10 +940,6 @@ private function assertTotalsWithTaxesAndDiscountsOnShippingAndTotal(array $cust
982940
-6,
983941
$customerOrderItem['total']['discounts'][0]['amount']['value']
984942
);
985-
$this->assertEquals(
986-
'USD',
987-
$customerOrderItem['total']['discounts'][0]['amount']['currency']
988-
);
989943
$this->assertEquals(
990944
'null',
991945
$customerOrderItem['total']['discounts'][0]['label']
@@ -1027,7 +981,6 @@ private function assertTotalsAndShippingWithExcludedTaxSetting(array $customerOr
1027981
32.25,
1028982
$customerOrderItem['total']['base_grand_total']['value']
1029983
);
1030-
1031984
$this->assertEquals(
1032985
32.25,
1033986
$customerOrderItem['total']['grand_total']['value']
@@ -1040,23 +993,31 @@ private function assertTotalsAndShippingWithExcludedTaxSetting(array $customerOr
1040993
2.25,
1041994
$customerOrderItem['total']['total_tax']['value']
1042995
);
1043-
1044996
$this->assertEquals(
1045997
10,
1046998
$customerOrderItem['total']['total_shipping']['value']
1047999
);
1048-
$this->assertEquals(
1049-
0.75,
1050-
$customerOrderItem['total']['taxes'][0]['amount']['value']
1051-
);
1052-
$this->assertEquals(
1053-
'US-TEST-*-Rate-1',
1054-
$customerOrderItem['total']['taxes'][0]['title']
1055-
);
1056-
$this->assertEquals(
1057-
7.5,
1058-
$customerOrderItem['total']['taxes'][0]['rate']
1059-
);
1000+
$expectedProductAndShippingTaxes =
1001+
[
1002+
[
1003+
'amount' => [
1004+
'value' => 1.5,
1005+
'currency' => 'USD'
1006+
],
1007+
'title' => 'US-TEST-*-Rate-1',
1008+
'rate' => 7.5
1009+
],
1010+
[
1011+
'amount' => [
1012+
'value' => 0.75,
1013+
'currency' => 'USD'
1014+
],
1015+
1016+
'title' => 'US-TEST-*-Rate-1',
1017+
'rate' => 7.5
1018+
]
1019+
];
1020+
$this->assertEquals($expectedProductAndShippingTaxes, $customerOrderItem['total']['taxes']);
10601021
$this->assertEquals(
10611022
10.75,
10621023
$customerOrderItem['total']['shipping_handling']['amount_including_tax']['value']
@@ -1072,7 +1033,7 @@ private function assertTotalsAndShippingWithExcludedTaxSetting(array $customerOr
10721033

10731034
$this->assertEquals(
10741035
0.75,
1075-
$customerOrderItem['total']['shipping_handling']['taxes'][0]['amount']['value']
1036+
$customerOrderItem['total']['shipping_handling']['taxes'][1]['amount']['value']
10761037
);
10771038
$this->assertEquals(
10781039
'US-TEST-*-Rate-1',
@@ -1157,15 +1118,7 @@ private function addProductToCart(string $cartId, float $qty, string $sku): void
11571118
$this->graphQlMutation($query, [], '', $this->customerAuthenticationHeader->execute($currentEmail, $currentPassword));
11581119
}
11591120

1160-
/**
1161-
* @param string $cartId
1162-
* @param float $qty
1163-
* @param string $sku
1164-
* @param int $optionId
1165-
* @param int $selectionId
1166-
* @throws AuthenticationException
1167-
*/
1168-
public function addBundleProductToCart(string $cartId, float $qty, string $sku, int $optionId1, int $selectionId1, int $optionId2, int $selectionId2)
1121+
public function addBundleProductQuery(string $cartId, float $qty, string $sku, array $optionsAndSelectionData)
11691122
{
11701123
$query = <<<QUERY
11711124
mutation {
@@ -1179,14 +1132,14 @@ public function addBundleProductToCart(string $cartId, float $qty, string $sku,
11791132
}
11801133
bundle_options:[
11811134
{
1182-
id:$optionId1
1135+
id:$optionsAndSelectionData[0]
11831136
quantity:1
1184-
value:["{$selectionId1}"]
1137+
value:["{$optionsAndSelectionData[1]}"]
11851138
}
11861139
{
1187-
id:$optionId2
1140+
id:$optionsAndSelectionData[2]
11881141
quantity:2
1189-
value:["{$selectionId2}"]
1142+
value:["{$optionsAndSelectionData[3]}"]
11901143
}
11911144
]
11921145
}
@@ -1203,7 +1156,6 @@ public function addBundleProductToCart(string $cartId, float $qty, string $sku,
12031156
$response = $this->graphQlMutation($query, [], '', $this->customerAuthenticationHeader->execute($currentEmail, $currentPassword));
12041157
$this->assertArrayHasKey('cart', $response['addBundleProductsToCart']);
12051158
}
1206-
12071159
/**
12081160
* @param string $cartId
12091161
* @param array $auth
@@ -1641,4 +1593,30 @@ private function assertTotals(array $response, int $expectedCount): void
16411593
);
16421594
}
16431595
}
1596+
1597+
/**
1598+
* @param string $bundleSku
1599+
* @return array
1600+
* @throws \Magento\Framework\Exception\NoSuchEntityException
1601+
*/
1602+
private function getBundleOptionAndSelectionData($bundleSku): array
1603+
{
1604+
/** @var Product $bundleProduct */
1605+
$bundleProduct = $this->productRepository->get($bundleSku);
1606+
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
1607+
$typeInstance = $bundleProduct->getTypeInstance();
1608+
$optionsAndSelections = [];
1609+
/** @var $option \Magento\Bundle\Model\Option */
1610+
$option1 = $typeInstance->getOptionsCollection($bundleProduct)->getFirstItem();
1611+
$option2 = $typeInstance->getOptionsCollection($bundleProduct)->getLastItem();
1612+
$optionId1 =(int) $option1->getId();
1613+
$optionId2 =(int) $option2->getId();
1614+
/** @var Selection $selection */
1615+
$selection1 = $typeInstance->getSelectionsCollection([$option1->getId()], $bundleProduct)->getFirstItem();
1616+
$selectionId1 = (int)$selection1->getSelectionId();
1617+
$selection2 = $typeInstance->getSelectionsCollection([$option2->getId()], $bundleProduct)->getLastItem();
1618+
$selectionId2 = (int)$selection2->getSelectionId();
1619+
array_push($optionsAndSelections, $optionId1, $selectionId1, $optionId2, $selectionId2);
1620+
return $optionsAndSelections;
1621+
}
16441622
}

0 commit comments

Comments
 (0)