12
12
use Magento \Catalog \Model \Product ;
13
13
use Magento \CatalogInventory \Api \Data \StockItemInterface ;
14
14
use Magento \Framework \Api \SearchCriteriaBuilder ;
15
+ use Magento \Framework \Exception \AuthenticationException ;
15
16
use Magento \Integration \Api \CustomerTokenServiceInterface ;
16
17
use Magento \Sales \Api \OrderRepositoryInterface ;
17
18
use Magento \Sales \Model \Order ;
@@ -247,6 +248,7 @@ public function testGetMatchingCustomerOrders()
247
248
$ this ->assertArrayHasKey ('total_count ' , $ response ['customer ' ]['orders ' ]);
248
249
$ this ->assertEquals (6 , $ response ['customer ' ]['orders ' ]['total_count ' ]);
249
250
}
251
+
250
252
/**
251
253
* @magentoApiDataFixture Magento/Customer/_files/customer.php
252
254
* @magentoApiDataFixture Magento/Sales/_files/orders_with_customer.php
@@ -470,6 +472,7 @@ public function testGetCustomerOrdersWithWrongCustomer()
470
472
471
473
/**
472
474
* @param String $orderNumber
475
+ * @throws AuthenticationException
473
476
* @dataProvider dataProviderIncorrectOrder
474
477
* @magentoApiDataFixture Magento/Customer/_files/customer.php
475
478
* @magentoApiDataFixture Magento/Sales/_files/orders_with_customer.php
@@ -568,7 +571,7 @@ public function dataProviderIncorrectOrder(): array
568
571
* @param String $orderNumber
569
572
* @param String $store
570
573
* @param int $expectedCount
571
- * @throws \Magento\Framework\Exception\ AuthenticationException
574
+ * @throws AuthenticationException
572
575
* @dataProvider dataProviderMultiStores
573
576
* @magentoApiDataFixture Magento/Customer/_files/customer.php
574
577
* @magentoApiDataFixture Magento/GraphQl/Sales/_files/two_orders_with_order_items_two_storeviews.php
@@ -689,11 +692,136 @@ public function testCustomerOrderWithTaxesAndDiscountsOnShippingAndTotal()
689
692
$ this ->setPaymentMethod ($ cartId , $ paymentMethod );
690
693
$ orderNumber = $ this ->placeOrder ($ cartId );
691
694
$ customerOrderResponse = $ this ->getCustomerOrderQuery ($ orderNumber );
695
+ // Asserting discounts on order item level
696
+ $ this ->assertEquals (
697
+ 4 ,
698
+ $ customerOrderResponse [0 ]['items ' ][0 ]['discounts ' ][0 ]['amount ' ]['value ' ]
699
+ );
700
+ $ this ->assertEquals (
701
+ 'USD ' ,
702
+ $ customerOrderResponse [0 ]['items ' ][0 ]['discounts ' ][0 ]['amount ' ]['currency ' ]
703
+ );
704
+ $ this ->assertEquals (
705
+ 'null ' ,
706
+ $ customerOrderResponse [0 ]['items ' ][0 ]['discounts ' ][0 ]['label ' ]
707
+ );
692
708
$ customerOrderItem = $ customerOrderResponse [0 ];
693
- //TODO: once discounts are calculated, order Totals can be verified
709
+ $ this -> assertTotalsWithTaxesAndDiscountsOnShippingAndTotal ( $ customerOrderItem );
694
710
$ this ->deleteOrder ();
695
711
}
696
712
713
+ /**
714
+ * Assert order totals including shipping_handling and taxes
715
+ *
716
+ * @param array $customerOrderItem
717
+ */
718
+ private function assertTotalsWithTaxesAndDiscountsOnShippingAndTotal (array $ customerOrderItem ): void
719
+ {
720
+ $ this ->assertEquals (
721
+ 58.05 ,
722
+ $ customerOrderItem ['total ' ]['base_grand_total ' ]['value ' ]
723
+ );
724
+
725
+ $ this ->assertEquals (
726
+ 58.05 ,
727
+ $ customerOrderItem ['total ' ]['grand_total ' ]['value ' ]
728
+ );
729
+ $ this ->assertEquals (
730
+ 40 ,
731
+ $ customerOrderItem ['total ' ]['subtotal ' ]['value ' ]
732
+ );
733
+ $ this ->assertEquals (
734
+ 4.05 ,
735
+ $ customerOrderItem ['total ' ]['total_tax ' ]['value ' ]
736
+ );
737
+
738
+ $ this ->assertEquals (
739
+ 20 ,
740
+ $ customerOrderItem ['total ' ]['total_shipping ' ]['value ' ]
741
+ );
742
+ $ this ->assertEquals (
743
+ 1.35 ,
744
+ $ customerOrderItem ['total ' ]['taxes ' ][0 ]['amount ' ]['value ' ]
745
+ );
746
+ $ this ->assertEquals (
747
+ 'USD ' ,
748
+ $ customerOrderItem ['total ' ]['taxes ' ][0 ]['amount ' ]['currency ' ]
749
+ );
750
+ $ this ->assertEquals (
751
+ 'US-TEST-*-Rate-1 ' ,
752
+ $ customerOrderItem ['total ' ]['taxes ' ][0 ]['title ' ]
753
+ );
754
+ $ this ->assertEquals (
755
+ 7.5 ,
756
+ $ customerOrderItem ['total ' ]['taxes ' ][0 ]['rate ' ]
757
+ );
758
+ $ this ->assertEquals (
759
+ 2.7 ,
760
+ $ customerOrderItem ['total ' ]['taxes ' ][1 ]['amount ' ]['value ' ]
761
+ );
762
+ $ this ->assertEquals (
763
+ 'USD ' ,
764
+ $ customerOrderItem ['total ' ]['taxes ' ][1 ]['amount ' ]['currency ' ]
765
+ );
766
+ $ this ->assertEquals (
767
+ 'US-TEST-*-Rate-1 ' ,
768
+ $ customerOrderItem ['total ' ]['taxes ' ][1 ]['title ' ]
769
+ );
770
+ $ this ->assertEquals (
771
+ 7.5 ,
772
+ $ customerOrderItem ['total ' ]['taxes ' ][1 ]['rate ' ]
773
+ );
774
+ $ this ->assertEquals (
775
+ 21.5 ,
776
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['amount_including_tax ' ]['value ' ]
777
+ );
778
+ $ this ->assertEquals (
779
+ 20 ,
780
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['amount_excluding_tax ' ]['value ' ]
781
+ );
782
+ $ this ->assertEquals (
783
+ 20 ,
784
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['total_amount ' ]['value ' ]
785
+ );
786
+
787
+ $ this ->assertEquals (
788
+ 1.35 ,
789
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['taxes ' ][0 ]['amount ' ]['value ' ]
790
+ );
791
+ $ this ->assertEquals (
792
+ 'US-TEST-*-Rate-1 ' ,
793
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['taxes ' ][0 ]['title ' ]
794
+ );
795
+ $ this ->assertEquals (
796
+ 7.5 ,
797
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['taxes ' ][0 ]['rate ' ]
798
+ );
799
+ $ this ->assertEquals (
800
+ 2 ,
801
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['discounts ' ][0 ]['amount ' ]['value ' ]
802
+ );
803
+ $ this ->assertEquals (
804
+ 'USD ' ,
805
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['discounts ' ][0 ]['amount ' ]['currency ' ]
806
+ );
807
+ $ this ->assertEquals (
808
+ 'null ' ,
809
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['discounts ' ][0 ]['label ' ]
810
+ );
811
+ $ this ->assertEquals (
812
+ -6 ,
813
+ $ customerOrderItem ['total ' ]['discounts ' ][0 ]['amount ' ]['value ' ]
814
+ );
815
+ $ this ->assertEquals (
816
+ 'USD ' ,
817
+ $ customerOrderItem ['total ' ]['discounts ' ][0 ]['amount ' ]['currency ' ]
818
+ );
819
+ $ this ->assertEquals (
820
+ 'null ' ,
821
+ $ customerOrderItem ['total ' ]['discounts ' ][0 ]['label ' ]
822
+ );
823
+ }
824
+
697
825
/**
698
826
* Verify that the customer order has the tax information on shipping and totals
699
827
* @magentoApiDataFixture Magento/Customer/_files/customer.php
@@ -865,7 +993,7 @@ private function addProductToCart(string $cartId, float $qty, string $sku): void
865
993
* @param string $sku
866
994
* @param int $optionId
867
995
* @param int $selectionId
868
- * @throws \Magento\Framework\Exception\ AuthenticationException
996
+ * @throws AuthenticationException
869
997
*/
870
998
public function addBundleProductToCart (string $ cartId , float $ qty , string $ sku , int $ optionId1 , int $ selectionId1 ,int $ optionId2 , int $ selectionId2 )
871
999
{
@@ -1100,22 +1228,24 @@ private function getCustomerOrderQuery($orderNumber):array
1100
1228
number
1101
1229
order_date
1102
1230
status
1103
- items{product_name product_sku quantity_ordered}
1231
+ items{product_name product_sku quantity_ordered discounts {amount{value currency} label} }
1104
1232
total {
1105
1233
base_grand_total{value currency}
1106
1234
grand_total{value currency}
1107
1235
total_tax{value}
1108
1236
subtotal { value currency }
1109
1237
taxes {amount{value currency} title rate}
1238
+ discounts {amount{value currency} label}
1110
1239
total_shipping{value}
1111
1240
shipping_handling
1112
1241
{
1113
1242
amount_including_tax{value}
1114
1243
amount_excluding_tax{value}
1115
1244
total_amount{value currency}
1116
1245
taxes {amount{value} title rate}
1246
+ discounts {amount{value currency} label}
1117
1247
}
1118
- discounts {amount{value currency} label}
1248
+
1119
1249
}
1120
1250
}
1121
1251
}
@@ -1137,7 +1267,7 @@ private function getCustomerOrderQuery($orderNumber):array
1137
1267
*
1138
1268
* @param $orderNumber
1139
1269
* @return mixed
1140
- * @throws \Magento\Framework\Exception\ AuthenticationException
1270
+ * @throws AuthenticationException
1141
1271
*/
1142
1272
private function getCustomerOrderQueryBundleProduct ($ orderNumber )
1143
1273
{
@@ -1182,7 +1312,6 @@ private function getCustomerOrderQueryBundleProduct($orderNumber)
1182
1312
total_amount{value}
1183
1313
taxes {amount{value} title rate}
1184
1314
}
1185
-
1186
1315
}
1187
1316
}
1188
1317
}
0 commit comments