|
9 | 9 |
|
10 | 10 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
11 | 11 | use Magento\TestFramework\ObjectManager;
|
| 12 | +use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException; |
12 | 13 | use Magento\Customer\Api\CustomerRepositoryInterface;
|
13 | 14 | use Magento\Sales\Api\OrderRepositoryInterface;
|
14 | 15 | use Magento\Framework\Api\SearchCriteriaBuilder;
|
@@ -80,4 +81,66 @@ public function testGetCustomerDownloadableProducts()
|
80 | 81 | $response['customerDownloadableProducts']['items'][0]['order_increment_id']
|
81 | 82 | );
|
82 | 83 | }
|
| 84 | + |
| 85 | + /** |
| 86 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 87 | + * @magentoApiDataFixture Magento/Customer/_files/customer.php |
| 88 | + */ |
| 89 | + public function testGetCustomerDownloadableProductsIfProductsDoNotExist() |
| 90 | + { |
| 91 | + $query = <<<MUTATION |
| 92 | +mutation { |
| 93 | + generateCustomerToken( |
| 94 | + email: "customer@example.com" |
| 95 | + password: "password" |
| 96 | + ) { |
| 97 | + token |
| 98 | + } |
| 99 | +} |
| 100 | +MUTATION; |
| 101 | + $response = $this->graphQlMutation($query); |
| 102 | + $token = $response['generateCustomerToken']['token']; |
| 103 | + $this->headers = ['Authorization' => 'Bearer ' . $token]; |
| 104 | + |
| 105 | + $query = <<<QUERY |
| 106 | + { |
| 107 | + customerDownloadableProducts{ |
| 108 | + items{ |
| 109 | + order_increment_id |
| 110 | + date |
| 111 | + status |
| 112 | + download_url |
| 113 | + remaining_downloads |
| 114 | + } |
| 115 | + } |
| 116 | +
|
| 117 | +} |
| 118 | +QUERY; |
| 119 | + |
| 120 | + $response = $this->graphQlQuery($query, [], '', $this->headers); |
| 121 | + $this->assertEmpty($response['customerDownloadableProducts']['items']); |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + public function testGuestCannotAccessDownloadableProducts() |
| 126 | + { |
| 127 | + $query = <<<QUERY |
| 128 | + { |
| 129 | + customerDownloadableProducts{ |
| 130 | + items{ |
| 131 | + order_increment_id |
| 132 | + date |
| 133 | + status |
| 134 | + download_url |
| 135 | + remaining_downloads |
| 136 | + } |
| 137 | + } |
| 138 | +
|
| 139 | +} |
| 140 | +QUERY; |
| 141 | + |
| 142 | + $this->expectException(ResponseContainsErrorsException::class); |
| 143 | + $this->expectExceptionMessage('GraphQL response contains errors: The current customer isn\'t authorized'); |
| 144 | + $this->graphQlQuery($query); |
| 145 | + } |
83 | 146 | }
|
0 commit comments