Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit f7727e4

Browse files
authored
ENGCOM-6270: Refactor Magento\GraphQl\Quote\Customer\GetCustomerCartTest #1056
2 parents 8ed44b0 + 98df358 commit f7727e4

File tree

1 file changed

+7
-39
lines changed

1 file changed

+7
-39
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCustomerCartTest.php

+7-39
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ public function testGetLoggedInCustomerCartWithoutMaskedQuoteId()
9090
*/
9191
public function testGetNewCustomerCart()
9292
{
93-
$customerToken = $this->generateCustomerToken();
9493
$customerCartQuery = $this->getCustomerCartQuery();
95-
$headers = ['Authorization' => 'Bearer ' . $customerToken];
96-
$response = $this->graphQlQuery($customerCartQuery, [], '', $headers);
94+
$response = $this->graphQlQuery($customerCartQuery, [], '', $this->getHeaderMap());
9795
$this->assertArrayHasKey('customerCart', $response);
9896
$this->assertArrayHasKey('id', $response['customerCart']);
9997
$this->assertNotNull($response['customerCart']['id']);
@@ -118,22 +116,20 @@ public function testGetCustomerCartWithNoCustomerToken()
118116
* Query for customer cart after customer token is revoked
119117
*
120118
* @magentoApiDataFixture Magento/Customer/_files/customer.php
119+
* @expectedException \Exception
120+
* @expectedExceptionMessage The request is allowed for logged in customer
121121
*/
122122
public function testGetCustomerCartAfterTokenRevoked()
123123
{
124-
$customerToken = $this->generateCustomerToken();
125-
$headers = ['Authorization' => 'Bearer ' . $customerToken];
126124
$customerCartQuery = $this->getCustomerCartQuery();
125+
$headers = $this->getHeaderMap();
127126
$response = $this->graphQlMutation($customerCartQuery, [], '', $headers);
128127
$this->assertArrayHasKey('customerCart', $response);
129128
$this->assertArrayHasKey('id', $response['customerCart']);
130129
$this->assertNotNull($response['customerCart']['id']);
131130
$this->assertNotEmpty($response['customerCart']['id']);
132131
$this->revokeCustomerToken();
133132
$customerCartQuery = $this->getCustomerCartQuery();
134-
$this->expectExceptionMessage(
135-
'The request is allowed for logged in customer'
136-
);
137133
$this->graphQlQuery($customerCartQuery, [], '', $headers);
138134
}
139135

@@ -144,16 +140,14 @@ public function testGetCustomerCartAfterTokenRevoked()
144140
*/
145141
public function testRequestCustomerCartTwice()
146142
{
147-
$customerToken = $this->generateCustomerToken();
148-
$headers = ['Authorization' => 'Bearer ' . $customerToken];
149143
$customerCartQuery = $this->getCustomerCartQuery();
150-
$response = $this->graphQlMutation($customerCartQuery, [], '', $headers);
144+
$response = $this->graphQlMutation($customerCartQuery, [], '', $this->getHeaderMap());
151145
$this->assertArrayHasKey('customerCart', $response);
152146
$this->assertArrayHasKey('id', $response['customerCart']);
153147
$this->assertNotNull($response['customerCart']['id']);
154148
$cartId = $response['customerCart']['id'];
155149
$customerCartQuery = $this->getCustomerCartQuery();
156-
$response2 = $this->graphQlQuery($customerCartQuery, [], '', $headers);
150+
$response2 = $this->graphQlQuery($customerCartQuery, [], '', $this->getHeaderMap());
157151
$this->assertEquals($cartId, $response2['customerCart']['id']);
158152
}
159153

@@ -192,31 +186,6 @@ public function testGetCustomerCartSecondStore()
192186
$this->assertEquals($maskedQuoteIdSecondStore, $responseSecondStore['customerCart']['id']);
193187
}
194188

195-
/**
196-
* Query to generate customer token
197-
*
198-
* @return string
199-
*/
200-
private function generateCustomerToken(): string
201-
{
202-
$query = <<<QUERY
203-
mutation {
204-
generateCustomerToken(
205-
206-
password: "password"
207-
) {
208-
token
209-
}
210-
}
211-
QUERY;
212-
$response = $this->graphQlMutation($query);
213-
self::assertArrayHasKey('generateCustomerToken', $response);
214-
self::assertArrayHasKey('token', $response['generateCustomerToken']);
215-
self::assertNotEmpty($response['generateCustomerToken']['token']);
216-
217-
return $response['generateCustomerToken']['token'];
218-
}
219-
220189
/**
221190
* Query to revoke customer token
222191
*
@@ -232,8 +201,7 @@ private function revokeCustomerToken(): void
232201
}
233202
QUERY;
234203

235-
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
236-
$this->assertTrue($response['revokeCustomerToken']['result']);
204+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
237205
}
238206

239207
/**

0 commit comments

Comments
 (0)