Skip to content

Commit 35bedb5

Browse files
committed
ACP2E-894: wip adding parametrized data fixtures
1 parent 9a84bd1 commit 35bedb5

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/CustomerOrders/GetCustomerOrdersTest.php

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99

1010
use Magento\Catalog\Helper\Data;
1111
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
12+
use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture;
13+
use Magento\Checkout\Test\Fixture\SetBillingAddress;
14+
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
15+
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
16+
use Magento\Checkout\Test\Fixture\SetShippingAddress;
1217
use Magento\Customer\Api\CustomerRepositoryInterface;
1318
use Magento\Customer\Model\CustomerAuthUpdate;
1419
use Magento\Customer\Model\CustomerRegistry;
1520
use Magento\Customer\Test\Fixture\Customer;
16-
use Magento\Framework\Exception\AuthenticationException;
1721
use Magento\Framework\ObjectManagerInterface;
1822
use Magento\Integration\Api\CustomerTokenServiceInterface;
1923
use Magento\Quote\Test\Fixture\AddProductToCart;
@@ -102,13 +106,30 @@ protected function setUp(): void
102106
as: 'customer'
103107
),
104108
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$', 'store_id' => '$store2.id$'], as: 'quote'),
105-
DataFixture(AddProductToCart::class, ['cart_id' => '$quote.id$', 'product_id' => '$product.id$', 'qty' => 1])
109+
DataFixture(AddProductToCart::class, ['cart_id' => '$quote.id$', 'product_id' => '$product.id$', 'qty' => 1]),
110+
DataFixture(SetBillingAddress::class, ['cart_id' => '$quote.id$']),
111+
DataFixture(SetShippingAddress::class, ['cart_id' => '$quote.id$']),
112+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote.id$']),
113+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote.id$']),
114+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote.id$'], 'order')
106115
]
107116
public function testGetCustomerOrders()
108117
{
109-
$currentEmail = '[email protected]';
118+
$fixtures = DataFixtureStorageManager::getStorage();
119+
$store2 = $fixtures->get('store2');
120+
$customer = $fixtures->get('customer');
121+
$currentEmail = $customer->getEmail();
110122
$currentPassword = 'password';
111123

124+
$generateToken = $this->generateCustomerToken($currentEmail, $currentPassword);
125+
$tokenResponse = $this->graphQlMutationWithResponseHeaders(
126+
$generateToken,
127+
[],
128+
'',
129+
['Store' => $store2->getCode()]
130+
);
131+
$customerToken = $tokenResponse['body']['generateCustomerToken']['token'];
132+
112133
$query = <<<QUERY
113134
query {
114135
customer {
@@ -127,13 +148,13 @@ public function testGetCustomerOrders()
127148
}
128149
}
129150
}
130-
}
151+
}
131152
QUERY;
132153
$response = $this->graphQlQuery(
133154
$query,
134155
[],
135156
'',
136-
$this->getCustomerAuthHeaders($currentEmail, $currentPassword)
157+
$this->getCustomerAuthHeaders($customerToken)
137158
);
138159

139160
$this->assertNull($response['customer']['id']);
@@ -142,15 +163,32 @@ public function testGetCustomerOrders()
142163
$this->assertEquals($currentEmail, $response['customer']['email']);
143164
}
144165

166+
/**
167+
* @param string $token
168+
*
169+
* @return array
170+
*/
171+
private function getCustomerAuthHeaders(string $token): array
172+
{
173+
return ['Authorization' => 'Bearer ' . $token];
174+
}
175+
145176
/**
146177
* @param string $email
147178
* @param string $password
148-
* @return array
149-
* @throws AuthenticationException
179+
* @return string
150180
*/
151-
private function getCustomerAuthHeaders(string $email, string $password): array
181+
private function generateCustomerToken(string $email, string $password) : string
152182
{
153-
$customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password);
154-
return ['Authorization' => 'Bearer ' . $customerToken];
183+
return <<<MUTATION
184+
mutation {
185+
generateCustomerToken(
186+
email: "{$email}"
187+
password: "{$password}"
188+
) {
189+
token
190+
}
191+
}
192+
MUTATION;
155193
}
156194
}

0 commit comments

Comments
 (0)