diff --git a/SalesGraphQlAux/Model/Resolver/OrderState.php b/SalesGraphQlAux/Model/Resolver/OrderState.php new file mode 100644 index 0000000..3f19206 --- /dev/null +++ b/SalesGraphQlAux/Model/Resolver/OrderState.php @@ -0,0 +1,40 @@ +getState(); + } +} diff --git a/SalesGraphQlAux/README.md b/SalesGraphQlAux/README.md new file mode 100644 index 0000000..a1e29d1 --- /dev/null +++ b/SalesGraphQlAux/README.md @@ -0,0 +1,3 @@ +# Magento_SalesGraphQlAux module + +magento/module-sales-graph-ql-aux (Magento_SalesGraphQlAux) any changes which affect the core SalesGraphQl module which lives as magento/module-sales-graph-ql diff --git a/SalesGraphQlAux/composer.json b/SalesGraphQlAux/composer.json new file mode 100644 index 0000000..1337dc4 --- /dev/null +++ b/SalesGraphQlAux/composer.json @@ -0,0 +1,25 @@ +{ + "name": "magento/module-sales-graph-ql-aux", + "description": "N/A", + "type": "magento2-module", + "require": { + "php": "~7.4.0||~8.1.0", + "magento/framework": "*", + "magento/module-sales-graph-ql": "*" + }, + "suggest": { + "magento/module-graph-ql": "*" + }, + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\SalesGraphQlAux\\": "" + } + } +} diff --git a/SalesGraphQlAux/etc/module.xml b/SalesGraphQlAux/etc/module.xml new file mode 100644 index 0000000..e44721c --- /dev/null +++ b/SalesGraphQlAux/etc/module.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/SalesGraphQlAux/etc/schema.graphqls b/SalesGraphQlAux/etc/schema.graphqls new file mode 100644 index 0000000..03493ad --- /dev/null +++ b/SalesGraphQlAux/etc/schema.graphqls @@ -0,0 +1,6 @@ +# Copyright © Magento, Inc. All rights reserved. +# See COPYING.txt for license details. + +type CustomerOrder { + state: String! @doc(description: "The current state of the order.") @resolver(class: "Magento\\SalesGraphQlAux\\Model\\Resolver\\OrderState") +} \ No newline at end of file diff --git a/SalesGraphQlAux/registration.php b/SalesGraphQlAux/registration.php new file mode 100644 index 0000000..09dacc6 --- /dev/null +++ b/SalesGraphQlAux/registration.php @@ -0,0 +1,10 @@ +customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Sales/_files/orders_with_customer.php + */ + public function testOrdersQuery() + { + $query = + <<graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword)); + + $expectedData = [ + [ + 'order_number' => '100000002', + 'state' => Order::STATE_NEW + ], + [ + 'order_number' => '100000003', + 'state' => Order::STATE_PROCESSING + ], + [ + 'order_number' => '100000004', + 'state' => Order::STATE_PROCESSING + ], + [ + 'order_number' => '100000005', + 'state' => Order::STATE_COMPLETE + ], + [ + 'order_number' => '100000006', + 'state' => Order::STATE_COMPLETE + ] + ]; + + $actualData = $response['customerOrders']['items']; + + foreach ($expectedData as $key => $data) { + $this->assertEquals( + $data['order_number'], + $actualData[$key]['order_number'], + "order_number is different than the expected for order - " . $data['order_number'] + ); + $this->assertEquals( + $data['state'], + $actualData[$key]['state'], + "state is different than the expected for order - " . $data['order_number'] + ); + } + } + + /** + * @param string $email + * @param string $password + * @return array + * @throws \Magento\Framework\Exception\AuthenticationException + */ + private function getCustomerAuthHeaders(string $email, string $password): array + { + $customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password); + return ['Authorization' => 'Bearer ' . $customerToken]; + } +}