@@ -38,9 +38,8 @@ protected function setUp(): void
38
38
*/
39
39
public function testSingleInvoiceForLoggedInCustomerQuery ()
40
40
{
41
- $ response = $ this ->getCustomerInvoice ();
41
+ $ response = $ this ->getCustomerInvoices ();
42
42
$ expectedOrdersData = [
43
- 'order_number ' => '100000001 ' ,
44
43
'status ' => 'Processing ' ,
45
44
'grand_total ' => 100.00
46
45
];
@@ -103,9 +102,8 @@ public function testSingleInvoiceForLoggedInCustomerQuery()
103
102
*/
104
103
public function testMultipleInvoiceForLoggedInCustomerQuery ()
105
104
{
106
- $ response = $ this ->getCustomerInvoice ();
105
+ $ response = $ this ->getCustomerInvoices ();
107
106
$ expectedOrdersData = [
108
- 'order_number ' => '100000002 ' ,
109
107
'status ' => 'Processing ' ,
110
108
'grand_total ' => 50.00
111
109
];
@@ -200,12 +198,11 @@ public function testMultipleCustomersWithInvoicesQuery()
200
198
{
201
199
$ query =
202
200
<<<QUERY
203
- query {
201
+ {
204
202
customer
205
203
{
206
204
orders {
207
205
items {
208
- order_number
209
206
grand_total
210
207
status
211
208
invoices {
@@ -248,7 +245,6 @@ public function testMultipleCustomersWithInvoicesQuery()
248
245
$ this ->customerAuthenticationHeader ->execute ($ currentEmail , $ currentPassword )
249
246
);
250
247
$ expectedOrdersData = [
251
- 'order_number ' => '100000001 ' ,
252
248
'status ' => 'Processing ' ,
253
249
'grand_total ' => 100.00
254
250
];
@@ -308,7 +304,7 @@ public function testInvoiceForCustomerWithTaxesAndDiscounts()
308
304
309
305
$ orderNumber = $ this ->placeOrder ($ cartId );
310
306
$ this ->prepareInvoice ($ orderNumber , 2 );
311
- $ customerOrderResponse = $ this ->getCustomerOrderQuery ($ orderNumber );
307
+ $ customerOrderResponse = $ this ->getCustomerInvoicesBasedOnOrderNumber ($ orderNumber );
312
308
$ customerOrderItem = $ customerOrderResponse [0 ];
313
309
$ invoice = $ customerOrderItem ['invoices ' ][0 ];
314
310
$ this ->assertEquals (3 , $ invoice ['total ' ]['discounts ' ][0 ]['amount ' ]['value ' ]);
@@ -342,9 +338,13 @@ public function testPartialInvoiceForCustomerWithTaxesAndDiscounts()
342
338
343
339
$ orderNumber = $ this ->placeOrder ($ cartId );
344
340
$ this ->prepareInvoice ($ orderNumber , 1 );
345
- $ customerOrderResponse = $ this ->getCustomerOrderQuery ($ orderNumber );
341
+ $ customerOrderResponse = $ this ->getCustomerInvoicesBasedOnOrderNumber ($ orderNumber );
346
342
$ customerOrderItem = $ customerOrderResponse [0 ];
347
343
$ invoice = $ customerOrderItem ['invoices ' ][0 ];
344
+ $ invoiceItem = $ invoice ['items ' ][0 ];
345
+ $ this ->assertEquals (1 , $ invoiceItem ['discounts ' ][0 ]['amount ' ]['value ' ]);
346
+ $ this ->assertEquals ('USD ' , $ invoiceItem ['discounts ' ][0 ]['amount ' ]['currency ' ]);
347
+ $ this ->assertEquals ('Discount Label for 10% off ' , $ invoiceItem ['discounts ' ][0 ]['label ' ]);
348
348
$ this ->assertEquals (2 , $ invoice ['total ' ]['discounts ' ][0 ]['amount ' ]['value ' ]);
349
349
$ this ->assertEquals ('USD ' , $ invoice ['total ' ]['discounts ' ][0 ]['amount ' ]['currency ' ]);
350
350
$ this ->assertEquals (
@@ -356,6 +356,8 @@ public function testPartialInvoiceForCustomerWithTaxesAndDiscounts()
356
356
}
357
357
358
358
/**
359
+ * Prepare invoice for the order
360
+ *
359
361
* @param string $orderNumber
360
362
* @param int|null $qty
361
363
*/
@@ -737,7 +739,7 @@ private function placeOrder(string $cartId): string
737
739
* @param string $orderNumber
738
740
* @return array
739
741
*/
740
- private function getCustomerOrderQuery ($ orderNumber ): array
742
+ private function getCustomerInvoicesBasedOnOrderNumber ($ orderNumber ): array
741
743
{
742
744
$ query =
743
745
<<<QUERY
@@ -747,29 +749,8 @@ private function getCustomerOrderQuery($orderNumber): array
747
749
orders(filter:{number:{eq:" {$ orderNumber }"}}) {
748
750
total_count
749
751
items {
750
- id
751
- number
752
- order_date
753
- status
754
- items{product_name product_sku quantity_ordered discounts {amount{value currency} label}}
755
- total {
756
- base_grand_total{value currency}
757
- grand_total{value currency}
758
- total_tax{value currency}
759
- subtotal { value currency }
760
- taxes {amount{value currency} title rate}
761
- discounts {amount{value currency} label}
762
- total_shipping{value currency}
763
- shipping_handling
764
- {
765
- amount_including_tax{value}
766
- amount_excluding_tax{value}
767
- total_amount{value currency}
768
- taxes {amount{value} title rate}
769
- discounts {amount{value currency} label}
770
- }
771
- }
772
752
invoices {
753
+ items{product_sale_price{value currency} quantity_invoiced discounts {amount{value currency} label}}
773
754
total {
774
755
base_grand_total{value currency}
775
756
grand_total{value currency}
@@ -810,33 +791,33 @@ private function getCustomerOrderQuery($orderNumber): array
810
791
private function assertOrdersData ($ response , $ expectedOrdersData ): void
811
792
{
812
793
$ actualData = $ response ['customer ' ]['orders ' ]['items ' ][0 ];
813
- $ this ->assertEquals (
814
- $ expectedOrdersData ['order_number ' ],
815
- $ actualData ['order_number ' ],
816
- "order_number is different than the expected for order - " . $ expectedOrdersData ['order_number ' ]
817
- );
818
794
$ this ->assertEquals (
819
795
$ expectedOrdersData ['grand_total ' ],
820
796
$ actualData ['grand_total ' ],
821
- "grand_total is different than the expected for order - " . $ expectedOrdersData [ ' order_number ' ]
797
+ "grand_total is different than the expected for order "
822
798
);
823
799
$ this ->assertEquals (
824
800
$ expectedOrdersData ['status ' ],
825
801
$ actualData ['status ' ],
826
- "status is different than the expected for order - " . $ expectedOrdersData [ ' order_number ' ]
802
+ "status is different than the expected for order "
827
803
);
828
804
}
829
805
830
- private function getCustomerInvoice (): array
806
+ /**
807
+ * Get invoices for the customer
808
+ *
809
+ * @return array
810
+ * @throws \Magento\Framework\Exception\AuthenticationException
811
+ */
812
+ private function getCustomerInvoices (): array
831
813
{
832
814
$ query =
833
815
<<<QUERY
834
- query {
816
+ {
835
817
customer
836
818
{
837
819
orders {
838
820
items {
839
- order_number
840
821
grand_total
841
822
status
842
823
invoices {
0 commit comments