Skip to content

Commit a16952c

Browse files
committed
Customer downloadable products added more tests
1 parent bfe26d8 commit a16952c

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/CustomerDownloadableProduct/CustomerDownloadableProductTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\TestFramework\TestCase\GraphQlAbstract;
1111
use Magento\TestFramework\ObjectManager;
12+
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
1213
use Magento\Customer\Api\CustomerRepositoryInterface;
1314
use Magento\Sales\Api\OrderRepositoryInterface;
1415
use Magento\Framework\Api\SearchCriteriaBuilder;
@@ -80,4 +81,66 @@ public function testGetCustomerDownloadableProducts()
8081
$response['customerDownloadableProducts']['items'][0]['order_increment_id']
8182
);
8283
}
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+
}
83146
}

0 commit comments

Comments
 (0)