From e95c678c4db2b29fad6bf7f319dcb1f16dd4c15f Mon Sep 17 00:00:00 2001 From: Patrick McLain Date: Tue, 29 Jan 2019 14:03:10 -0500 Subject: [PATCH 1/6] Proposal For setPaymentMethodOnCart Ref #293 --- app/code/Magento/BraintreeGraphQl/README.md | 4 + .../Magento/BraintreeGraphQl/composer.json | 24 ++ .../BraintreeGraphQl/etc/graphql/di.xml | 27 ++ .../Magento/BraintreeGraphQl/etc/module.xml | 10 + .../BraintreeGraphQl/etc/schema.graphqls | 18 + .../Magento/BraintreeGraphQl/registration.php | 10 + .../AdditionalDataBuilderInterface.php | 13 + .../Payment/AdditionalDataBuilderPool.php | 32 ++ .../Payment/DefaultAdditionalDataBuilder.php | 43 +++ .../Model/Cart/Payment/MethodBuilder.php | 62 ++++ .../Cart/Payment/PaymentDataProvider.php | 35 ++ .../Model/Resolver/CartPaymentMethod.php | 58 +++ .../Model/Resolver/SetPaymentMethodOnCart.php | 102 ++++++ .../Magento/QuoteGraphQl/etc/schema.graphqls | 21 ++ composer.json | 1 + composer.lock | 4 +- .../Quote/SetPaymentMethodOnCartTest.php | 335 ++++++++++++++++++ 17 files changed, 797 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/BraintreeGraphQl/README.md create mode 100644 app/code/Magento/BraintreeGraphQl/composer.json create mode 100644 app/code/Magento/BraintreeGraphQl/etc/graphql/di.xml create mode 100644 app/code/Magento/BraintreeGraphQl/etc/module.xml create mode 100644 app/code/Magento/BraintreeGraphQl/etc/schema.graphqls create mode 100644 app/code/Magento/BraintreeGraphQl/registration.php create mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/AdditionalDataBuilderInterface.php create mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/AdditionalDataBuilderPool.php create mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/DefaultAdditionalDataBuilder.php create mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/MethodBuilder.php create mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/PaymentDataProvider.php create mode 100644 app/code/Magento/QuoteGraphQl/Model/Resolver/CartPaymentMethod.php create mode 100644 app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php diff --git a/app/code/Magento/BraintreeGraphQl/README.md b/app/code/Magento/BraintreeGraphQl/README.md new file mode 100644 index 000000000000..f6740e4d250e --- /dev/null +++ b/app/code/Magento/BraintreeGraphQl/README.md @@ -0,0 +1,4 @@ +# BraintreeGraphQl + +**BraintreeGraphQl** provides type and resolver for method additional +information. \ No newline at end of file diff --git a/app/code/Magento/BraintreeGraphQl/composer.json b/app/code/Magento/BraintreeGraphQl/composer.json new file mode 100644 index 000000000000..a322db9d257d --- /dev/null +++ b/app/code/Magento/BraintreeGraphQl/composer.json @@ -0,0 +1,24 @@ +{ + "name": "magento/module-braintree-graph-ql", + "description": "N/A", + "type": "magento2-module", + "require": { + "php": "~7.1.3||~7.2.0", + "magento/framework": "*" + }, + "suggest": { + "magento/module-graph-ql": "*" + }, + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\BraintreeGraphQl\\": "" + } + } +} diff --git a/app/code/Magento/BraintreeGraphQl/etc/graphql/di.xml b/app/code/Magento/BraintreeGraphQl/etc/graphql/di.xml new file mode 100644 index 000000000000..3788a0c2f132 --- /dev/null +++ b/app/code/Magento/BraintreeGraphQl/etc/graphql/di.xml @@ -0,0 +1,27 @@ + + + + + + + BraintreeAdditionalDataBuilder + BraintreeVaultAdditionalDataBuilder + + + + + + Magento\Braintree\Model\Ui\ConfigProvider::CODE + + + + + Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE + + + diff --git a/app/code/Magento/BraintreeGraphQl/etc/module.xml b/app/code/Magento/BraintreeGraphQl/etc/module.xml new file mode 100644 index 000000000000..2133e95a6910 --- /dev/null +++ b/app/code/Magento/BraintreeGraphQl/etc/module.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/app/code/Magento/BraintreeGraphQl/etc/schema.graphqls b/app/code/Magento/BraintreeGraphQl/etc/schema.graphqls new file mode 100644 index 000000000000..83c98a68d85e --- /dev/null +++ b/app/code/Magento/BraintreeGraphQl/etc/schema.graphqls @@ -0,0 +1,18 @@ +# Copyright © Magento, Inc. All rights reserved. +# See COPYING.txt for license details. + +input PaymentMethodInput { + braintree: BraintreeInput + braintree_vault: BraintreeVaultInput +} + +input BraintreeInput { + payment_method_nonce: String! + is_active_payment_token_enabler: Boolean! +} + +input BraintreeVaultInput { + payment_method_nonce: String! + public_hash: String! + is_active_payment_token_enabler: Boolean! +} diff --git a/app/code/Magento/BraintreeGraphQl/registration.php b/app/code/Magento/BraintreeGraphQl/registration.php new file mode 100644 index 000000000000..37f7ef30864c --- /dev/null +++ b/app/code/Magento/BraintreeGraphQl/registration.php @@ -0,0 +1,10 @@ +builders = $builders; + } + + public function buildForMethod(string $methodCode, array $args): array + { + $additionalData = []; + if (isset($this->builders[$methodCode])) { + $additionalData = $this->builders[$methodCode]->build($args); + } + + return $additionalData; + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/DefaultAdditionalDataBuilder.php b/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/DefaultAdditionalDataBuilder.php new file mode 100644 index 000000000000..5a032ccc6386 --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/DefaultAdditionalDataBuilder.php @@ -0,0 +1,43 @@ +arrayManager = $arrayManager; + $this->methodCode = $methodCode; + } + + public function build(array $args): array + { + return $this->arrayManager->get($this->getAdditionalDataPath(), $args) ?? []; + } + + private function getAdditionalDataPath(): string + { + return sprintf(static::INPUT_PATH_ADDITIONAL_DATA, $this->methodCode); + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/MethodBuilder.php b/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/MethodBuilder.php new file mode 100644 index 000000000000..110e24d7d0fe --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/MethodBuilder.php @@ -0,0 +1,62 @@ +paymentFactory = $paymentFactory; + $this->additionalDataBuilderPool = $additionalDataBuilderPool; + $this->arrayManager = $arrayManager; + } + + public function build(array $args): PaymentInterface + { + $method = (string) $this->arrayManager->get('input/payment_method/method', $args); + + return $this->paymentFactory->create([ + 'data' => [ + PaymentInterface::KEY_METHOD => $method, + PaymentInterface::KEY_PO_NUMBER => $this->arrayManager->get('input/payment_method/po_number', $args), + PaymentInterface::KEY_ADDITIONAL_DATA => $this->additionalDataBuilderPool->buildForMethod( + $method, + $args + ), + ] + ]); + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/PaymentDataProvider.php b/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/PaymentDataProvider.php new file mode 100644 index 000000000000..22adc69d1cc5 --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/PaymentDataProvider.php @@ -0,0 +1,35 @@ +getPayment(); + if (!$payment) { + return []; + } + + return [ + 'method' => $payment->getMethod(), + 'po_number' => $payment->getPoNumber(), + ]; + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPaymentMethod.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPaymentMethod.php new file mode 100644 index 000000000000..9e75256cd9b2 --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPaymentMethod.php @@ -0,0 +1,58 @@ +paymentDataProvider = $paymentDataProvider; + $this->getCartForUser = $getCartForUser; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + if (!isset($value['cart_id'])) { + throw new LocalizedException(__('"model" value should be specified')); + } + + $maskedCartId = $value['cart_id']; + $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId()); + + return $this->paymentDataProvider->getCartPayment($cart); + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php new file mode 100644 index 000000000000..5e48b3413f7c --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php @@ -0,0 +1,102 @@ +maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; + $this->getCartForUser = $getCartForUser; + $this->arrayManager = $arrayManager; + $this->paymentMethodManagement = $paymentMethodManagement; + $this->methodBuilder = $methodBuilder; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + $paymentMethod = $this->arrayManager->get('input/payment_method', $args); + $maskedCartId = $this->arrayManager->get('input/cart_id', $args); + + if (!$maskedCartId) { + throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); + } + if (!$paymentMethod) { + throw new GraphQlInputException(__('Required parameter "payment_method" is missing')); + } + + $maskedCartId = $args['input']['cart_id']; + $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId()); + + try { + $this->paymentMethodManagement->set($cart->getId(), $this->methodBuilder->build($args)); + } catch (LocalizedException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } + + return [ + 'cart' => [ + 'cart_id' => $maskedCartId, + ], + ]; + } +} diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 4c1101a5f90a..e1dd06f64cf8 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -15,6 +15,17 @@ type Mutation { setBillingAddressOnCart(input: SetBillingAddressOnCartInput): SetBillingAddressOnCartOutput setShippingMethodsOnCart(input: SetShippingMethodsOnCartInput): SetShippingMethodsOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetShippingMethodsOnCart") addSimpleProductsToCart(input: AddSimpleProductsToCartInput): AddSimpleProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart") + setPaymentMethodOnCart(input: SetPaymentMethodOnCartInput): SetPaymentMethodOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentMethodOnCart") +} + +input SetPaymentMethodOnCartInput { + cart_id: String! + payment_method: PaymentMethodInput! +} + +input PaymentMethodInput { + method: String! + po_number: String } input SetShippingAddressesOnCartInput { @@ -64,6 +75,10 @@ input ShippingMethodForAddressInput { shipping_method_code: String! } +type SetPaymentMethodOnCartOutput { + cart: Cart! +} + type SetBillingAddressOnCartOutput { cart: Cart! } @@ -98,6 +113,7 @@ type Cart { items: [CartItemInterface] applied_coupon: AppliedCoupon addresses: [CartAddress]! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartAddresses") + payment_method: CartPaymentMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartPaymentMethod") } type CartAddress { @@ -118,6 +134,11 @@ type CartAddress { cart_items: [CartItemQuantity] } +type CartPaymentMethod { + method: String + po_number: String +} + type CartItemQuantity { cart_item_id: String! quantity: Float! diff --git a/composer.json b/composer.json index 3222de2d1fe0..69924d836b9e 100644 --- a/composer.json +++ b/composer.json @@ -108,6 +108,7 @@ "magento/module-backend": "*", "magento/module-backup": "*", "magento/module-braintree": "*", + "magento/module-braintree-graph-ql": "*", "magento/module-bundle": "*", "magento/module-bundle-graph-ql": "*", "magento/module-bundle-import-export": "*", diff --git a/composer.lock b/composer.lock index 697e7df3e19a..172866d59f4f 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "3f58ddc5609e6a934ee3706006357646", + "content-hash": "bee21a1a1fa89a8a2dc5aedcd087d1e7", "packages": [ { "name": "braintree/braintree_php", diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php new file mode 100644 index 000000000000..cd16123d428b --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php @@ -0,0 +1,335 @@ +quoteResource = $objectManager->create(QuoteResource::class); + $this->quote = $objectManager->create(Quote::class); + $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + $this->config = $objectManager->get(Config::class); + $this->cacheList = $objectManager->get(TypeListInterface::class); + + foreach (static::OFFLINE_METHOD_CODES as $offlineMethodCode) { + $this->config->saveConfig( + 'payment/' . $offlineMethodCode . '/active', + '1', + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + 0 + ); + } + $this->cacheList->cleanType('config'); + } + + /** + * @inheritdoc + */ + protected function tearDown() + { + foreach (static::OFFLINE_METHOD_CODES as $offlineMethodCode) { + //Never no disable checkmo method + if ($offlineMethodCode === Checkmo::PAYMENT_METHOD_CHECKMO_CODE) { + continue; + } + $this->config->saveConfig( + 'payment/' . $offlineMethodCode . '/active', + '0', + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + 0 + ); + } + $this->cacheList->cleanType('config'); + } + + /** + * @param string $methodCode + * @dataProvider dataProviderOfflinePaymentMethods + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentMethodOnCart(string $methodCode) + { + /** @var \Magento\Config\Model\ResourceModel\Config $config */ + $config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); + $config->saveConfig( + 'payment/' . $methodCode . '/active', + 1, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + 0 + ); + + $this->quoteResource->load( + $this->quote, + 'test_order_1', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode + ); + + $response = $this->sendRequestWithToken($query); + + $this->assertArrayHasKey('setPaymentMethodOnCart', $response); + $this->assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); + $this->assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); + $this->assertArrayHasKey('payment_method', $response['setPaymentMethodOnCart']['cart']); + $this->assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['payment_method']['method']); + } + + public function dataProviderOfflinePaymentMethods(): array + { + $methods = []; + foreach (static::OFFLINE_METHOD_CODES as $offlineMethodCode) { + //Purchase order requires additional input and is tested separately + if ($offlineMethodCode === Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE) { + continue; + } + $methods[] = [$offlineMethodCode]; + } + + return $methods; + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetNonExistingPaymentMethod() + { + $paymentMethod = 'noway'; + $this->quoteResource->load( + $this->quote, + 'test_order_1', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $paymentMethod + ); + + $this->expectExceptionMessage('The requested Payment Method is not available.'); + $this->sendRequestWithToken($query); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentMethodByGuestToCustomerCart() + { + $paymentMethod = 'checkmo'; + $this->quoteResource->load( + $this->quote, + 'test_order_1', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $paymentMethod + ); + + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentMethodPurchaseOrderOnCart() + { + $methodCode = \Magento\OfflinePayments\Model\Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE; + $poNumber = 'GQL-19002'; + + /** @var \Magento\Config\Model\ResourceModel\Config $config */ + $config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); + $config->saveConfig( + 'payment/' . $methodCode . '/active', + 1, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + 0 + ); + + $this->quoteResource->load( + $this->quote, + 'test_order_1', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + + $query = <<sendRequestWithToken($query); + + $this->assertArrayHasKey('setPaymentMethodOnCart', $response); + $this->assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); + $this->assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); + $this->assertArrayHasKey('payment_method', $response['setPaymentMethodOnCart']['cart']); + $this->assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['payment_method']['method']); + $this->assertEquals($poNumber, $response['setPaymentMethodOnCart']['cart']['payment_method']['po_number']); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testPurchaseOrderPaymentMethodFailingValidation() + { + $this->quoteResource->load( + $this->quote, + 'test_order_1', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE + ); + + $this->expectExceptionMessage('Purchase order number is a required field.'); + $this->sendRequestWithToken($query); + } + + /** + * Generates query for setting the specified shipping method on cart + * + * @param string $maskedQuoteId + * @param string $methodCode + * @return string + */ + private function prepareMutationQuery( + string $maskedQuoteId, + string $methodCode + ) : string { + return <<customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; + + return $this->graphQlQuery($query, [], '', $headerMap); + } +} From f4f62ea72dcd73fc8100ae31b76d46c6d3b7a11d Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Fri, 22 Feb 2019 16:48:38 -0600 Subject: [PATCH 2/6] GraphQL-293: [Payment methods] Set Payment Method on Cart --- app/code/Magento/BraintreeGraphQl/README.md | 4 -- .../Magento/BraintreeGraphQl/composer.json | 24 ------- .../BraintreeGraphQl/etc/graphql/di.xml | 27 -------- .../Magento/BraintreeGraphQl/etc/module.xml | 10 --- .../BraintreeGraphQl/etc/schema.graphqls | 18 ------ .../Magento/BraintreeGraphQl/registration.php | 10 --- .../AdditionalDataBuilderInterface.php | 13 ---- .../Payment/AdditionalDataBuilderPool.php | 32 ---------- .../Payment/DefaultAdditionalDataBuilder.php | 43 ------------- .../Model/Cart/Payment/MethodBuilder.php | 62 ------------------- .../Cart/Payment/PaymentDataProvider.php | 35 ----------- .../Model/Resolver/CartPaymentMethod.php | 58 ----------------- .../Model/Resolver/SelectedPaymentMethod.php | 42 +++++++++++++ .../Model/Resolver/SetPaymentMethodOnCart.php | 49 +++++++++------ .../Resolver/SetShippingAddressesOnCart.php | 9 ++- .../Magento/QuoteGraphQl/etc/schema.graphqls | 30 +++++---- .../Quote/SetPaymentMethodOnCartTest.php | 12 ++-- 17 files changed, 103 insertions(+), 375 deletions(-) delete mode 100644 app/code/Magento/BraintreeGraphQl/README.md delete mode 100644 app/code/Magento/BraintreeGraphQl/composer.json delete mode 100644 app/code/Magento/BraintreeGraphQl/etc/graphql/di.xml delete mode 100644 app/code/Magento/BraintreeGraphQl/etc/module.xml delete mode 100644 app/code/Magento/BraintreeGraphQl/etc/schema.graphqls delete mode 100644 app/code/Magento/BraintreeGraphQl/registration.php delete mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/AdditionalDataBuilderInterface.php delete mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/AdditionalDataBuilderPool.php delete mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/DefaultAdditionalDataBuilder.php delete mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/MethodBuilder.php delete mode 100644 app/code/Magento/QuoteGraphQl/Model/Cart/Payment/PaymentDataProvider.php delete mode 100644 app/code/Magento/QuoteGraphQl/Model/Resolver/CartPaymentMethod.php create mode 100644 app/code/Magento/QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php diff --git a/app/code/Magento/BraintreeGraphQl/README.md b/app/code/Magento/BraintreeGraphQl/README.md deleted file mode 100644 index f6740e4d250e..000000000000 --- a/app/code/Magento/BraintreeGraphQl/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# BraintreeGraphQl - -**BraintreeGraphQl** provides type and resolver for method additional -information. \ No newline at end of file diff --git a/app/code/Magento/BraintreeGraphQl/composer.json b/app/code/Magento/BraintreeGraphQl/composer.json deleted file mode 100644 index a322db9d257d..000000000000 --- a/app/code/Magento/BraintreeGraphQl/composer.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "magento/module-braintree-graph-ql", - "description": "N/A", - "type": "magento2-module", - "require": { - "php": "~7.1.3||~7.2.0", - "magento/framework": "*" - }, - "suggest": { - "magento/module-graph-ql": "*" - }, - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Magento\\BraintreeGraphQl\\": "" - } - } -} diff --git a/app/code/Magento/BraintreeGraphQl/etc/graphql/di.xml b/app/code/Magento/BraintreeGraphQl/etc/graphql/di.xml deleted file mode 100644 index 3788a0c2f132..000000000000 --- a/app/code/Magento/BraintreeGraphQl/etc/graphql/di.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - BraintreeAdditionalDataBuilder - BraintreeVaultAdditionalDataBuilder - - - - - - Magento\Braintree\Model\Ui\ConfigProvider::CODE - - - - - Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE - - - diff --git a/app/code/Magento/BraintreeGraphQl/etc/module.xml b/app/code/Magento/BraintreeGraphQl/etc/module.xml deleted file mode 100644 index 2133e95a6910..000000000000 --- a/app/code/Magento/BraintreeGraphQl/etc/module.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/app/code/Magento/BraintreeGraphQl/etc/schema.graphqls b/app/code/Magento/BraintreeGraphQl/etc/schema.graphqls deleted file mode 100644 index 83c98a68d85e..000000000000 --- a/app/code/Magento/BraintreeGraphQl/etc/schema.graphqls +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright © Magento, Inc. All rights reserved. -# See COPYING.txt for license details. - -input PaymentMethodInput { - braintree: BraintreeInput - braintree_vault: BraintreeVaultInput -} - -input BraintreeInput { - payment_method_nonce: String! - is_active_payment_token_enabler: Boolean! -} - -input BraintreeVaultInput { - payment_method_nonce: String! - public_hash: String! - is_active_payment_token_enabler: Boolean! -} diff --git a/app/code/Magento/BraintreeGraphQl/registration.php b/app/code/Magento/BraintreeGraphQl/registration.php deleted file mode 100644 index 37f7ef30864c..000000000000 --- a/app/code/Magento/BraintreeGraphQl/registration.php +++ /dev/null @@ -1,10 +0,0 @@ -builders = $builders; - } - - public function buildForMethod(string $methodCode, array $args): array - { - $additionalData = []; - if (isset($this->builders[$methodCode])) { - $additionalData = $this->builders[$methodCode]->build($args); - } - - return $additionalData; - } -} diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/DefaultAdditionalDataBuilder.php b/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/DefaultAdditionalDataBuilder.php deleted file mode 100644 index 5a032ccc6386..000000000000 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/DefaultAdditionalDataBuilder.php +++ /dev/null @@ -1,43 +0,0 @@ -arrayManager = $arrayManager; - $this->methodCode = $methodCode; - } - - public function build(array $args): array - { - return $this->arrayManager->get($this->getAdditionalDataPath(), $args) ?? []; - } - - private function getAdditionalDataPath(): string - { - return sprintf(static::INPUT_PATH_ADDITIONAL_DATA, $this->methodCode); - } -} diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/MethodBuilder.php b/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/MethodBuilder.php deleted file mode 100644 index 110e24d7d0fe..000000000000 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/MethodBuilder.php +++ /dev/null @@ -1,62 +0,0 @@ -paymentFactory = $paymentFactory; - $this->additionalDataBuilderPool = $additionalDataBuilderPool; - $this->arrayManager = $arrayManager; - } - - public function build(array $args): PaymentInterface - { - $method = (string) $this->arrayManager->get('input/payment_method/method', $args); - - return $this->paymentFactory->create([ - 'data' => [ - PaymentInterface::KEY_METHOD => $method, - PaymentInterface::KEY_PO_NUMBER => $this->arrayManager->get('input/payment_method/po_number', $args), - PaymentInterface::KEY_ADDITIONAL_DATA => $this->additionalDataBuilderPool->buildForMethod( - $method, - $args - ), - ] - ]); - } -} diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/PaymentDataProvider.php b/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/PaymentDataProvider.php deleted file mode 100644 index 22adc69d1cc5..000000000000 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/Payment/PaymentDataProvider.php +++ /dev/null @@ -1,35 +0,0 @@ -getPayment(); - if (!$payment) { - return []; - } - - return [ - 'method' => $payment->getMethod(), - 'po_number' => $payment->getPoNumber(), - ]; - } -} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPaymentMethod.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPaymentMethod.php deleted file mode 100644 index 9e75256cd9b2..000000000000 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartPaymentMethod.php +++ /dev/null @@ -1,58 +0,0 @@ -paymentDataProvider = $paymentDataProvider; - $this->getCartForUser = $getCartForUser; - } - - /** - * @inheritdoc - */ - public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) - { - if (!isset($value['cart_id'])) { - throw new LocalizedException(__('"model" value should be specified')); - } - - $maskedCartId = $value['cart_id']; - $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId()); - - return $this->paymentDataProvider->getCartPayment($cart); - } -} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php new file mode 100644 index 000000000000..5d6aed15821f --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php @@ -0,0 +1,42 @@ +getPayment(); + if (!$payment) { + return []; + } + + return [ + 'code' => $payment->getMethod(), + 'po_number' => $payment->getPoNumber(), + ]; + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php index 5e48b3413f7c..82709de03b9b 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php @@ -13,21 +13,16 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\Stdlib\ArrayManager; -use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; +use Magento\Quote\Api\Data\PaymentInterface; use Magento\QuoteGraphQl\Model\Cart\GetCartForUser; +use Magento\Quote\Api\Data\PaymentInterfaceFactory; use Magento\Quote\Api\PaymentMethodManagementInterface; -use Magento\QuoteGraphQl\Model\Cart\Payment\MethodBuilder; /** * Mutation resolver for setting payment method for shopping cart */ class SetPaymentMethodOnCart implements ResolverInterface { - /** - * @var MaskedQuoteIdToQuoteIdInterface - */ - private $maskedQuoteIdToQuoteId; - /** * @var GetCartForUser */ @@ -44,29 +39,26 @@ class SetPaymentMethodOnCart implements ResolverInterface private $paymentMethodManagement; /** - * @var MethodBuilder + * @var PaymentInterfaceFactory */ - private $methodBuilder; + private $paymentFactory; /** - * @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId * @param GetCartForUser $getCartForUser * @param ArrayManager $arrayManager * @param PaymentMethodManagementInterface $paymentMethodManagement - * @param MethodBuilder $methodBuilder + * @param PaymentInterfaceFactory $paymentFactory */ public function __construct( - MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId, GetCartForUser $getCartForUser, ArrayManager $arrayManager, PaymentMethodManagementInterface $paymentMethodManagement, - MethodBuilder $methodBuilder + PaymentInterfaceFactory $paymentFactory ) { - $this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; $this->getCartForUser = $getCartForUser; $this->arrayManager = $arrayManager; $this->paymentMethodManagement = $paymentMethodManagement; - $this->methodBuilder = $methodBuilder; + $this->paymentFactory = $paymentFactory; } /** @@ -74,21 +66,37 @@ public function __construct( */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { - $paymentMethod = $this->arrayManager->get('input/payment_method', $args); - $maskedCartId = $this->arrayManager->get('input/cart_id', $args); - + $maskedCartId = (string)$this->arrayManager->get('input/cart_id', $args); if (!$maskedCartId) { throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); } + + $paymentMethod = $this->arrayManager->get('input/payment_method', $args); if (!$paymentMethod) { throw new GraphQlInputException(__('Required parameter "payment_method" is missing')); } - $maskedCartId = $args['input']['cart_id']; + $paymentMethodCode = (string) $this->arrayManager->get('input/payment_method/code', $args); + if (!$paymentMethodCode) { + throw new GraphQlInputException(__('Required parameter payment "code" is missing')); + } + + $poNumber = $this->arrayManager->get('input/payment_method/po_number', $args); + if (!$poNumber) { + throw new GraphQlInputException(__('Required parameter payment "po_number" is missing')); + } + $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId()); + $payment = $this->paymentFactory->create([ + 'data' => [ + PaymentInterface::KEY_METHOD => $paymentMethodCode, + PaymentInterface::KEY_PO_NUMBER => $poNumber, + PaymentInterface::KEY_ADDITIONAL_DATA => [], + ] + ]); try { - $this->paymentMethodManagement->set($cart->getId(), $this->methodBuilder->build($args)); + $this->paymentMethodManagement->set($cart->getId(), $payment); } catch (LocalizedException $e) { throw new GraphQlInputException(__($e->getMessage())); } @@ -96,6 +104,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value return [ 'cart' => [ 'cart_id' => $maskedCartId, + 'model' => $cart, ], ]; } diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetShippingAddressesOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetShippingAddressesOnCart.php index ec50bd6ab6ea..a55e2971e0ef 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetShippingAddressesOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetShippingAddressesOnCart.php @@ -7,6 +7,7 @@ namespace Magento\QuoteGraphQl\Model\Resolver; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Query\ResolverInterface; @@ -67,7 +68,7 @@ public function __construct( public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { $shippingAddresses = $this->arrayManager->get('input/shipping_addresses', $args); - $maskedCartId = (string) $this->arrayManager->get('input/cart_id', $args); + $maskedCartId = (string)$this->arrayManager->get('input/cart_id', $args); if (!$maskedCartId) { throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); @@ -79,7 +80,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId()); - $this->setShippingAddressesOnCart->execute($context, $cart, $shippingAddresses); + try { + $this->setShippingAddressesOnCart->execute($context, $cart, $shippingAddresses); + } catch (LocalizedException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } return [ 'cart' => [ diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 2a83b2969d73..78c12f939d8f 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -109,8 +109,12 @@ input SetPaymentMethodOnCartInput { } input PaymentMethodInput { - method: String! - po_number: String + code: String! @doc(description:"Payment method code") + po_number: String! @doc(description:"Purchase order number") + additional_data: PaymentMethodAdditionalDataInput +} + +input PaymentMethodAdditionalDataInput { } type SetPaymentMethodOnCartOutput { @@ -139,8 +143,8 @@ type Cart { applied_coupon: AppliedCoupon shipping_addresses: [CartAddress]! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddresses") billing_address: CartAddress! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\BillingAddress") - available_payment_methods : [PaymentMethod] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AvailablePaymentMethods") @doc(description: "Available payment methods") - payment_method: CartPaymentMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartPaymentMethod") + available_payment_methods : [AvailablePaymentMethod] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AvailablePaymentMethods") @doc(description: "Available payment methods") + selected_payment_method: SelectedPaymentMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SelectedPaymentMethod") } type CartAddress { @@ -154,18 +158,13 @@ type CartAddress { country: CartAddressCountry telephone: String address_type: AdressTypeEnum - selected_shipping_method: SelectedShippingMethod available_shipping_methods: [AvailableShippingMethod] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAdress\\AvailableShippingMethods") + selected_shipping_method: SelectedShippingMethod items_weight: Float customer_notes: String cart_items: [CartItemQuantity] } -type CartPaymentMethod { - method: String - po_number: String -} - type CartItemQuantity { cart_item_id: String! quantity: Float! @@ -197,11 +196,20 @@ type AvailableShippingMethod { price_incl_tax: Float! } -type PaymentMethod { +type AvailablePaymentMethod { code: String @doc(description: "The payment method code") title: String @doc(description: "The payment method title.") } +type SelectedPaymentMethod { + code: String @doc(description: "The payment method code") + po_number: String @doc(description: "The purchase order number.") + additional_data: SelectedPaymentMethodAdditionalData +} + +type SelectedPaymentMethodAdditionalData { +} + enum AdressTypeEnum { SHIPPING BILLING diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php index cd16123d428b..496c3efbbd89 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php @@ -142,7 +142,7 @@ public function testSetPaymentMethodOnCart(string $methodCode) $this->assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); $this->assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); $this->assertArrayHasKey('payment_method', $response['setPaymentMethodOnCart']['cart']); - $this->assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['payment_method']['method']); + $this->assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['payment_method']['code']); } public function dataProviderOfflinePaymentMethods(): array @@ -236,7 +236,7 @@ public function testSetPaymentMethodPurchaseOrderOnCart() { cart_id: "$maskedQuoteId", payment_method: { - method: "$methodCode" + code: "$methodCode" po_number: "$poNumber" } }) { @@ -244,7 +244,7 @@ public function testSetPaymentMethodPurchaseOrderOnCart() cart { cart_id, payment_method { - method + code po_number } } @@ -259,7 +259,7 @@ public function testSetPaymentMethodPurchaseOrderOnCart() $this->assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); $this->assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); $this->assertArrayHasKey('payment_method', $response['setPaymentMethodOnCart']['cart']); - $this->assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['payment_method']['method']); + $this->assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['payment_method']['code']); $this->assertEquals($poNumber, $response['setPaymentMethodOnCart']['cart']['payment_method']['po_number']); } @@ -301,14 +301,14 @@ private function prepareMutationQuery( { cart_id: "$maskedQuoteId", payment_method: { - method: "$methodCode" + code: "$methodCode" } }) { cart { cart_id, payment_method { - method + code } } } From 495c540c55b760a61746835139c14ab51f843c51 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 26 Feb 2019 12:18:47 -0600 Subject: [PATCH 3/6] GraphQL-293: [Payment methods] Set Payment Method on Cart --- .../QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php | 2 +- .../QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php | 5 +---- app/code/Magento/QuoteGraphQl/etc/schema.graphqls | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php index 5d6aed15821f..7a99b04638ac 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php @@ -36,7 +36,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value return [ 'code' => $payment->getMethod(), - 'po_number' => $payment->getPoNumber(), + 'purchase_order_number' => $payment->getPoNumber(), ]; } } diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php index 82709de03b9b..78a841a9cb61 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php @@ -81,10 +81,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__('Required parameter payment "code" is missing')); } - $poNumber = $this->arrayManager->get('input/payment_method/po_number', $args); - if (!$poNumber) { - throw new GraphQlInputException(__('Required parameter payment "po_number" is missing')); - } + $poNumber = $this->arrayManager->get('input/payment_method/purchase_order_number', $args); $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId()); $payment = $this->paymentFactory->create([ diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 78c12f939d8f..41d67020fcf2 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -110,7 +110,7 @@ input SetPaymentMethodOnCartInput { input PaymentMethodInput { code: String! @doc(description:"Payment method code") - po_number: String! @doc(description:"Purchase order number") + purchase_order_number: String @doc(description:"Purchase order number") additional_data: PaymentMethodAdditionalDataInput } @@ -203,7 +203,7 @@ type AvailablePaymentMethod { type SelectedPaymentMethod { code: String @doc(description: "The payment method code") - po_number: String @doc(description: "The purchase order number.") + purchase_order_number: String @doc(description: "The purchase order number.") additional_data: SelectedPaymentMethodAdditionalData } From 287186d61baddc38a64c140e0ee3b20a404e7aaf Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 26 Feb 2019 12:44:27 -0600 Subject: [PATCH 4/6] GraphQL-293: [Payment methods] Set Payment Method on Cart --- .../Quote/SetPaymentMethodOnCartTest.php | 245 +++--------------- 1 file changed, 36 insertions(+), 209 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php index 496c3efbbd89..89e88bd0ce04 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php @@ -7,33 +7,19 @@ namespace Magento\GraphQl\Quote; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\OfflinePayments\Model\Banktransfer; -use Magento\OfflinePayments\Model\Cashondelivery; use Magento\OfflinePayments\Model\Checkmo; -use Magento\OfflinePayments\Model\Purchaseorder; -use Magento\Quote\Model\Quote; +use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; -use Magento\TestFramework\ObjectManager; use Magento\TestFramework\TestCase\GraphQlAbstract; -use Magento\Framework\App\Cache\TypeListInterface; -use Magento\Config\Model\ResourceModel\Config; /** * Test for setting payment methods on cart */ class SetPaymentMethodOnCartTest extends GraphQlAbstract { - private const OFFLINE_METHOD_CODES = [ - Checkmo::PAYMENT_METHOD_CHECKMO_CODE, - Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE, - Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE, - Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE, - ]; - /** * @var CustomerTokenServiceInterface */ @@ -45,139 +31,56 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract private $quoteResource; /** - * @var Quote + * @var QuoteFactory */ - private $quote; + private $quoteFactory; /** * @var QuoteIdToMaskedQuoteIdInterface */ private $quoteIdToMaskedId; - /** - * @var Config - */ - private $config; - - /** - * @var TypeListInterface - */ - private $cacheList; - /** * @inheritdoc */ protected function setUp() { $objectManager = Bootstrap::getObjectManager(); - $this->quoteResource = $objectManager->create(QuoteResource::class); - $this->quote = $objectManager->create(Quote::class); - $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + $this->quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); - $this->config = $objectManager->get(Config::class); - $this->cacheList = $objectManager->get(TypeListInterface::class); - - foreach (static::OFFLINE_METHOD_CODES as $offlineMethodCode) { - $this->config->saveConfig( - 'payment/' . $offlineMethodCode . '/active', - '1', - ScopeConfigInterface::SCOPE_TYPE_DEFAULT, - 0 - ); - } - $this->cacheList->cleanType('config'); } /** - * @inheritdoc - */ - protected function tearDown() - { - foreach (static::OFFLINE_METHOD_CODES as $offlineMethodCode) { - //Never no disable checkmo method - if ($offlineMethodCode === Checkmo::PAYMENT_METHOD_CHECKMO_CODE) { - continue; - } - $this->config->saveConfig( - 'payment/' . $offlineMethodCode . '/active', - '0', - ScopeConfigInterface::SCOPE_TYPE_DEFAULT, - 0 - ); - } - $this->cacheList->cleanType('config'); - } - - /** - * @param string $methodCode - * @dataProvider dataProviderOfflinePaymentMethods * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php */ - public function testSetPaymentMethodOnCart(string $methodCode) + public function testSetPaymentMethodOnCart() { - /** @var \Magento\Config\Model\ResourceModel\Config $config */ - $config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); - $config->saveConfig( - 'payment/' . $methodCode . '/active', - 1, - ScopeConfigInterface::SCOPE_TYPE_DEFAULT, - 0 - ); - - $this->quoteResource->load( - $this->quote, - 'test_order_1', - 'reserved_order_id' - ); - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); - - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $methodCode - ); + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $response = $this->sendRequestWithToken($query); - $this->assertArrayHasKey('setPaymentMethodOnCart', $response); - $this->assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); - $this->assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); - $this->assertArrayHasKey('payment_method', $response['setPaymentMethodOnCart']['cart']); - $this->assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['payment_method']['code']); - } - - public function dataProviderOfflinePaymentMethods(): array - { - $methods = []; - foreach (static::OFFLINE_METHOD_CODES as $offlineMethodCode) { - //Purchase order requires additional input and is tested separately - if ($offlineMethodCode === Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE) { - continue; - } - $methods[] = [$offlineMethodCode]; - } - - return $methods; + self::assertArrayHasKey('setPaymentMethodOnCart', $response); + self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); + self::assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); + self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); + self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); } /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @expectedException \Exception + * @expectedExceptionMessage The requested Payment Method is not available. */ public function testSetNonExistingPaymentMethod() { - $paymentMethod = 'noway'; - $this->quoteResource->load( - $this->quote, - 'test_order_1', - 'reserved_order_id' - ); - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); - - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $paymentMethod - ); + $methodCode = 'noway'; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); - $this->expectExceptionMessage('The requested Payment Method is not available.'); + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $this->sendRequestWithToken($query); } @@ -186,18 +89,10 @@ public function testSetNonExistingPaymentMethod() */ public function testSetPaymentMethodByGuestToCustomerCart() { - $paymentMethod = 'checkmo'; - $this->quoteResource->load( - $this->quote, - 'test_order_1', - 'reserved_order_id' - ); - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + $methodCode = 'checkmo'; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $paymentMethod - ); + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" @@ -206,84 +101,6 @@ public function testSetPaymentMethodByGuestToCustomerCart() $this->graphQlQuery($query); } - /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - */ - public function testSetPaymentMethodPurchaseOrderOnCart() - { - $methodCode = \Magento\OfflinePayments\Model\Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE; - $poNumber = 'GQL-19002'; - - /** @var \Magento\Config\Model\ResourceModel\Config $config */ - $config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); - $config->saveConfig( - 'payment/' . $methodCode . '/active', - 1, - ScopeConfigInterface::SCOPE_TYPE_DEFAULT, - 0 - ); - - $this->quoteResource->load( - $this->quote, - 'test_order_1', - 'reserved_order_id' - ); - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); - - $query = <<sendRequestWithToken($query); - - $this->assertArrayHasKey('setPaymentMethodOnCart', $response); - $this->assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); - $this->assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); - $this->assertArrayHasKey('payment_method', $response['setPaymentMethodOnCart']['cart']); - $this->assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['payment_method']['code']); - $this->assertEquals($poNumber, $response['setPaymentMethodOnCart']['cart']['payment_method']['po_number']); - } - - /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php - */ - public function testPurchaseOrderPaymentMethodFailingValidation() - { - $this->quoteResource->load( - $this->quote, - 'test_order_1', - 'reserved_order_id' - ); - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); - - $query = $this->prepareMutationQuery( - $maskedQuoteId, - Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE - ); - - $this->expectExceptionMessage('Purchase order number is a required field.'); - $this->sendRequestWithToken($query); - } - /** * Generates query for setting the specified shipping method on cart * @@ -307,13 +124,12 @@ private function prepareMutationQuery( cart { cart_id, - payment_method { + selected_payment_method { code } } } } - QUERY; } @@ -326,10 +142,21 @@ private function prepareMutationQuery( */ private function sendRequestWithToken(string $query): array { - $customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; return $this->graphQlQuery($query, [], '', $headerMap); } + + /** + * @param string $reversedQuoteId + * @return string + */ + private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } } From 4cae1af66482f7f67211e3e87d47456f1db3088a Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 26 Feb 2019 17:43:46 -0600 Subject: [PATCH 5/6] GraphQL-293: [Payment methods] Set Payment Method on Cart --- .../Model/Cart/GetCartForUser.php | 10 +- .../SetPaymentMethodOnCartTest.php | 315 ++++++++++++++++++ .../GraphQl/Quote/CreateEmptyCartTest.php | 91 ----- .../Quote/Customer/CreateEmptyCartTest.php | 61 ++++ .../GetAvailablePaymentMethodsTest.php | 102 ++++++ .../Quote/{ => Customer}/GetCartTest.php | 58 ++-- .../SetBillingAddressOnCartTest.php | 177 ++++------ .../Customer/SetPaymentMethodOnCartTest.php | 227 +++++++++++++ .../Quote/GetAvailablePaymentMethodsTest.php | 152 --------- .../Quote/Guest/CreateEmptyCartTest.php | 47 +++ .../Guest/GetAvailablePaymentMethodsTest.php | 90 +++++ .../GraphQl/Quote/Guest/GetCartTest.php | 151 +++++++++ .../Guest/SetBillingAddressOnCartTest.php | 263 +++++++++++++++ .../SetPaymentMethodOnCartTest.php | 83 +++-- .../Quote/SetShippingAddressOnCartTest.php | 2 +- 15 files changed, 1423 insertions(+), 406 deletions(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/OfflinePayments/SetPaymentMethodOnCartTest.php delete mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CreateEmptyCartTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CreateEmptyCartTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php rename dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/{ => Customer}/GetCartTest.php (70%) rename dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/{ => Customer}/SetBillingAddressOnCartTest.php (82%) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php delete mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetAvailablePaymentMethodsTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CreateEmptyCartTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php rename dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/{ => Guest}/SetPaymentMethodOnCartTest.php (59%) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php b/app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php index c3207bf478bb..21df2271cc7f 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php @@ -45,12 +45,12 @@ public function __construct( * Get cart for user * * @param string $cartHash - * @param int|null $userId + * @param int|null $customerId * @return Quote * @throws GraphQlAuthorizationException * @throws GraphQlNoSuchEntityException */ - public function execute(string $cartHash, ?int $userId): Quote + public function execute(string $cartHash, ?int $customerId): Quote { try { $cartId = $this->maskedQuoteIdToQuoteId->execute($cartHash); @@ -69,14 +69,14 @@ public function execute(string $cartHash, ?int $userId): Quote ); } - $customerId = (int)$cart->getCustomerId(); + $cartCustomerId = (int)$cart->getCustomerId(); /* Guest cart, allow operations */ - if (!$customerId) { + if (!$cartCustomerId && null === $customerId) { return $cart; } - if ($customerId !== $userId) { + if ($cartCustomerId !== $customerId) { throw new GraphQlAuthorizationException( __( 'The current user cannot perform operations on cart "%masked_cart_id"', diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/OfflinePayments/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/OfflinePayments/SetPaymentMethodOnCartTest.php new file mode 100644 index 000000000000..3a3e50efa067 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/OfflinePayments/SetPaymentMethodOnCartTest.php @@ -0,0 +1,315 @@ +quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + $this->config = $objectManager->get(Config::class); + $this->cacheList = $objectManager->get(TypeListInterface::class); + + foreach (static::OFFLINE_METHOD_CODES as $offlineMethodCode) { + $this->config->saveConfig( + 'payment/' . $offlineMethodCode . '/active', + '1', + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + 0 + ); + } + $this->cacheList->cleanType('config'); + } + + /** + * @inheritdoc + */ + protected function tearDown() + { +// foreach (static::OFFLINE_METHOD_CODES as $offlineMethodCode) { +// //Never no disable checkmo method +// if ($offlineMethodCode === Checkmo::PAYMENT_METHOD_CHECKMO_CODE) { +// continue; +// } +// $this->config->saveConfig( +// 'payment/' . $offlineMethodCode . '/active', +// '0', +// ScopeConfigInterface::SCOPE_TYPE_DEFAULT, +// 0 +// ); +// } +// $this->cacheList->cleanType('config'); + } + + /** + * @param string $methodCode + * @dataProvider dataProviderOfflinePaymentMethods + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentMethodOnCart(string $methodCode) + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $methodCode + ); + + $response = $this->sendRequestWithToken($query); + + self::assertArrayHasKey('setPaymentMethodOnCart', $response); + self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); + self::assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); + self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); + self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); + } + + public function dataProviderOfflinePaymentMethods(): array + { + $methods = []; + foreach (static::OFFLINE_METHOD_CODES as $offlineMethodCode) { + //Purchase order requires additional input and is tested separately + if ($offlineMethodCode === Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE) { + continue; + } + $methods[] = [$offlineMethodCode]; + } + + return $methods; + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetNonExistingPaymentMethod() + { + $paymentMethod = 'noway'; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $paymentMethod + ); + + $this->expectExceptionMessage('The requested Payment Method is not available.'); + $this->sendRequestWithToken($query); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentMethodByGuestToCustomerCart() + { + $paymentMethod = 'checkmo'; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + $paymentMethod + ); + + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentMethodPurchaseOrderOnCart() + { + $methodCode = \Magento\OfflinePayments\Model\Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE; + $poNumber = 'GQL-19002'; + + /** @var \Magento\Config\Model\ResourceModel\Config $config */ + $config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); + $config->saveConfig( + 'payment/' . $methodCode . '/active', + 1, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + 0 + ); + + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + + $query = <<sendRequestWithToken($query); + + self::assertArrayHasKey('setPaymentMethodOnCart', $response); + self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); + self::assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); + self::assertArrayHasKey('payment_method', $response['setPaymentMethodOnCart']['cart']); + self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); + self::assertEquals( + $poNumber, + $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['purchase_order_number'] + ); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testPurchaseOrderPaymentMethodFailingValidation() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + + $query = $this->prepareMutationQuery( + $maskedQuoteId, + Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE + ); + + $this->expectExceptionMessage('Purchase order number is a required field.'); + $this->sendRequestWithToken($query); + } + + /** + * Generates query for setting the specified shipping method on cart + * + * @param string $maskedQuoteId + * @param string $methodCode + * @return string + */ + private function prepareMutationQuery( + string $maskedQuoteId, + string $methodCode + ) : string { + return <<customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; + + return $this->graphQlQuery($query, [], '', $headerMap); + } + + /** + * @param string $reversedQuoteId + * @return string + */ + private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CreateEmptyCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CreateEmptyCartTest.php deleted file mode 100644 index 6e819b523ec8..000000000000 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CreateEmptyCartTest.php +++ /dev/null @@ -1,91 +0,0 @@ -objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $this->quoteIdMask = $this->objectManager->create(QuoteIdMask::class); - $this->guestCartRepository = $this->objectManager->create(GuestCartRepositoryInterface::class); - } - - public function testCreateEmptyCartForGuest() - { - $query = <<graphQlQuery($query); - - self::assertArrayHasKey('createEmptyCart', $response); - - $maskedCartId = $response['createEmptyCart']; - /** @var CartInterface $guestCart */ - $guestCart = $this->guestCartRepository->get($maskedCartId); - - self::assertNotNull($guestCart->getId()); - self::assertNull($guestCart->getCustomer()->getId()); - } - - /** - * @magentoApiDataFixture Magento/Customer/_files/customer.php - */ - public function testCreateEmptyCartForRegisteredCustomer() - { - $query = <<objectManager->create( - \Magento\Integration\Api\CustomerTokenServiceInterface::class - ); - $customerToken = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); - $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; - - $response = $this->graphQlQuery($query, [], '', $headerMap); - - self::assertArrayHasKey('createEmptyCart', $response); - - $maskedCartId = $response['createEmptyCart']; - /* guestCartRepository is used for registered customer to get the cart hash */ - $guestCart = $this->guestCartRepository->get($maskedCartId); - - self::assertNotNull($guestCart->getId()); - self::assertEquals(1, $guestCart->getCustomer()->getId()); - } -} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CreateEmptyCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CreateEmptyCartTest.php new file mode 100644 index 000000000000..0cb8a38b0cb5 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CreateEmptyCartTest.php @@ -0,0 +1,61 @@ +guestCartRepository = $objectManager->get(GuestCartRepositoryInterface::class); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testCreateEmptyCart() + { + $query = <<customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; + + $response = $this->graphQlQuery($query, [], '', $headerMap); + + self::assertArrayHasKey('createEmptyCart', $response); + + $maskedCartId = $response['createEmptyCart']; + $guestCart = $this->guestCartRepository->get($maskedCartId); + + self::assertNotNull($guestCart->getId()); + self::assertEquals(1, $guestCart->getCustomer()->getId()); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php new file mode 100644 index 000000000000..b5323ee98658 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php @@ -0,0 +1,102 @@ +quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + */ + public function testGetCartWithPaymentMethods() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); + + $query = <<graphQlQuery($query, [], '', $this->getHeaderMap()); + + self::assertArrayHasKey('cart', $response); + self::assertCount(1, $response['cart']['available_payment_methods']); + self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); + self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); + } + + /** + * @param string $username + * @param string $password + * @return array + */ + private function getHeaderMap(string $username = 'customer@example.com', string $password = 'password'): array + { + $customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password); + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; + return $headerMap; + } + + /** + * @param string $reversedQuoteId + * @return string + */ + private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php similarity index 70% rename from dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetCartTest.php rename to dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php index 6c5add7df6b0..8c1fcce7fb55 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\GraphQl\Quote; +namespace Magento\GraphQl\Quote\Customer; use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\Quote\Model\QuoteFactory; @@ -49,49 +49,62 @@ protected function setUp() } /** - * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php */ - public function testGetCartForGuest() + public function testGetCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); $query = $this->getCartQuery($maskedQuoteId); - $response = $this->graphQlQuery($query); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); self::assertArrayHasKey('cart', $response); self::assertEquals($maskedQuoteId, $response['cart']['cart_id']); + + self::assertArrayHasKey('items', $response['cart']); + self::assertCount(2, $response['cart']['items']); + + self::assertNotEmpty($response['cart']['items'][0]['id']); + self::assertEquals($response['cart']['items'][0]['qty'], 2); + self::assertEquals($response['cart']['items'][0]['product']['sku'], 'simple'); + + self::assertNotEmpty($response['cart']['items'][1]['id']); + self::assertEquals($response['cart']['items'][1]['qty'], 1); + self::assertEquals($response['cart']['items'][1]['product']['sku'], 'simple_one'); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php */ - public function testGetCartByRegisteredCustomer() + public function testGetGuestCart() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); $query = $this->getCartQuery($maskedQuoteId); - $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); - - self::assertArrayHasKey('cart', $response); - self::assertEquals($maskedQuoteId, $response['cart']['cart_id']); - self::assertNotEmpty($response['cart']['items']); + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"{$maskedQuoteId}\"" + ); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** + * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php */ - public function testGetCartOfAnotherCustomerByGuest() + public function testGetCartIfCustomerIsNotOwnerOfCart() { $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); $query = $this->getCartQuery($maskedQuoteId); - self:$this->expectExceptionMessage( + $this->expectExceptionMessage( "The current user cannot perform operations on cart \"{$maskedQuoteId}\"" ); - $this->graphQlQuery($query); + $this->graphQlQuery($query, [], '', $this->getHeaderMap('customer2@search.example.com')); } /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php * @expectedException \Exception * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ @@ -100,7 +113,7 @@ public function testGetNonExistentCart() $maskedQuoteId = 'non_existent_masked_id'; $query = $this->getCartQuery($maskedQuoteId); - $this->graphQlQuery($query); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** @@ -114,15 +127,12 @@ private function getCartQuery( { cart(cart_id: "$maskedQuoteId") { cart_id - applied_coupon { - code - } items { id - } - shipping_addresses { - firstname, - lastname + qty + product { + sku + } } } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php similarity index 82% rename from dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetBillingAddressOnCartTest.php rename to dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index bfe57109d107..d244fcb27f02 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -5,17 +5,14 @@ */ declare(strict_types=1); -namespace Magento\GraphQl\Quote; +namespace Magento\GraphQl\Quote\Customer; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Integration\Api\CustomerTokenServiceInterface; -use Magento\Multishipping\Helper\Data; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; -use Magento\TestFramework\ObjectManager; /** * Test for set billing address on cart mutation @@ -53,10 +50,11 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php */ - public function testSetNewBillingAddressByGuest() + public function testSetNewBillingAddress() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->assignQuoteToCustomer(); $query = <<graphQlQuery($query); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); $cartResponse = $response['setBillingAddressOnCart']['cart']; @@ -104,10 +102,11 @@ public function testSetNewBillingAddressByGuest() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php */ - public function testSetNewBillingAddressWithUseForShippingParameterByGuest() + public function testSetNewBillingAddressWithUseForShippingParameter() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->assignQuoteToCustomer(); $query = <<graphQlQuery($query); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); $cartResponse = $response['setBillingAddressOnCart']['cart']; @@ -168,12 +167,12 @@ public function testSetNewBillingAddressWithUseForShippingParameterByGuest() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php - * @expectedException \Exception - * @expectedExceptionMessage The current customer isn't authorized. + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php */ - public function testSetBillingAddressFromAddressBookByGuest() + public function testSetBillingAddressFromAddressBook() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->assignQuoteToCustomer(); $query = <<graphQlQuery($query); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + + self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); + $cartResponse = $response['setBillingAddressOnCart']['cart']; + self::assertArrayHasKey('billing_address', $cartResponse); + $billingAddressResponse = $cartResponse['billing_address']; + $this->assertSavedBillingAddressFields($billingAddressResponse); } /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @expectedException \Exception + * @expectedExceptionMessage Could not find a address with ID "100" */ - public function testSetNewBillingAddressByRegisteredCustomer() + public function testSetNotExistedBillingAddressFromAddressBook() { $maskedQuoteId = $this->assignQuoteToCustomer(); @@ -210,42 +223,19 @@ public function testSetNewBillingAddressByRegisteredCustomer() input: { cart_id: "$maskedQuoteId" billing_address: { - address: { - firstname: "test firstname" - lastname: "test lastname" - company: "test company" - street: ["test street 1", "test street 2"] - city: "test city" - region: "test region" - postcode: "887766" - country_code: "US" - telephone: "88776655" - save_in_address_book: false - } - } + customer_address_id: 100 + } } ) { cart { billing_address { - firstname - lastname - company - street city - postcode - telephone } } } } QUERY; - $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); - - self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); - $cartResponse = $response['setBillingAddressOnCart']['cart']; - self::assertArrayHasKey('billing_address', $cartResponse); - $billingAddressResponse = $cartResponse['billing_address']; - $this->assertNewAddressFields($billingAddressResponse); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** @@ -253,7 +243,7 @@ public function testSetNewBillingAddressByRegisteredCustomer() * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php */ - public function testSetBillingAddressFromAddressBookByRegisteredCustomer() + public function testSetNewBillingAddressAndFromAddressBookAtSameTime() { $maskedQuoteId = $this->assignQuoteToCustomer(); @@ -263,42 +253,45 @@ public function testSetBillingAddressFromAddressBookByRegisteredCustomer() input: { cart_id: "$maskedQuoteId" billing_address: { - customer_address_id: 1 - } + customer_address_id: 1 + address: { + firstname: "test firstname" + lastname: "test lastname" + company: "test company" + street: ["test street 1", "test street 2"] + city: "test city" + region: "test region" + postcode: "887766" + country_code: "US" + telephone: "88776655" + save_in_address_book: false + } + } } ) { cart { billing_address { - firstname - lastname - company - street city - postcode - telephone } } } } QUERY; - $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); - self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); - $cartResponse = $response['setBillingAddressOnCart']['cart']; - self::assertArrayHasKey('billing_address', $cartResponse); - $billingAddressResponse = $cartResponse['billing_address']; - $this->assertSavedBillingAddressFields($billingAddressResponse); + self::expectExceptionMessage( + 'The billing address cannot contain "customer_address_id" and "address" at the same time.' + ); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @expectedException \Exception - * @expectedExceptionMessage Could not find a address with ID "100" + * @magentoApiDataFixture Magento/Customer/_files/customer_address.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php */ - public function testSetNotExistedBillingAddressFromAddressBook() + public function testSetBillingAddressToGuestCart() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); $query = <<expectExceptionMessage( + "The current user cannot perform operations on cart \"{$maskedQuoteId}\"" + ); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** + * @magentoApiDataFixture Magento/Customer/_files/three_customers.php + * @magentoApiDataFixture Magento/Customer/_files/customer_address.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php - * @magentoApiDataFixture Magento/Customer/_files/customer.php - * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php */ - public function testSetNewBillingAddressAndFromAddressBookAtSameTime() + public function testSetBillingAddressIfCustomerIsNotOwnerOfCart() { - $maskedQuoteId = $this->assignQuoteToCustomer(); + $maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 2); $query = <<expectExceptionMessage( + "The current user cannot perform operations on cart \"{$maskedQuoteId}\"" ); - $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + + $this->graphQlQuery($query, [], '', $this->getHeaderMap('customer@search.example.com')); } /** @@ -376,7 +361,7 @@ public function testSetNewBillingAddressAndFromAddressBookAtSameTime() */ public function testSetBillingAddressIfCustomerIsNotOwnerOfAddress() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 2); $query = <<quoteResource->save($quote); return $this->quoteIdToMaskedId->execute((int)$quote->getId()); } - - public function tearDown() - { - /** @var \Magento\Config\Model\ResourceModel\Config $config */ - $config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); - - //default state of multishipping config - $config->saveConfig( - Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE, - 1, - ScopeConfigInterface::SCOPE_TYPE_DEFAULT, - 0 - ); - - /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ - $config = ObjectManager::getInstance()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); - $config->reinit(); - } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php new file mode 100644 index 000000000000..8856b2ab44c2 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php @@ -0,0 +1,227 @@ +quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + */ + public function testSetPaymentWithVirtualProduct() + { + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_virtual_product'); + + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + + self::assertArrayHasKey('setPaymentMethodOnCart', $response); + self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); + self::assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); + self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); + self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentWithSimpleProduct() + { + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + + self::assertArrayHasKey('setPaymentMethodOnCart', $response); + self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); + self::assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); + self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); + self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @expectedException \Exception + * @expectedExceptionMessage The shipping address is missing. Set the address and try again. + */ + public function testSetPaymentWithSimpleProductWithoutAddress() + { + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 1); + + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @expectedException \Exception + * @expectedExceptionMessage The requested Payment Method is not available. + */ + public function testSetNonExistingPaymentMethod() + { + $methodCode = 'noway'; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + */ + public function testSetPaymentMethodToGuestCart() + { + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + + $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/three_customers.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentMethodIfCustomerIsNotOwnerOfCart() + { + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + + $this->graphQlQuery($query, [], '', $this->getHeaderMap('customer2@search.example.com')); + } + + /** + * Generates query for setting the specified shipping method on cart + * + * @param string $maskedQuoteId + * @param string $methodCode + * @return string + */ + private function prepareMutationQuery( + string $maskedQuoteId, + string $methodCode + ) : string { + return <<quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } + + /** + * @param string $reversedQuoteId + * @param int $customerId + * @return string + */ + private function assignQuoteToCustomer( + string $reversedQuoteId, + int $customerId + ): string { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $quote->setCustomerId($customerId); + $this->quoteResource->save($quote); + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } + + /** + * @param string $username + * @param string $password + * @return array + */ + private function getHeaderMap(string $username = 'customer@example.com', string $password = 'password'): array + { + $customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password); + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; + return $headerMap; + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetAvailablePaymentMethodsTest.php deleted file mode 100644 index d6eff6816b34..000000000000 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetAvailablePaymentMethodsTest.php +++ /dev/null @@ -1,152 +0,0 @@ -quoteResource = $objectManager->create(QuoteResource::class); - $this->quote = $objectManager->create(Quote::class); - $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); - $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); - } - - /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php - */ - public function testGetCartWithPaymentMethodsForRegisteredCustomer() - { - $reservedOrderId = 'test_order_item_with_items'; - $this->quoteResource->load( - $this->quote, - $reservedOrderId, - 'reserved_order_id' - ); - - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); - $query = $this->prepareGetCartQuery($maskedQuoteId); - - $response = $this->sendRequestWithToken($query); - - self::assertArrayHasKey('cart', $response); - self::assertNotEmpty($response['cart']['items']); - self::assertNotEmpty($response['cart']['available_payment_methods']); - self::assertCount(1, $response['cart']['available_payment_methods']); - self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); - self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); - } - - /** - * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php - */ - public function testGetCartWithPaymentMethodsForGuest() - { - $reservedOrderId = 'test_order_1'; - $this->quoteResource->load( - $this->quote, - $reservedOrderId, - 'reserved_order_id' - ); - - $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); - $query = $this->prepareGetCartQuery($maskedQuoteId); - - $response = $this->graphQlQuery($query); - - self::assertArrayHasKey('cart', $response); - - self::assertNotEmpty($response['cart']['available_payment_methods']); - self::assertCount(2, $response['cart']['available_payment_methods']); - self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); - self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); - self::assertEquals('free', $response['cart']['available_payment_methods'][1]['code']); - self::assertEquals( - 'No Payment Information Required', - $response['cart']['available_payment_methods'][1]['title'] - ); - } - - /** - * Generates query for setting the specified shipping method on cart - * - * @param string $maskedQuoteId - * @return string - */ - private function prepareGetCartQuery( - string $maskedQuoteId - ) : string { - return <<customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); - $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; - - return $this->graphQlQuery($query, [], '', $headerMap); - } -} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CreateEmptyCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CreateEmptyCartTest.php new file mode 100644 index 000000000000..4fd398439913 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CreateEmptyCartTest.php @@ -0,0 +1,47 @@ +guestCartRepository = $objectManager->get(GuestCartRepositoryInterface::class); + } + + public function testCreateEmptyCart() + { + $query = <<graphQlQuery($query); + + self::assertArrayHasKey('createEmptyCart', $response); + + $maskedCartId = $response['createEmptyCart']; + $guestCart = $this->guestCartRepository->get($maskedCartId); + + self::assertNotNull($guestCart->getId()); + self::assertNull($guestCart->getCustomer()->getId()); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php new file mode 100644 index 000000000000..d4459180bc16 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php @@ -0,0 +1,90 @@ +quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + */ + public function testGetCartWithPaymentMethods() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + + $query = <<graphQlQuery($query); + + self::assertArrayHasKey('cart', $response); + self::assertCount(2, $response['cart']['available_payment_methods']); + + self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); + self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); + + self::assertEquals('free', $response['cart']['available_payment_methods'][1]['code']); + self::assertEquals( + 'No Payment Information Required', + $response['cart']['available_payment_methods'][1]['title'] + ); + } + + /** + * @param string $reversedQuoteId + * @return string + */ + private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php new file mode 100644 index 000000000000..42b5cbd06b9f --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartTest.php @@ -0,0 +1,151 @@ +quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + */ + public function testGetCart() + { + $maskedQuoteId = $this->unAssignCustomerFromQuote('test_order_item_with_items'); + $query = $this->getCartQuery($maskedQuoteId); + + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('cart', $response); + self::assertEquals($maskedQuoteId, $response['cart']['cart_id']); + + self::assertArrayHasKey('items', $response['cart']); + self::assertCount(2, $response['cart']['items']); + + self::assertNotEmpty($response['cart']['items'][0]['id']); + self::assertEquals($response['cart']['items'][0]['qty'], 2); + self::assertEquals($response['cart']['items'][0]['product']['sku'], 'simple'); + + self::assertNotEmpty($response['cart']['items'][1]['id']); + self::assertEquals($response['cart']['items'][1]['qty'], 1); + self::assertEquals($response['cart']['items'][1]['product']['sku'], 'simple_one'); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + */ + public function testGetCustomerCart() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); + $query = $this->getCartQuery($maskedQuoteId); + + $this->expectExceptionMessage( + "The current user cannot perform operations on cart \"{$maskedQuoteId}\"" + ); + $this->graphQlQuery($query); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" + */ + public function testGetNonExistentCart() + { + $maskedQuoteId = 'non_existent_masked_id'; + $query = $this->getCartQuery($maskedQuoteId); + + $this->graphQlQuery($query); + } + + /** + * @param string $maskedQuoteId + * @return string + */ + private function getCartQuery( + string $maskedQuoteId + ) : string { + return <<quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } + + /** + * @param string $reversedQuoteId + * @param int $customerId + * @return string + */ + private function unAssignCustomerFromQuote( + string $reversedQuoteId + ): string { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $quote->setCustomerId(0); + $this->quoteResource->save($quote); + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php new file mode 100644 index 000000000000..98c2fe81f82a --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -0,0 +1,263 @@ +quoteResource = $objectManager->get(QuoteResource::class); + $this->quoteFactory = $objectManager->get(QuoteFactory::class); + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + */ + public function testSetNewBillingAddress() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + + $query = <<graphQlQuery($query); + + self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); + $cartResponse = $response['setBillingAddressOnCart']['cart']; + self::assertArrayHasKey('billing_address', $cartResponse); + $billingAddressResponse = $cartResponse['billing_address']; + $this->assertNewAddressFields($billingAddressResponse); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + */ + public function testSetNewBillingAddressWithUseForShippingParameter() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + + $query = <<graphQlQuery($query); + + self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); + $cartResponse = $response['setBillingAddressOnCart']['cart']; + self::assertArrayHasKey('billing_address', $cartResponse); + $billingAddressResponse = $cartResponse['billing_address']; + self::assertArrayHasKey('shipping_addresses', $cartResponse); + $shippingAddressResponse = current($cartResponse['shipping_addresses']); + $this->assertNewAddressFields($billingAddressResponse); + $this->assertNewAddressFields($shippingAddressResponse); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSettBillingAddressToCustomerCart() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + + $query = <<expectExceptionMessage( + "The current user cannot perform operations on cart \"$maskedQuoteId\"" + ); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @expectedException \Exception + * @expectedExceptionMessage The current customer isn't authorized. + */ + public function testSetBillingAddressFromAddressBook() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + + $query = <<graphQlQuery($query); + } + + /** + * Verify the all the whitelisted fields for a New Address Object + * + * @param array $billingAddressResponse + */ + private function assertNewAddressFields(array $billingAddressResponse): void + { + $assertionMap = [ + ['response_field' => 'firstname', 'expected_value' => 'test firstname'], + ['response_field' => 'lastname', 'expected_value' => 'test lastname'], + ['response_field' => 'company', 'expected_value' => 'test company'], + ['response_field' => 'street', 'expected_value' => [0 => 'test street 1', 1 => 'test street 2']], + ['response_field' => 'city', 'expected_value' => 'test city'], + ['response_field' => 'postcode', 'expected_value' => '887766'], + ['response_field' => 'telephone', 'expected_value' => '88776655'] + ]; + + $this->assertResponseFields($billingAddressResponse, $assertionMap); + } + + /** + * @param string $reversedQuoteId + * @return string + */ + private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string + { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php similarity index 59% rename from dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php rename to dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php index 89e88bd0ce04..8286f9714895 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetPaymentMethodOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php @@ -5,9 +5,8 @@ */ declare(strict_types=1); -namespace Magento\GraphQl\Quote; +namespace Magento\GraphQl\Quote\Guest; -use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\OfflinePayments\Model\Checkmo; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; @@ -16,15 +15,10 @@ use Magento\TestFramework\TestCase\GraphQlAbstract; /** - * Test for setting payment methods on cart + * Test for setting payment methods on cart by guest */ class SetPaymentMethodOnCartTest extends GraphQlAbstract { - /** - * @var CustomerTokenServiceInterface - */ - private $customerTokenService; - /** * @var QuoteResource */ @@ -49,19 +43,38 @@ protected function setUp() $this->quoteResource = $objectManager->get(QuoteResource::class); $this->quoteFactory = $objectManager->get(QuoteFactory::class); $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); - $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + */ + public function testSetPaymentWithVirtualProduct() + { + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_virtual_product'); + $this->unAssignCustomerFromQuote('test_order_with_virtual_product'); + + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('setPaymentMethodOnCart', $response); + self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); + self::assertEquals($maskedQuoteId, $response['setPaymentMethodOnCart']['cart']['cart_id']); + self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); + self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); } /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php */ - public function testSetPaymentMethodOnCart() + public function testSetPaymentWithSimpleProduct() { $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $this->unAssignCustomerFromQuote('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); - $response = $this->sendRequestWithToken($query); + $response = $this->graphQlQuery($query); self::assertArrayHasKey('setPaymentMethodOnCart', $response); self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); @@ -70,6 +83,20 @@ public function testSetPaymentMethodOnCart() self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @expectedException \Exception + * @expectedExceptionMessage The shipping address is missing. Set the address and try again. + */ + public function testSetPaymentWithSimpleProductWithoutAddress() + { + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; + $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + + $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); + $this->graphQlQuery($query); + } + /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php * @expectedException \Exception @@ -79,17 +106,18 @@ public function testSetNonExistingPaymentMethod() { $methodCode = 'noway'; $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); + $this->unAssignCustomerFromQuote('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); - $this->sendRequestWithToken($query); + $this->graphQlQuery($query); } /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php */ - public function testSetPaymentMethodByGuestToCustomerCart() + public function testSetPaymentMethodToCustomerCart() { - $methodCode = 'checkmo'; + $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1'); $query = $this->prepareMutationQuery($maskedQuoteId, $methodCode); @@ -97,7 +125,6 @@ public function testSetPaymentMethodByGuestToCustomerCart() $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); - $this->graphQlQuery($query); } @@ -116,9 +143,9 @@ private function prepareMutationQuery( mutation { setPaymentMethodOnCart(input: { - cart_id: "$maskedQuoteId", + cart_id: "{$maskedQuoteId}", payment_method: { - code: "$methodCode" + code: "{$methodCode}" } }) { @@ -134,18 +161,18 @@ private function prepareMutationQuery( } /** - * Sends a GraphQL request with using a bearer token - * - * @param string $query - * @return array - * @throws \Magento\Framework\Exception\AuthenticationException + * @param string $reversedQuoteId + * @param int $customerId + * @return string */ - private function sendRequestWithToken(string $query): array - { - $customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); - $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; - - return $this->graphQlQuery($query, [], '', $headerMap); + private function unAssignCustomerFromQuote( + string $reversedQuoteId + ): string { + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); + $quote->setCustomerId(0); + $this->quoteResource->save($quote); + return $this->quoteIdToMaskedId->execute((int)$quote->getId()); } /** diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php index c3685c88ae48..f73454b0a8b9 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php @@ -422,7 +422,7 @@ public function testSetMultipleNewShippingAddresses() */ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress() { - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); + $maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 2); $query = << Date: Tue, 26 Feb 2019 17:55:57 -0600 Subject: [PATCH 6/6] GraphQL-293: [Payment methods] Set Payment Method on Cart -- Fixes after merge with mainline --- .../Customer/SetBillingAddressOnCartTest.php | 10 ++++++++-- .../Quote/Guest/SetBillingAddressOnCartTest.php | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index 2dd0394dfc6d..2e0b57f96fe3 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -205,6 +205,10 @@ public function testSetBillingAddressFromAddressBook() city postcode telephone + country { + code + label + } } } } @@ -410,7 +414,8 @@ private function assertNewAddressFields(array $billingAddressResponse): void ['response_field' => 'street', 'expected_value' => [0 => 'test street 1', 1 => 'test street 2']], ['response_field' => 'city', 'expected_value' => 'test city'], ['response_field' => 'postcode', 'expected_value' => '887766'], - ['response_field' => 'telephone', 'expected_value' => '88776655'] + ['response_field' => 'telephone', 'expected_value' => '88776655'], + ['response_field' => 'country', 'expected_value' => ['code' => 'US', 'label' => 'US']], ]; $this->assertResponseFields($billingAddressResponse, $assertionMap); @@ -430,7 +435,8 @@ private function assertSavedBillingAddressFields(array $billingAddressResponse): ['response_field' => 'street', 'expected_value' => [0 => 'Green str, 67']], ['response_field' => 'city', 'expected_value' => 'CityM'], ['response_field' => 'postcode', 'expected_value' => '75477'], - ['response_field' => 'telephone', 'expected_value' => '3468676'] + ['response_field' => 'telephone', 'expected_value' => '3468676'], + ['response_field' => 'country', 'expected_value' => ['code' => 'US', 'label' => 'US']], ]; $this->assertResponseFields($billingAddressResponse, $assertionMap); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index 98c2fe81f82a..24fc8353d255 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -78,6 +78,10 @@ public function testSetNewBillingAddress() city postcode telephone + country { + code + label + } } } } @@ -130,6 +134,10 @@ public function testSetNewBillingAddressWithUseForShippingParameter() city postcode telephone + country { + code + label + } } shipping_addresses { firstname @@ -139,6 +147,10 @@ public function testSetNewBillingAddressWithUseForShippingParameter() city postcode telephone + country { + code + label + } } } } @@ -243,7 +255,8 @@ private function assertNewAddressFields(array $billingAddressResponse): void ['response_field' => 'street', 'expected_value' => [0 => 'test street 1', 1 => 'test street 2']], ['response_field' => 'city', 'expected_value' => 'test city'], ['response_field' => 'postcode', 'expected_value' => '887766'], - ['response_field' => 'telephone', 'expected_value' => '88776655'] + ['response_field' => 'telephone', 'expected_value' => '88776655'], + ['response_field' => 'country', 'expected_value' => ['code' => 'US', 'label' => 'US']], ]; $this->assertResponseFields($billingAddressResponse, $assertionMap);