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

Commit

Permalink
ENGCOM-4608: issue #485 [Test coverage] testReSetShippingMethod #496
Browse files Browse the repository at this point in the history
 - Merge Pull Request #496 from magento/graphql-ce:485-testReSetShippingMethod
 - Merged commits:
   1. 4f19d03
   2. 43f5bce
   3. 4bdc30e
   4. f9ecace
   5. 5d9a64e
   6. f01dc00
   7. 16ce046
   8. c2f15b3
   9. 14d5c3d
   10. 2643424
   11. cf4eb72
   12. 829a39b
   13. 4837778
   14. 1c582f1
  • Loading branch information
magento-engcom-team committed Mar 29, 2019
2 parents 70bf7c6 + 1c582f1 commit 7c5769d
Show file tree
Hide file tree
Showing 16 changed files with 577 additions and 118 deletions.
21 changes: 11 additions & 10 deletions app/code/Magento/QuoteGraphQl/Model/Cart/GetQuoteAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace Magento\QuoteGraphQl\Model\Cart;

use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Api\Data\AddressInterfaceFactory;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\ResourceModel\Quote\Address as AddressResource;

/**
Expand Down Expand Up @@ -44,14 +44,14 @@ public function __construct(
/**
* Get quote address
*
* @param CartInterface $cart
* @param int $quoteAddressId
* @param int|null $customerId
* @return AddressInterface
* @throws GraphQlInputException
* @throws GraphQlNoSuchEntityException
* @throws GraphQlAuthorizationException
* @throws GraphQlNoSuchEntityException
*/
public function execute(int $quoteAddressId, ?int $customerId): AddressInterface
public function execute(CartInterface $cart, int $quoteAddressId, ?int $customerId): AddressInterface
{
$quoteAddress = $this->quoteAddressFactory->create();

Expand All @@ -62,14 +62,15 @@ public function execute(int $quoteAddressId, ?int $customerId): AddressInterface
);
}

$quoteAddressCustomerId = (int)$quoteAddress->getCustomerId();

/* Guest cart, allow operations */
if (!$quoteAddressCustomerId && null === $customerId) {
return $quoteAddress;
// TODO: GetQuoteAddress::execute should depend only on AddressInterface contract
// https://github.com/magento/graphql-ce/issues/550
if ($quoteAddress->getQuoteId() !== $cart->getId()) {
throw new GraphQlNoSuchEntityException(
__('Cart does not contain address with ID "%cart_address_id"', ['cart_address_id' => $quoteAddressId])
);
}

if ($quoteAddressCustomerId !== $customerId) {
if ((int)$quoteAddress->getCustomerId() !== (int)$customerId) {
throw new GraphQlAuthorizationException(
__(
'The current user cannot use cart address with ID "%cart_address_id"',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
}
$methodCode = $shippingMethodInput['method_code'];

$quoteAddress = $this->getQuoteAddress->execute($cartAddressId, $context->getUserId());

$quoteAddress = $this->getQuoteAddress->execute($cart, $cartAddressId, $context->getUserId());
$this->assignShippingMethodToCart->execute($cart, $quoteAddress, $carrierCode, $methodCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -429,17 +429,27 @@ public function testSetBillingAddressIfCustomerIsNotOwnerOfAddress()

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
* @expectedException \Exception
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
*/
public function testSetBillingAddressOnNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';
$query = <<<QUERY
{
cart(cart_id: "$maskedQuoteId") {
items {
id
mutation {
setBillingAddressOnCart(
input: {
cart_id: "$maskedQuoteId"
billing_address: {
customer_address_id: 1
}
}
) {
cart {
billing_address {
city
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,9 @@ public function testSetNonExistentPaymentMethod()
public function testSetPaymentOnNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';
$query = <<<QUERY
{
cart(cart_id: "$maskedQuoteId") {
items {
id
}
}
}
QUERY;
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;

$query = $this->getQuery($maskedQuoteId, $methodCode);
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\GraphQl\Quote;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
use Magento\Quote\Model\QuoteFactory;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function __construct(
*
* @param string $reversedOrderId
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws NoSuchEntityException
*/
public function execute(string $reversedOrderId): string
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\GraphQl\Quote;

use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
use Magento\Quote\Model\QuoteFactory;

/**
* Get quote shipping address id by reserved order id
*/
class GetQuoteShippingAddressIdByReservedQuoteId
{
/**
* @var QuoteFactory
*/
private $quoteFactory;

/**
* @var QuoteResource
*/
private $quoteResource;

/**
* @param QuoteFactory $quoteFactory
* @param QuoteResource $quoteResource
*/
public function __construct(
QuoteFactory $quoteFactory,
QuoteResource $quoteResource
) {
$this->quoteFactory = $quoteFactory;
$this->quoteResource = $quoteResource;
}

/**
* Get quote shipping address id by reserved order id
*
* @param string $reversedOrderId
* @return int
*/
public function execute(string $reversedOrderId): int
{
$quote = $this->quoteFactory->create();
$this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id');

return (int)$quote->getShippingAddress()->getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,30 @@ public function testSetBillingAddressOnNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';
$query = <<<QUERY
{
cart(cart_id: "$maskedQuoteId") {
items {
id
mutation {
setBillingAddressOnCart(
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
}
}
}
) {
cart {
billing_address {
city
}
}
}
}
Expand Down Expand Up @@ -289,7 +309,6 @@ public function testSetBillingAddressWithoutRequiredParameters(string $input, st
}
}
QUERY;

$this->expectExceptionMessage($message);
$this->graphQlQuery($query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,9 @@ public function testSetNonExistentPaymentMethod()
public function testSetPaymentOnNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';
$query = <<<QUERY
{
cart(cart_id: "$maskedQuoteId") {
items {
id
}
}
}
QUERY;
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;

$query = $this->getQuery($maskedQuoteId, $methodCode);
$this->graphQlQuery($query);
}

Expand Down
Loading

0 comments on commit 7c5769d

Please sign in to comment.