|
| 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\Sales; |
| 9 | + |
| 10 | +use Magento\Integration\Api\CustomerTokenServiceInterface; |
| 11 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | + |
| 14 | +/** |
| 15 | + * Class OrdersTest |
| 16 | + */ |
| 17 | +class OrdersTest extends GraphQlAbstract |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var CustomerTokenServiceInterface |
| 21 | + */ |
| 22 | + private $customerTokenService; |
| 23 | + |
| 24 | + /** |
| 25 | + * {@inheritdoc} |
| 26 | + */ |
| 27 | + protected function setUp() |
| 28 | + { |
| 29 | + parent::setUp(); |
| 30 | + $objectManager = Bootstrap::getObjectManager(); |
| 31 | + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @magentoApiDataFixture Magento/Customer/_files/customer.php |
| 36 | + * @magentoApiDataFixture Magento/Sales/_files/orders_with_customer.php |
| 37 | + */ |
| 38 | + public function testOrdersQuery() |
| 39 | + { |
| 40 | + $query = |
| 41 | + <<<QUERY |
| 42 | +query { |
| 43 | + customerOrders { |
| 44 | + items { |
| 45 | + id |
| 46 | + increment_id |
| 47 | + created_at |
| 48 | + grant_total |
| 49 | + state |
| 50 | + status |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +QUERY; |
| 55 | + |
| 56 | + $currentEmail = '[email protected]'; |
| 57 | + $currentPassword = 'password'; |
| 58 | + |
| 59 | + $response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword)); |
| 60 | + |
| 61 | + $expectedData = [ |
| 62 | + [ |
| 63 | + 'increment_id' => '100000002', |
| 64 | + 'state' => \Magento\Sales\Model\Order::STATE_NEW, |
| 65 | + 'status' => 'processing', |
| 66 | + 'grant_total' => 120.00 |
| 67 | + ], |
| 68 | + [ |
| 69 | + 'increment_id' => '100000003', |
| 70 | + 'state' => \Magento\Sales\Model\Order::STATE_PROCESSING, |
| 71 | + 'status' => 'processing', |
| 72 | + 'grant_total' => 130.00 |
| 73 | + ], |
| 74 | + [ |
| 75 | + 'increment_id' => '100000004', |
| 76 | + 'state' => \Magento\Sales\Model\Order::STATE_PROCESSING, |
| 77 | + 'status' => 'closed', |
| 78 | + 'grant_total' => 140.00 |
| 79 | + ], |
| 80 | + [ |
| 81 | + 'increment_id' => '100000005', |
| 82 | + 'state' => \Magento\Sales\Model\Order::STATE_COMPLETE, |
| 83 | + 'status' => 'complete', |
| 84 | + 'grant_total' => 150.00 |
| 85 | + ], |
| 86 | + [ |
| 87 | + 'increment_id' => '100000006', |
| 88 | + 'state' => \Magento\Sales\Model\Order::STATE_COMPLETE, |
| 89 | + 'status' => 'complete', |
| 90 | + 'grant_total' => 160.00 |
| 91 | + ] |
| 92 | + ]; |
| 93 | + |
| 94 | + $actualData = $response['customerOrders']['items']; |
| 95 | + |
| 96 | + foreach ($expectedData as $key => $data) { |
| 97 | + $this->assertEquals($data['increment_id'], $actualData[$key]['increment_id']); |
| 98 | + $this->assertEquals($data['grant_total'], $actualData[$key]['grant_total']); |
| 99 | + $this->assertEquals($data['state'], $actualData[$key]['state']); |
| 100 | + $this->assertEquals($data['status'], $actualData[$key]['status']); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @param string $email |
| 106 | + * @param string $password |
| 107 | + * @return array |
| 108 | + * @throws \Magento\Framework\Exception\AuthenticationException |
| 109 | + */ |
| 110 | + private function getCustomerAuthHeaders(string $email, string $password): array |
| 111 | + { |
| 112 | + $customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password); |
| 113 | + return ['Authorization' => 'Bearer ' . $customerToken]; |
| 114 | + } |
| 115 | +} |
0 commit comments