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

Commit

Permalink
Merge pull request #3945 from magento-engcom/graphql-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - GraphQL
  • Loading branch information
sivaschenko authored Mar 26, 2019
2 parents 9d6d4e2 + 05c9b49 commit 0d881fc
Show file tree
Hide file tree
Showing 14 changed files with 445 additions and 8 deletions.
6 changes: 4 additions & 2 deletions app/code/Magento/DirectoryGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ type Query {
type Currency {
base_currency_code: String
base_currency_symbol: String
default_display_currecy_code: String
default_display_currecy_symbol: String
default_display_currecy_code: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_code`.")
default_display_currency_code: String
default_display_currecy_symbol: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_symbol`.")
default_display_currency_symbol: String
available_currency_codes: [String]
exchange_rates: [ExchangeRate]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public function execute(Quote $cart, array $cartItemData): void
{
$sku = $this->extractSku($cartItemData);
$qty = $this->extractQty($cartItemData);
if ($qty <= 0) {
throw new GraphQlInputException(
__('Please enter a number greater than 0 in this field.')
);
}
$customizableOptions = $this->extractCustomizableOptions($cartItemData);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public function __construct(
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
throw new GraphQlInputException(__('Required parameter "cart_id" is missing.'));
}
$maskedCartId = $args['input']['cart_id'];

if (!isset($args['input']['payment_method']['code']) || empty($args['input']['payment_method']['code'])) {
throw new GraphQlInputException(__('Required parameter "payment_method" is missing'));
throw new GraphQlInputException(__('Required parameter "code" for "payment_method" is missing.'));
}
$paymentMethodCode = $args['input']['payment_method']['code'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel;
use Magento\Wishlist\Model\Wishlist;
use Magento\Wishlist\Model\WishlistFactory;
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;

/**
* Fetches the Wishlist data according to the GraphQL schema
Expand Down Expand Up @@ -51,6 +52,10 @@ public function resolve(
) {
$customerId = $context->getUserId();

/* Guest checking */
if (!$customerId && 0 === $customerId) {
throw new GraphQlAuthorizationException(__('The current user cannot perform operations on wishlist'));
}
/** @var Wishlist $wishlist */
$wishlist = $this->wishlistFactory->create();
$this->wishlistResource->load($wishlist, $customerId, 'customer_id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function testGetCurrency()
currency {
base_currency_code
base_currency_symbol
default_display_currecy_code
default_display_currecy_symbol
default_display_currency_code
default_display_currency_symbol
available_currency_codes
exchange_rates {
currency_to
Expand All @@ -36,8 +36,8 @@ public function testGetCurrency()
$this->assertArrayHasKey('currency', $result);
$this->assertArrayHasKey('base_currency_code', $result['currency']);
$this->assertArrayHasKey('base_currency_symbol', $result['currency']);
$this->assertArrayHasKey('default_display_currecy_code', $result['currency']);
$this->assertArrayHasKey('default_display_currecy_symbol', $result['currency']);
$this->assertArrayHasKey('default_display_currency_code', $result['currency']);
$this->assertArrayHasKey('default_display_currency_symbol', $result['currency']);
$this->assertArrayHasKey('available_currency_codes', $result['currency']);
$this->assertArrayHasKey('exchange_rates', $result['currency']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ public function testAddSimpleProductToCart()
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
* @expectedException \Exception
* @expectedExceptionMessage Please enter a number greater than 0 in this field.
*/
public function testAddSimpleProductToCartWithNegativeQty()
{
$sku = 'simple';
$qty = -2;
$maskedQuoteId = $this->getMaskedQuoteId();

$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
$this->graphQlQuery($query);
}

/**
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,39 @@ public function testSetBillingAddressOnNonExistentCart()
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @dataProvider dataProviderSetWithoutRequiredParameters
* @param string $input
* @param string $message
* @throws \Exception
*/
public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message)
{
$maskedQuoteId = $this->assignQuoteToCustomer();
$input = str_replace('cart_id_value', $maskedQuoteId, $input);

$query = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
{$input}
}
) {
cart {
billing_address {
city
}
}
}
}
QUERY;

$this->expectExceptionMessage($message);
$this->graphQlQuery($query);
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down Expand Up @@ -506,4 +539,22 @@ private function assignQuoteToCustomer(
$this->quoteResource->save($quote);
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
}

/**
* @return array
*/
public function dataProviderSetWithoutRequiredParameters()
{
return [
'missed_billing_address' => [
'cart_id: "cart_id_value"',
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!'
. ' was not provided.',
],
'missed_cart_id' => [
'billing_address: {}',
'Required parameter "cart_id" is missing'
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,54 @@ public function testPaymentMethodOnNonExistentCart()
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
* @param string $input
* @param string $message
* @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters
*/
public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message)
{
$query = <<<QUERY
mutation {
setPaymentMethodOnCart(
input: {
{$input}
}
) {
cart {
items {
qty
}
}
}
}
QUERY;
$this->expectExceptionMessage($message);
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}
/**
* @return array
*/
public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array
{
return [
'missed_cart_id' => [
'payment_method: {code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"}',
'Required parameter "cart_id" is missing.'
],
'missed_payment_method' => [
'cart_id: "test"',
'Required parameter "code" for "payment_method" is missing.'
],
'missed_payment_method_code' => [
'cart_id: "test", payment_method: {code: ""}',
'Required parameter "code" for "payment_method" is missing.'
],
];
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,38 @@ public function testSetBillingAddressOnNonExistentCart()
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @dataProvider dataProviderSetWithoutRequiredParameters
* @param string $input
* @param string $message
* @throws \Exception
*/
public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message)
{
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
$input = str_replace('cart_id_value', $maskedQuoteId, $input);

$query = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
{$input}
}
) {
cart {
billing_address {
city
}
}
}
}
QUERY;

$this->expectExceptionMessage($message);
$this->graphQlQuery($query);
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down Expand Up @@ -297,4 +329,22 @@ private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): str

return $this->quoteIdToMaskedId->execute((int)$quote->getId());
}

/**
* @return array
*/
public function dataProviderSetWithoutRequiredParameters()
{
return [
'missed_billing_address' => [
'cart_id: "cart_id_value"',
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!'
. ' was not provided.',
],
'missed_cart_id' => [
'billing_address: {}',
'Required parameter "cart_id" is missing'
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,53 @@ public function testSetPaymentMethodToCustomerCart()
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
* @param string $input
* @param string $message
* @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters
*/
public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message)
{
$query = <<<QUERY
mutation {
setPaymentMethodOnCart(
input: {
{$input}
}
) {
cart {
items {
qty
}
}
}
}
QUERY;
$this->expectExceptionMessage($message);
$this->graphQlQuery($query);
}
/**
* @return array
*/
public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array
{
return [
'missed_cart_id' => [
'payment_method: {code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"}',
'Required parameter "cart_id" is missing.'
],
'missed_payment_method' => [
'cart_id: "test"',
'Required parameter "code" for "payment_method" is missing.'
],
'missed_payment_method_code' => [
'cart_id: "test", payment_method: {code: ""}',
'Required parameter "code" for "payment_method" is missing.'
],
];
}

/**
* @expectedException \Exception
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
Expand Down
Loading

0 comments on commit 0d881fc

Please sign in to comment.