Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Kilo authored and Maciej Pawłowski committed May 2, 2020
1 parent 4a05e78 commit cfa889e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Magento\GraphQl\Catalog;

use Magento\PageCache\Model\Cache\Type as PageCache;
use Magento\TestFramework\ObjectManager;
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
use Magento\TestFramework\TestCase\GraphQlAbstract;

/**
Expand Down Expand Up @@ -77,12 +77,7 @@ public function testProductFromSpecificAndDefaultStore()
'Product name in fixture store is invalid.'
);

// use case for invalid storeCode
$nonExistingStoreCode = "non_existent_store";
$headerMapInvalidStoreCode = ['Store' => $nonExistingStoreCode];
$this->expectException(ResponseContainsErrorsException::class);
$this->expectExceptionMessage('Requested store is not found');
$this->graphQlQuery($query, [], '', $headerMapInvalidStoreCode);
$this->flushPageCache();

//use case for default storeCode
$nameInDefaultStore = 'Simple Product';
Expand All @@ -94,6 +89,8 @@ public function testProductFromSpecificAndDefaultStore()
'Product name in default store is invalid.'
);

$this->flushPageCache();

//use case for empty storeCode
$headerMapEmpty = ['Store' => ''];
$response = $this->graphQlQuery($query, [], '', $headerMapEmpty);
Expand All @@ -102,5 +99,21 @@ public function testProductFromSpecificAndDefaultStore()
$response['products']['items'][0]['name'],
'Product in the default store should be returned'
);

$this->flushPageCache();

// use case for invalid storeCode
$nonExistingStoreCode = "non_existent_store";
$headerMapInvalidStoreCode = ['Store' => $nonExistingStoreCode];
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Requested store is not found');
$this->graphQlQuery($query, [], '', $headerMapInvalidStoreCode);
}

protected function flushPageCache(): void
{
/** @var PageCache $fullPageCache */
$fullPageCache = ObjectManager::getInstance()->get(PageCache::class);
$fullPageCache->clean();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\GraphQl\PageCache;

use Magento\PageCache\Model\Cache\Type as PageCache;
use Magento\TestFramework\ObjectManager;
use Magento\TestFramework\TestCase\GraphQlAbstract;

Expand Down Expand Up @@ -242,6 +243,8 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
'Currency code EUR in fixture ' . $storeCodeFromFixture . ' is unexpected'
);

$this->flushPageCache();

// test cached store + currency header in Euros
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'EUR'];
$response = $this->graphQlQuery($query, [], '', $headerMap);
Expand All @@ -256,6 +259,8 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
'Currency code EUR in fixture ' . $storeCodeFromFixture . ' is unexpected'
);

$this->flushPageCache();

// test non cached store + currency header in USD
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'USD'];
$response = $this->graphQlQuery($query, [], '', $headerMap);
Expand All @@ -270,42 +275,41 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
'Currency code USD in fixture ' . $storeCodeFromFixture . ' is unexpected'
);

$this->flushPageCache();

// test non cached store + currency header in USD not cached
$headerMap = ['Store' => 'default', 'Content-Currency' => 'EUR'];
$headerMap = ['Store' => 'default', 'Content-Currency' => 'USD'];
$response = $this->graphQlQuery($query, [], '', $headerMap);
$this->assertEquals(
'Simple Product',
$response['products']['items'][0]['name'],
'Product name in fixture store is invalid.'
);
$this->assertEquals(
'EUR',
'USD',
$response['products']['items'][0]['price']['minimalPrice']['amount']['currency'],
'Currency code EUR in fixture store default is unexpected'
'Currency code USD in fixture store default is unexpected'
);

// test cached response store + currency header with non existing currency, and no valid response, no cache
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'SOMECURRENCY'];
$this->expectExceptionMessage(
'GraphQL response contains errors: Please correct the target currency'
);
$this->graphQlQuery($query, [], '', $headerMap);
$this->flushPageCache();

// test non cached store + currency header in USD not cached
$headerMap = ['Store' => 'default', 'Content-Currency' => 'USD'];
$headerMap = ['Store' => 'default', 'Content-Currency' => 'EUR'];
$response = $this->graphQlQuery($query, [], '', $headerMap);
$this->assertEquals(
'Simple Product',
$response['products']['items'][0]['name'],
'Product name in fixture store is invalid.'
);
$this->assertEquals(
'USD',
'EUR',
$response['products']['items'][0]['price']['minimalPrice']['amount']['currency'],
'Currency code USD in fixture store default is unexpected'
'Currency code EUR in fixture store default is unexpected'
);

// test non cached store + currency header in USD cached
$this->flushPageCache();

// test non cached store + currency header in USD cached
$headerMap = ['Store' => 'default'];
$response = $this->graphQlQuery($query, [], '', $headerMap);
$this->assertEquals(
Expand All @@ -318,5 +322,22 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
$response['products']['items'][0]['price']['minimalPrice']['amount']['currency'],
'Currency code USD in fixture store default is unexpected'
);

$this->flushPageCache();

// test cached response store + currency header with non existing currency, and no valid response, no cache
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'SOMECURRENCY'];
$this->expectExceptionMessage(
'GraphQL response contains errors: Please correct the target currency'
);

$this->graphQlQuery($query, [], '', $headerMap);
}

protected function flushPageCache(): void
{
/** @var PageCache $fullPageCache */
$fullPageCache = ObjectManager::getInstance()->get(PageCache::class);
$fullPageCache->clean();
}
}

0 comments on commit cfa889e

Please sign in to comment.