Skip to content

Commit

Permalink
magento2/pull/26032: Fix api-functional 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 859307b commit 8aed39f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
namespace Magento\GraphQl\Catalog;

use Magento\TestFramework\ObjectManager;
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
use Magento\TestFramework\TestCase\GraphQlAbstract;

/**
* Class ProductInMultipleStoresTest
* Class for ProductInMultipleStoresTest
*
* @magentoAppIsolation enabled
*/
class ProductInMultipleStoresTest extends GraphQlAbstract
{
Expand Down Expand Up @@ -74,6 +77,13 @@ 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);

//use case for default storeCode
$nameInDefaultStore = 'Simple Product';
$headerMapDefault = ['Store' => 'default'];
Expand All @@ -92,12 +102,5 @@ public function testProductFromSpecificAndDefaultStore()
$response['products']['items'][0]['name'],
'Product in the default store should be returned'
);

// 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,34 +271,41 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
);

// 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 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);

// 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 non cached store + currency header in USD cached
// test non cached store + currency header in USD cached
$headerMap = ['Store' => 'default'];
$response = $this->graphQlQuery($query, [], '', $headerMap);
$this->assertEquals(
Expand All @@ -311,12 +318,5 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
$response['products']['items'][0]['price']['minimalPrice']['amount']['currency'],
'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);
}
}

0 comments on commit 8aed39f

Please sign in to comment.