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

Commit

Permalink
Refactoring:
Browse files Browse the repository at this point in the history
 - removed function for getting `customer_token`. (dublication)
 - removed assertion from private function revokeCustomerToken that is nod considered as test and already covered with tests

Signed-off-by: Tomash Khamlai <[email protected]>
  • Loading branch information
TomashKhamlai committed Nov 11, 2019
1 parent 3efbe15 commit cdbd452
Showing 1 changed file with 6 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ public function testGetLoggedInCustomerCartWithoutMaskedQuoteId()
*/
public function testGetNewCustomerCart()
{
$customerToken = $this->generateCustomerToken();
$customerCartQuery = $this->getCustomerCartQuery();
$headers = ['Authorization' => 'Bearer ' . $customerToken];
$response = $this->graphQlQuery($customerCartQuery, [], '', $headers);
$response = $this->graphQlQuery($customerCartQuery, [], '', $this->getHeaderMap());
$this->assertArrayHasKey('customerCart', $response);
$this->assertArrayHasKey('id', $response['customerCart']);
$this->assertNotNull($response['customerCart']['id']);
Expand All @@ -118,22 +116,20 @@ public function testGetCustomerCartWithNoCustomerToken()
* Query for customer cart after customer token is revoked
*
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException \Exception
* @expectedExceptionMessage The request is allowed for logged in customer
*/
public function testGetCustomerCartAfterTokenRevoked()
{
$customerToken = $this->generateCustomerToken();
$headers = ['Authorization' => 'Bearer ' . $customerToken];
$customerCartQuery = $this->getCustomerCartQuery();
$headers = $this->getHeaderMap();
$response = $this->graphQlMutation($customerCartQuery, [], '', $headers);
$this->assertArrayHasKey('customerCart', $response);
$this->assertArrayHasKey('id', $response['customerCart']);
$this->assertNotNull($response['customerCart']['id']);
$this->assertNotEmpty($response['customerCart']['id']);
$this->revokeCustomerToken();
$customerCartQuery = $this->getCustomerCartQuery();
$this->expectExceptionMessage(
'The request is allowed for logged in customer'
);
$this->graphQlQuery($customerCartQuery, [], '', $headers);
}

Expand All @@ -144,16 +140,14 @@ public function testGetCustomerCartAfterTokenRevoked()
*/
public function testRequestCustomerCartTwice()
{
$customerToken = $this->generateCustomerToken();
$headers = ['Authorization' => 'Bearer ' . $customerToken];
$customerCartQuery = $this->getCustomerCartQuery();
$response = $this->graphQlMutation($customerCartQuery, [], '', $headers);
$response = $this->graphQlMutation($customerCartQuery, [], '', $this->getHeaderMap());
$this->assertArrayHasKey('customerCart', $response);
$this->assertArrayHasKey('id', $response['customerCart']);
$this->assertNotNull($response['customerCart']['id']);
$cartId = $response['customerCart']['id'];
$customerCartQuery = $this->getCustomerCartQuery();
$response2 = $this->graphQlQuery($customerCartQuery, [], '', $headers);
$response2 = $this->graphQlQuery($customerCartQuery, [], '', $this->getHeaderMap());
$this->assertEquals($cartId, $response2['customerCart']['id']);
}

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

/**
* Query to generate customer token
*
* @return string
*/
private function generateCustomerToken(): string
{
$query = <<<QUERY
mutation {
generateCustomerToken(
email: "[email protected]"
password: "password"
) {
token
}
}
QUERY;
$response = $this->graphQlMutation($query);
self::assertArrayHasKey('generateCustomerToken', $response);
self::assertArrayHasKey('token', $response['generateCustomerToken']);
self::assertNotEmpty($response['generateCustomerToken']['token']);

return $response['generateCustomerToken']['token'];
}

/**
* Query to revoke customer token
*
Expand All @@ -233,7 +202,6 @@ private function revokeCustomerToken(): void
QUERY;

$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
$this->assertTrue($response['revokeCustomerToken']['result']);
}

/**
Expand Down

0 comments on commit cdbd452

Please sign in to comment.