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

Refactor Magento\GraphQl\Quote\Customer\GetCustomerCartTest #1056

Merged
merged 2 commits into from
Nov 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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