Skip to content

Commit b99663f

Browse files
committed
MC-20636: MyAccount :: Order Details :: Order Details by Order Number
- reordered tests and fixed tax related inconsistencies
1 parent 79c7f5d commit b99663f

File tree

1 file changed

+87
-107
lines changed

1 file changed

+87
-107
lines changed

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

Lines changed: 87 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ public function testGetCustomerOrdersSimpleProductQuery()
112112
/** @var \Magento\Sales\Api\Data\OrderInterface[] $items */
113113
$orders = $this->orderRepository->getList($searchCriteria)->getItems();
114114
foreach ($orders as $order) {
115-
$orderId = $order->getEntityId();
116115
$orderNumber = $order->getIncrementId();
117-
$this->assertEquals($orderId, $customerOrderItemsInResponse['id']);
116+
$this->assertNotEmpty($customerOrderItemsInResponse['id']);
118117
$this->assertEquals($orderNumber, $customerOrderItemsInResponse['number']);
119118
$this->assertEquals('Processing', $customerOrderItemsInResponse['status']);
120119
}
@@ -136,13 +135,52 @@ public function testGetCustomerOrdersSimpleProductQuery()
136135
$this->assertEquals($expectedOrderTotal, $actualOrderTotalFromResponse, 'Totals do not match');
137136
}
138137

138+
/**
139+
* Verify the customer order with tax, discount with shipping tax class set for calculation setting
140+
*
141+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
142+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
143+
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
144+
* @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off_with_discount_on_shipping.php
145+
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_calculation_shipping_excludeTax_order_display_settings.php
146+
*/
147+
public function testCustomerOrdersSimpleProductWithTaxesAndDiscounts()
148+
{
149+
$quantity = 4;
150+
$sku = 'simple1';
151+
$cartId = $this->createEmptyCart();
152+
$this->addProductToCart($cartId, $quantity, $sku);
153+
$this->setBillingAddress($cartId);
154+
$shippingMethod = $this->setShippingAddress($cartId);
155+
$paymentMethod = $this->setShippingMethod($cartId, $shippingMethod);
156+
$this->setPaymentMethod($cartId, $paymentMethod);
157+
$orderNumber = $this->placeOrder($cartId);
158+
$customerOrderResponse = $this->getCustomerOrderQuery($orderNumber);
159+
// Asserting discounts on order item level
160+
$this->assertEquals(
161+
4,
162+
$customerOrderResponse[0]['items'][0]['discounts'][0]['amount']['value']
163+
);
164+
$this->assertEquals(
165+
'USD',
166+
$customerOrderResponse[0]['items'][0]['discounts'][0]['amount']['currency']
167+
);
168+
$this->assertEquals(
169+
'null',
170+
$customerOrderResponse[0]['items'][0]['discounts'][0]['label']
171+
);
172+
$customerOrderItem = $customerOrderResponse[0];
173+
$this->assertTotalsWithTaxesAndDiscountsOnShippingAndTotal($customerOrderItem);
174+
$this->deleteOrder();
175+
}
176+
139177
/**
140178
* Test customer order details with bundle product with child items
141179
*
142180
* @magentoApiDataFixture Magento/Customer/_files/customer.php
143181
* @magentoApiDataFixture Magento/Bundle/_files/bundle_product_two_dropdown_options.php
144182
*/
145-
public function testGetCustomerOrderWithBundleProduct()
183+
public function testGetCustomerOrderBundleProduct()
146184
{
147185
$qty = 1;
148186
$bundleSku = 'bundle-product-two-dropdown-options';
@@ -211,7 +249,7 @@ public function testGetCustomerOrderWithBundleProduct()
211249
* @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off_with_discount_on_shipping.php
212250
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_calculation_shipping_excludeTax_order_display_settings.php
213251
*/
214-
public function testGetCustomerOrderWithBundleProductWithTaxesAndDiscounts()
252+
public function testGetCustomerOrderBundleProductWithTaxesAndDiscounts()
215253
{
216254
$qty = 4;
217255
$bundleSku = 'bundle-product-two-dropdown-options';
@@ -278,10 +316,16 @@ private function assertTotalsOnBundleProductWithTaxesAndDiscounts(array $custome
278316
20,
279317
$customerOrderItem['total']['total_shipping']['value']
280318
);
281-
$this->assertEquals(
282-
1.35,
283-
$customerOrderItem['total']['taxes'][0]['amount']['value']
284-
);
319+
$this->assertCount(2, $customerOrderItem['total']['taxes']);
320+
$expectedProductAndShippingTaxes = [4.05, 1.35];
321+
322+
$totalTaxes = [];
323+
foreach ($customerOrderItem['total']['taxes'] as $totalTaxFromResponse) {
324+
array_push($totalTaxes, $totalTaxFromResponse['amount']['value']);
325+
}
326+
foreach ($totalTaxes as $value) {
327+
$this->assertTrue(in_array($value, $expectedProductAndShippingTaxes));
328+
}
285329
$this->assertEquals(
286330
'USD',
287331
$customerOrderItem['total']['taxes'][0]['amount']['currency']
@@ -294,10 +338,6 @@ private function assertTotalsOnBundleProductWithTaxesAndDiscounts(array $custome
294338
7.5,
295339
$customerOrderItem['total']['taxes'][0]['rate']
296340
);
297-
$this->assertEquals(
298-
4.05,
299-
$customerOrderItem['total']['taxes'][1]['amount']['value']
300-
);
301341
$this->assertEquals(
302342
'USD',
303343
$customerOrderItem['total']['taxes'][1]['amount']['currency']
@@ -462,7 +502,6 @@ public function testGetMatchingOrdersForLowerQueryLength()
462502
/**
463503
* @magentoApiDataFixture Magento/Customer/_files/customer.php
464504
* @magentoApiDataFixture Magento/GraphQl/Sales/_files/orders_with_customer.php
465-
* @magentoApiDataFixture Magento/Sales/_files/orders_with_customer.php
466505
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
467506
*/
468507
public function testGetMultipleCustomerOrdersQueryWithDefaultPagination()
@@ -482,7 +521,7 @@ public function testGetMultipleCustomerOrdersQueryWithDefaultPagination()
482521
}
483522
items
484523
{
485-
id
524+
486525
number
487526
status
488527
order_date
@@ -543,9 +582,8 @@ public function testGetMultipleCustomerOrdersQueryWithDefaultPagination()
543582
$orders = $this->orderRepository->getList($searchCriteria)->getItems();
544583
$key = 0;
545584
foreach ($orders as $order) {
546-
$orderId = $order->getEntityId();
547585
$orderNumber = $order->getIncrementId();
548-
$this->assertEquals($orderId, $customerOrderItemsInResponse[$key]['id']);
586+
$this->assertNotEmpty($customerOrderItemsInResponse[$key]['id']);
549587
$this->assertEquals($orderNumber, $customerOrderItemsInResponse[$key]['number']);
550588
$this->assertEquals('Processing', $customerOrderItemsInResponse[$key]['status']);
551589
$this->assertEquals(
@@ -820,7 +858,9 @@ public function testGetCustomerOrdersTwoStoreViewQuery(string $orderNumber, stri
820858
'',
821859
array_merge(
822860
$this->customerAuthenticationHeader->execute(
823-
$currentEmail, $currentPassword),
861+
$currentEmail,
862+
$currentPassword
863+
),
824864
['Store' => $store]
825865
)
826866
);
@@ -855,45 +895,6 @@ public function dataProviderMultiStores(): array
855895
];
856896
}
857897

858-
/**
859-
* Verify the customer order with tax, discount with shipping tax class set for calculation setting
860-
*
861-
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
862-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
863-
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
864-
* @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off_with_discount_on_shipping.php
865-
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_calculation_shipping_excludeTax_order_display_settings.php
866-
*/
867-
public function testCustomerOrderWithTaxesAndDiscountsOnShippingAndTotal()
868-
{
869-
$quantity = 4;
870-
$sku = 'simple1';
871-
$cartId = $this->createEmptyCart();
872-
$this->addProductToCart($cartId, $quantity, $sku);
873-
$this->setBillingAddress($cartId);
874-
$shippingMethod = $this->setShippingAddress($cartId);
875-
$paymentMethod = $this->setShippingMethod($cartId, $shippingMethod);
876-
$this->setPaymentMethod($cartId, $paymentMethod);
877-
$orderNumber = $this->placeOrder($cartId);
878-
$customerOrderResponse = $this->getCustomerOrderQuery($orderNumber);
879-
// Asserting discounts on order item level
880-
$this->assertEquals(
881-
4,
882-
$customerOrderResponse[0]['items'][0]['discounts'][0]['amount']['value']
883-
);
884-
$this->assertEquals(
885-
'USD',
886-
$customerOrderResponse[0]['items'][0]['discounts'][0]['amount']['currency']
887-
);
888-
$this->assertEquals(
889-
'null',
890-
$customerOrderResponse[0]['items'][0]['discounts'][0]['label']
891-
);
892-
$customerOrderItem = $customerOrderResponse[0];
893-
$this->assertTotalsWithTaxesAndDiscountsOnShippingAndTotal($customerOrderItem);
894-
$this->deleteOrder();
895-
}
896-
897898
/**
898899
* Assert order totals including shipping_handling and taxes
899900
*
@@ -919,32 +920,29 @@ private function assertTotalsWithTaxesAndDiscountsOnShippingAndTotal(array $cust
919920
4.05,
920921
$customerOrderItem['total']['total_tax']['value']
921922
);
922-
923+
$this->assertEquals(
924+
-6,
925+
$customerOrderItem['total']['discounts'][0]['amount']['value']
926+
);
927+
$this->assertEquals(
928+
'null',
929+
$customerOrderItem['total']['discounts'][0]['label']
930+
);
923931
$this->assertEquals(
924932
20,
925933
$customerOrderItem['total']['total_shipping']['value']
926934
);
927935
$this->assertCount(2, $customerOrderItem['total']['taxes']);
928-
$expectedProductAndShippingTaxes =
929-
[
930-
[
931-
'amount' => [
932-
'value' => 2.7,
933-
'currency' => 'USD',
934-
],
935-
'title' => 'US-TEST-*-Rate-1',
936-
'rate' => 7.5,
937-
],
938-
[
939-
'amount' => [
940-
'value' => 1.35,
941-
'currency' => 'USD'
942-
],
943-
'title' => 'US-TEST-*-Rate-1',
944-
'rate' => 7.5,
945-
]
946-
];
947-
$this->assertEquals($expectedProductAndShippingTaxes, $customerOrderItem['total']['taxes']);
936+
$expectedProductAndShippingTaxes = [2.7, 1.35];
937+
938+
$totalTaxes = [];
939+
foreach ($customerOrderItem['total']['taxes'] as $totalTaxFromResponse) {
940+
array_push($totalTaxes, $totalTaxFromResponse['amount']['value']);
941+
}
942+
foreach ($totalTaxes as $value) {
943+
$this->assertTrue(in_array($value, $expectedProductAndShippingTaxes));
944+
}
945+
948946
$this->assertEquals(
949947
21.5,
950948
$customerOrderItem['total']['shipping_handling']['amount_including_tax']['value']
@@ -979,14 +977,6 @@ private function assertTotalsWithTaxesAndDiscountsOnShippingAndTotal(array $cust
979977
'null',
980978
$customerOrderItem['total']['shipping_handling']['discounts'][0]['label']
981979
);
982-
$this->assertEquals(
983-
-6,
984-
$customerOrderItem['total']['discounts'][0]['amount']['value']
985-
);
986-
$this->assertEquals(
987-
'null',
988-
$customerOrderItem['total']['discounts'][0]['label']
989-
);
990980
}
991981

992982
/**
@@ -1040,27 +1030,16 @@ private function assertTotalsAndShippingWithExcludedTaxSetting(array $customerOr
10401030
10,
10411031
$customerOrderItem['total']['total_shipping']['value']
10421032
);
1043-
$expectedProductAndShippingTaxes =
1044-
[
1045-
[
1046-
'amount' => [
1047-
'value' => 1.5,
1048-
'currency' => 'USD'
1049-
],
1050-
'title' => 'US-TEST-*-Rate-1',
1051-
'rate' => 7.5
1052-
],
1053-
[
1054-
'amount' => [
1055-
'value' => 0.75,
1056-
'currency' => 'USD'
1057-
],
1058-
1059-
'title' => 'US-TEST-*-Rate-1',
1060-
'rate' => 7.5
1061-
]
1062-
];
1063-
$this->assertEquals($expectedProductAndShippingTaxes, $customerOrderItem['total']['taxes']);
1033+
$expectedProductAndShippingTaxes = [1.5, 0.75];
1034+
1035+
$totalTaxes = [];
1036+
foreach ($customerOrderItem['total']['taxes'] as $totalTaxFromResponse) {
1037+
array_push($totalTaxes, $totalTaxFromResponse['amount']['value']);
1038+
}
1039+
foreach ($totalTaxes as $value) {
1040+
$this->assertTrue(in_array($value, $expectedProductAndShippingTaxes));
1041+
}
1042+
10641043
$this->assertEquals(
10651044
10.75,
10661045
$customerOrderItem['total']['shipping_handling']['amount_including_tax']['value']
@@ -1073,10 +1052,11 @@ private function assertTotalsAndShippingWithExcludedTaxSetting(array $customerOr
10731052
10,
10741053
$customerOrderItem['total']['shipping_handling']['total_amount']['value']
10751054
);
1055+
$this->assertCount(1, $customerOrderItem['total']['shipping_handling']['taxes'], 'Count is incorrect');
10761056

10771057
$this->assertEquals(
10781058
0.75,
1079-
$customerOrderItem['total']['shipping_handling']['taxes'][1]['amount']['value']
1059+
$customerOrderItem['total']['shipping_handling']['taxes'][0]['amount']['value']
10801060
);
10811061
$this->assertEquals(
10821062
'US-TEST-*-Rate-1',

0 commit comments

Comments
 (0)