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

Commit

Permalink
ENGCOM-6270: Refactor Magento\GraphQl\Quote\Customer\GetCustomerCartT…
Browse files Browse the repository at this point in the history
…est #1056
  • Loading branch information
lenaorobei authored Nov 13, 2019
2 parents 8ed44b0 + 98df358 commit f7727e4
Showing 1 changed file with 7 additions and 39 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: "customer@example.com"
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 @@ -232,8 +201,7 @@ private function revokeCustomerToken(): void
}
QUERY;

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

/**
Expand Down

0 comments on commit f7727e4

Please sign in to comment.