|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\GraphQl\SalesGraphQlAux; |
| 9 | + |
| 10 | +use Magento\Sales\Model\Order; |
| 11 | +use Magento\TestFramework\Helper\Bootstrap; |
| 12 | +use Magento\Integration\Api\CustomerTokenServiceInterface; |
| 13 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 14 | + |
| 15 | +class OrderStateTest extends GraphQlAbstract |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var CustomerTokenServiceInterface |
| 19 | + */ |
| 20 | + private $customerTokenService; |
| 21 | + |
| 22 | + protected function setUp(): void |
| 23 | + { |
| 24 | + parent::setUp(); |
| 25 | + $this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @magentoApiDataFixture Magento/Customer/_files/customer.php |
| 30 | + * @magentoApiDataFixture Magento/Sales/_files/orders_with_customer.php |
| 31 | + */ |
| 32 | + public function testOrdersQuery() |
| 33 | + { |
| 34 | + $query = |
| 35 | + <<<QUERY |
| 36 | +query { |
| 37 | + customer { |
| 38 | + orders { |
| 39 | + items { |
| 40 | + order_number |
| 41 | + state |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | +QUERY; |
| 47 | + |
| 48 | + $currentEmail = 'customer@example.com'; |
| 49 | + $currentPassword = 'password'; |
| 50 | + $response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword)); |
| 51 | + |
| 52 | + $expectedData = [ |
| 53 | + [ |
| 54 | + 'order_number' => '100000002', |
| 55 | + 'state' => Order::STATE_NEW |
| 56 | + ], |
| 57 | + [ |
| 58 | + 'order_number' => '100000004', |
| 59 | + 'state' => Order::STATE_PROCESSING |
| 60 | + ], |
| 61 | + [ |
| 62 | + 'order_number' => '100000005', |
| 63 | + 'state' => Order::STATE_COMPLETE |
| 64 | + ], |
| 65 | + [ |
| 66 | + 'order_number' => '100000006', |
| 67 | + 'state' => Order::STATE_COMPLETE |
| 68 | + ] |
| 69 | + ]; |
| 70 | + |
| 71 | + $actualData = $response['customer']['orders']['items']; |
| 72 | + |
| 73 | + foreach ($expectedData as $key => $data) { |
| 74 | + $this->assertEquals( |
| 75 | + $data['order_number'], |
| 76 | + $actualData[$key]['order_number'], |
| 77 | + "order_number is different than the expected for order - " . $data['order_number'] |
| 78 | + ); |
| 79 | + $this->assertEquals( |
| 80 | + $data['state'], |
| 81 | + $actualData[$key]['state'], |
| 82 | + "state is different than the expected for order - " . $data['order_number'] |
| 83 | + ); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @param string $email |
| 89 | + * @param string $password |
| 90 | + * @return array |
| 91 | + * @throws \Magento\Framework\Exception\AuthenticationException |
| 92 | + */ |
| 93 | + private function getCustomerAuthHeaders(string $email, string $password): array |
| 94 | + { |
| 95 | + $customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password); |
| 96 | + return ['Authorization' => 'Bearer ' . $customerToken]; |
| 97 | + } |
| 98 | +} |
0 commit comments